From a571ae0c35f428cf96de1ce73ca9a469305da60a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 16 Oct 2019 16:12:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competitions/competitions_controller.rb | 16 ++++++++++++---- .../competitions/index.json.jbuilder | 2 +- config/initializers/wechat_init.rb | 1 + config/routes.rb | 4 ++++ ...1016070842_add_description_to_competitions.rb | 6 ++++++ 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20191016070842_add_description_to_competitions.rb diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 34dac7350..77159fdaf 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -1,5 +1,6 @@ class Competitions::CompetitionsController < Competitions::BaseController skip_before_action :require_login + before_action :allow_visit, except: [:index] def index # 已上架 或者 即将上架 @@ -24,10 +25,10 @@ class Competitions::CompetitionsController < Competitions::BaseController end def show - unless current_competition.published? || admin_or_business? - render_forbidden - return - end + end + + def common_header + end private @@ -35,4 +36,11 @@ class Competitions::CompetitionsController < Competitions::BaseController def current_competition @_current_competition ||= Competition.find_by!(identifier: params[:id]) end + + def allow_visit + unless current_competition.published? || admin_or_business? + render_forbidden + return + end + end end \ No newline at end of file diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder index 400f17379..4b8390a7d 100644 --- a/app/views/competitions/competitions/index.json.jbuilder +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -1,7 +1,7 @@ json.count @count json.competitions do json.array! @competitions.each do |competition| - json.extract! competition, :id, :identifier, :name, :sub_title + json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description json.visits_count competition.visits member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count diff --git a/config/initializers/wechat_init.rb b/config/initializers/wechat_init.rb index 3fd8f9485..3f91d1665 100644 --- a/config/initializers/wechat_init.rb +++ b/config/initializers/wechat_init.rb @@ -13,6 +13,7 @@ rescue => ex puts %Q{\033[33m [warning] wechat config or configuration.yml missing, please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m} wechat_config = {} + weapp_config = {} end # 网站应用 diff --git a/config/routes.rb b/config/routes.rb index 4445278de..e8562b044 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -790,6 +790,10 @@ Rails.application.routes.draw do end resources :teachers, only: [:index] resources :students, only: [:index] + + member do + get :common_header + end end end diff --git a/db/migrate/20191016070842_add_description_to_competitions.rb b/db/migrate/20191016070842_add_description_to_competitions.rb new file mode 100644 index 000000000..268d7b8fc --- /dev/null +++ b/db/migrate/20191016070842_add_description_to_competitions.rb @@ -0,0 +1,6 @@ +class AddDescriptionToCompetitions < ActiveRecord::Migration[5.2] + def change + add_column :competitions, :description, :text + add_column :competitions, :introduction, :text + end +end