替换 'collection_select, :multiple =>真",在 Rails 中有多个“check_box"选项 [英] Replace 'collection_select, :multiple => true' with multiple 'check_box' options in Rails
问题描述
如何用 check_box
选项列表替换 collection_select
(使用 :multiple => true
),这样就有集合中每个对象的 check_box
选项?
How do you replace a collection_select
(with :multiple => true
) with a list of check_box
options, such that there is a check_box
option for each object in the collection?
是否有一种优雅的方式来使用表单构建器(即不使用 *_tag
助手)来实现这一点?我想尽可能多地依赖 ActiveRecord 的内置功能...
Is there an elegant way to implement this using form builders (i.e. without using *_tag
helpers)? I'd like to lean on ActiveRecord's built in functionality as much as possible...
推荐答案
我不认为有一种内置的优雅"方式可以做到这一点.
I don't think there's a built-in "elegant" way to do this.
这个 railscast 应该能让你继续前进:
This railscast should get you going, though:
- http://railscasts.com/episodes/17-habtm-checkboxes
- http://asciicasts.com/episodes/17-habtm-checkboxes(文字版n)
- http://railscasts.com/episodes/17-habtm-checkboxes
- http://asciicasts.com/episodes/17-habtm-checkboxes (text versionn)
这篇关于替换 'collection_select, :multiple =>真",在 Rails 中有多个“check_box"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!