使用 `:has_many :through` 记录关联处理复选框表单
我正在使用 Ruby on Rails 3.0.7,我想在视图文件中使用复选框字段(即,用于新建和编辑表单)以及 :has_many :through
记录关联。我看到使用 has_and_belongs_to_many
记录关联轻松实现了这种事情,但是是否有可能使其与第一个提到的关联轻松一起工作?如果是这样,该怎么做?
I am using Ruby on Rails 3.0.7 and I would like to use check box fields in my view files (that is, for new and edit forms) with an :has_many :through
Record Association. I seen that kind of things easily implemented using an has_and_belongs_to_many
Record Association, but is it possible to make that to work easly with the first mentioned association? If so, how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Dogbert 提供的链接是手动执行此操作的好方法。但是,如果您决定使用简单表单,您将获得内置功能。
使用前面提到的文章中的示例你会这样做:
这个例子当然非常简单,但它应该可以工作。祝你好运!
The link Dogbert supplied is a good way of doing it manual. If you however decide to use Simple Form you get that functionality build in.
Using the example from the previously mentioned article you would do:
This example is of course very simplified but it should work. Good luck!