From fe3c794a2063feee9a1cf7e815ed8bc1e686ad33 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 13 Dec 2019 09:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hacks_controller.rb | 10 ++++++++-- app/views/hack_user_lastest_codes/show.json.jbuilder | 2 +- app/views/hacks/index.json.jbuilder | 2 +- config/routes.rb | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 657ad0f2a..cab952a04 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -1,8 +1,8 @@ class HacksController < ApplicationController before_action :require_login, except: [:index] - before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set, :destroy] + before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set, :destroy, :cancel_publish] before_action :require_teacher_identity, only: [:create] - before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set, :destroy] + before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set, :destroy, :cancel_publish] # 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可 @@ -99,6 +99,12 @@ class HacksController < ApplicationController render_ok end + # 取消发布 + def cancel_publish + @hack.update_attribute(:status, 0) + render_ok + end + # 发布列表 def unpulished_list limit = params[:limit] || 16 diff --git a/app/views/hack_user_lastest_codes/show.json.jbuilder b/app/views/hack_user_lastest_codes/show.json.jbuilder index 2d7ffd2bf..cfdc87d25 100644 --- a/app/views/hack_user_lastest_codes/show.json.jbuilder +++ b/app/views/hack_user_lastest_codes/show.json.jbuilder @@ -1,5 +1,5 @@ json.hack do - json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier) + json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier, :status) json.language @hack.language json.username @hack.user.real_name json.code @my_hack.code diff --git a/app/views/hacks/index.json.jbuilder b/app/views/hacks/index.json.jbuilder index c86884a41..2b4a8b8c7 100644 --- a/app/views/hacks/index.json.jbuilder +++ b/app/views/hacks/index.json.jbuilder @@ -8,6 +8,6 @@ end json.hacks_count @hacks_count json.hacks_list do json.array! @hacks do |hack| - json.(hack,:identifier, :name , :hack_user_lastest_codes_count, :difficult, :passed_rate, :category) + json.(hack,:identifier, :name , :hack_user_lastest_codes_count, :difficult, :passed_rate, :category, :open_or_not, :status) end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 972579201..19cbe4058 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,6 +41,7 @@ Rails.application.routes.draw do end member do post :publish + post :cancel_publish get :start post :update_set delete :delete_set