class Job < ActiveRecord::Base
has_many :employments, :dependent => :destroy
has_many :users, :through => :employments
class User < ActiveRecord::Base
has_many :employments
has_many :jobs, :through => :employments
class Employment < ActiveRecord::Base
belongs_to :job
belongs_to :user # Employment has an extra attribute of confirmed ( values are 1 or 0)
在我看来,我正在尝试在用户单击时将已确认的字段从 0 更新为 1。
<%= link_to "Confirm Job", :action => :confirmjob, :id => job.id %>
在我的工作控制器中,我有
def confirmjob
@job = Job.find(params[:id])
@job.employments.update_attributes(:confirmed, 1)
flash[:notice] = "Job Confirmed"
redirect_to :dashboard
end
我确信这都是错误的,但我似乎在猜测 has_many: through。我将如何更新连接表中的已确认字段?