|
|
|
@ -47,21 +47,23 @@ class Admins::ShixunSettingsController < Admins::BaseController
|
|
|
|
|
@shixun = Shixun.find_by(id:params[:id])
|
|
|
|
|
@page_no = params[:page_no] || "1"
|
|
|
|
|
@shixun_tags = TagRepertoire.order("name asc").pluck(:name,:id)
|
|
|
|
|
tag_ids = params[:tag_repertoires]
|
|
|
|
|
if tag_ids.present?
|
|
|
|
|
@shixun&.shixun_tag_repertoires.delete_all
|
|
|
|
|
tag_repertoire_ids = @shixun&.tag_repertoires&.pluck(:id)
|
|
|
|
|
tag_ids.each do |id|
|
|
|
|
|
unless tag_repertoire_ids.include?(id)
|
|
|
|
|
tag_repertoire = @shixun.shixun_tag_repertoires.new(shixun_id:@shixun.id,tag_repertoire_id:id)
|
|
|
|
|
tag_repertoire.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
unless @shixun.update_attributes(setting_params)
|
|
|
|
|
redirect_to admins_shixun_settings_path
|
|
|
|
|
flash[:danger] = "更新失败"
|
|
|
|
|
end
|
|
|
|
|
unless @shixun.update_attributes(setting_params)
|
|
|
|
|
redirect_to admins_shixun_settings_path
|
|
|
|
|
flash[:danger] = "更新失败"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_tag_repertoires
|
|
|
|
|
shixun = Shixun.find_by(id:params[:id])
|
|
|
|
|
tag_repertoire_ids = params[:tag_repertoires] || []
|
|
|
|
|
tag_ids = tag_repertoire_ids.reject(&:blank?).map(&:to_i)
|
|
|
|
|
old_tag_ids = shixun.shixun_tag_repertoires.pluck(:tag_repertoire_id)
|
|
|
|
|
new_ids = tag_ids - old_tag_ids
|
|
|
|
|
delete_ids = old_tag_ids - tag_ids
|
|
|
|
|
tag_params = new_ids.map{|sub| {tag_repertoire_id: sub}}
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
shixun.shixun_tag_repertoires.where(tag_repertoire_id: delete_ids).destroy_all
|
|
|
|
|
shixun.shixun_tag_repertoires.create!(tag_params)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -133,6 +135,6 @@ class Admins::ShixunSettingsController < Admins::BaseController
|
|
|
|
|
|
|
|
|
|
def setting_params
|
|
|
|
|
params.permit(:use_scope,:excute_time,:close,:status,:can_copy,:webssh,:hidden,:homepage_show,:task_pass,
|
|
|
|
|
:code_hidden,:vip,:page_no,:id, :is_wechat_support, tag_repertoires:[])
|
|
|
|
|
:code_hidden,:vip,:page_no,:id, :is_wechat_support)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|