has_many 通过复选框 [英] has_many through checkboxes

查看:41
本文介绍了has_many 通过复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下模型

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

我可以创建一个表单来在添加新提要时列出警报类型,并且可以正确提交.但是,我无法成功更新这些警报类型.我似乎找不到定义复选框命名的正确方法

I can create a form to list the Alerttypes when adding a new Feed and this submits correctly. I am however unable to update these Alerttypes successfully. I cannot seem to find the correct method for defining the checkbox naming

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

对被检查"的 Alerttypes 的检查有效,但编辑时这些 Alerttypes 中的任何更改都不会更新,它们保持最初创建时的状态.

The checking of the Alerttypes being 'checked' works but any changes in those Alerttypes when editing does not update and they stay as when first created.

推荐答案

你看到了吗:http://millarian.com/programming/ruby-on-rails/quick-tip-has_many-through-checkboxes/ ?

这篇关于has_many 通过复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆