has_many通过复选框

时间:2010-02-28 20:33:06

标签: ruby-on-rails ruby

鉴于以下模型

class Feed < ActiveRecord::Base  
  has_many :alerts , :dependent => :destroy
  has_many :users , :through => :alerts
end

class Alert < ActiveRecord::Base  
  belongs_to :user
  belongs_to :feed  
  has_and_belongs_to_many :alerttypes

end 

class Alerttype < ActiveRecord::Base
  has_and_belongs_to_many :alerts
end

我可以创建一个表单,在添加新Feed时列出Alerttypes并正确提交。但是我无法成功更新这些Alerttypes。我似乎无法找到定义复选框命名的正确方法

<%= check_box_tag "UNKNOWN", type.id , @alerts[0].alerttypes.include?(type)%>

检查“已检查”的Alerttypes是否有效但编辑时这些Alerttypes中的任何更改都不会更新,并且它们会保留为首次创建时。

1 个答案:

答案 0 :(得分:6)

相关问题