给定以下模型
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,并且可以正确提交。但是,我无法成功更新这些警报类型。我似乎找不到定义复选框命名的正确方法
<%= check_box_tag "UNKNOWN", type.id , @alerts[0].alerttypes.include?(type)%>
检查正在“检查”的 Alerttypes 是有效的,但编辑时这些 Alerttypes 的任何更改都不会更新,它们会保持最初创建时的状态。
最佳答案
关于ruby-on-rails - has_many 通过复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2352554/