add: platform communicate

This commit is contained in:
viletyy 2021-12-02 16:59:55 +08:00
parent 0a00a4bc0e
commit 4a7878d16e
6 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,7 @@
class Home::PlatformCommunicatesController < ApplicationController
def index
scope = PlatformCommunicate.order(created_at: :desc)
@communicates = kaminari_paginate(scope)
end
end

View File

@ -1,4 +1,30 @@
# == Schema Information
#
# Table name: competitions
#
# id :integer not null, primary key
# title :string(255)
# start_time :datetime
# end_time :datetime
# identifier :string(255)
# available :boolean default("0")
# online_time :datetime
# visits :integer default("0")
# competition_lists_count :integer default("0")
# min_num :integer default("1")
# max_num :integer default("1")
# enroll_end_time :datetime
# created_at :datetime not null
# updated_at :datetime not null
# status :integer default("0")
# subtitle :string(255)
# team_members_count :integer default("0")
# limit_type :integer default("0")
# show_top :integer default("0")
# content :text(65535)
#
class Competition < ApplicationRecord
enum status: {archived: 0, active: 1}
end
end

View File

@ -0,0 +1,15 @@
# == Schema Information
#
# Table name: platform_communicates
#
# id :integer not null, primary key
# title :string(255)
# content :string(255)
# tag_field :text(65535)
# fake_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class PlatformCommunicate < ApplicationRecord
end

View File

@ -0,0 +1,8 @@
json.total_count @communicates.total_count
json.communicates do
json.array! @communicates.each do |communicate|
json.(communicate, :id, :title, :content, :fake_id)
json.tag communicate.tag_field.include?(',') ? communicate.tag_field.split(",") : communicate.tag_field
json.created_time format_time(communicate.created_at)
end
end

View File

@ -105,6 +105,7 @@ Rails.application.routes.draw do
namespace :home do
resources :platform_statistics, only: [:index]
resources :competitions, only:[:index]
resources :platform_communicates, only: [:index]
end
get 'home/index'
get 'home/search'

View File

@ -0,0 +1,12 @@
class CreatePlatformCommunicates < ActiveRecord::Migration[5.2]
def change
create_table :platform_communicates do |t|
t.string :title
t.string :content
t.text :tag_field
t.integer :fake_id
t.timestamps
end
end
end