私は愚かな問題に直面しています。私は、モデルstaffとtaskとの間の関係を参照するjoinテーブル "staffs_task"に要素を作成するコレクションselectを作成しました。 そして今私は2つのことを望みます:(1)このアソシエーションを削除するボタン(2)と、私のモデルstaffs_taskのコードを少し削除して、重複を避けるようにします。そして、最後の情報は、タスクが牧場で構築されたモデルですコレクションから要素を削除する
私のコード:
は(NEW_TASKでコレクション)だから、
<%= select_tag "staffs_task", options_from_collection_for_select(@staffs, 'id', 'name') , :multiple => true %>
(task_controller)
skip_before_action :configure_sign_up_params
before_action :set_ranch
before_action :set_task, except: [:create]
def create
@task = @ranch.tasks.create(task_params)
@staffs = Staff.where(:id => params[:staffs_task])
@task.staffs << @staffs
if @task.save
@task.update(done: false)
@task.update(star: false)
flash[:success] = "The task was created "
else
flash[:success] = "The task was not created "
end
redirect_to @ranch
end
private
def task_params
params.require(:task).permit(:content, :deadline, :row_order, :date, :assigned_to)
end
def set_ranch
@ranch = Ranch.find(params[:ranch_id])
end
def set_task
@task = @ranch.tasks.find(params[:id])
end
何かを持っている場合この2つの事のいずれかについてのアイデアは、あなたの助けが歓迎されるでしょう 事前に感謝!!
class Staff
has_many :assignments
has_many :tasks, through: :assignments
end
class Task
has_many :assignments
has_many :staff, through: :assignments
end
class Assignment
belongs_to :task
belongs_to :staff
end
注plural of staff is staffこと - あなたがウィザードによって運ばスティックについて話している場合を除き: