You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
class Admins::SubDisciplinesController < Admins::BaseController
|
|
|
|
def index
|
|
@discipline = current_discipline
|
|
@sub_disciplines = current_discipline.sub_disciplines
|
|
end
|
|
|
|
def create
|
|
name = params[:name].to_s.strip
|
|
return render_error('名称重复') if current_discipline.sub_disciplines.where(name: name).exists?
|
|
SubDiscipline.create!(name: name, discipline_id: current_discipline.id)
|
|
render_ok
|
|
end
|
|
|
|
def edit
|
|
@sub_discipline = current_sub_discipline
|
|
end
|
|
|
|
def update
|
|
if params[:sub_discipline] && params[:sub_discipline][:name].present?
|
|
name = params[:sub_discipline][:name].to_s.strip
|
|
current_sub_discipline.update_attributes!(name: name)
|
|
else
|
|
ActiveRecord::Base.transaction do
|
|
current_sub_discipline.update_attributes!(setting_params)
|
|
current_sub_discipline.tag_disciplines.each do |tag|
|
|
tag.update_attributes!(setting_params)
|
|
end
|
|
end
|
|
end
|
|
@sub_disciplines = current_sub_discipline.discipline&.sub_disciplines
|
|
end
|
|
|
|
def destroy
|
|
@sub_discipline_id = params[:id]
|
|
current_sub_discipline.destroy!
|
|
end
|
|
|
|
private
|
|
|
|
def current_sub_discipline
|
|
@_current_sub_discipline = SubDiscipline.find params[:id]
|
|
end
|
|
|
|
def current_discipline
|
|
@_current_discipline = Discipline.find params[:discipline_id]
|
|
end
|
|
|
|
def setting_params
|
|
params.permit(:shixun, :subject, :question)
|
|
end
|
|
end |