试卷编辑时撤销选题

dev_jupyter
cxt 5 years ago
parent 8776449234
commit 5e09071955

@ -2,7 +2,7 @@ class ExaminationBanksController < ApplicationController
include PaginateHelper
before_action :require_login
before_action :find_exam, except: [:index, :create]
before_action :edit_auth, only: [:update, :destroy, :set_public]
before_action :edit_auth, only: [:update, :destroy, :set_public, :revoke_item]
def index
exams = ExaminationBankQuery.call(params)
@ -62,6 +62,15 @@ class ExaminationBanksController < ApplicationController
render_ok
end
def revoke_item
item = @exam.examination_items.find_by!(item_bank_id: params[:item_id])
ActiveRecord::Base.transaction do
@exam.examination_items.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1")
item.destroy!
end
render_ok
end
private
def form_params

@ -8,7 +8,8 @@ class ItemBanksController < ApplicationController
items = ItemBankQuery.call(params)
@items_count = items.size
@items = paginate items.includes(:item_analysis, :user, :container)
@item_basket_ids = current_user.item_baskets.pluck(:item_bank_id)
exam = ExaminationBank.find_by(id: params[:exam_id]) if params[:exam_id].present?
@item_basket_ids = exam ? exam.examination_items.pluck(:item_bank_id) : current_user.item_baskets.pluck(:item_bank_id)
end
def create

@ -80,6 +80,7 @@ Rails.application.routes.draw do
resources :examination_banks do
member do
post :set_public
delete :revoke_item
end
end

Loading…
Cancel
Save