替换 'collection_select, :multiple =>真",在 Rails 中有多个“check_box"选项 [英] Replace 'collection_select, :multiple => true' with multiple 'check_box' options in Rails

查看:40
本文介绍了替换 'collection_select, :multiple =>真",在 Rails 中有多个“check_box"选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用 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 (text versionn)

这篇关于替换 'collection_select, :multiple =>真",在 Rails 中有多个“check_box"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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