在集合中选择多个选项_select rails [英] Select multiple options in a collection_select rails

查看:46
本文介绍了在集合中选择多个选项_select rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何组合一个简单的选择框,从模型中获取其值

I know how to put together a simple select box that takes its values from a model

<%= f.collection_select(:sector_id, Sector.all, :id, :name, :prompt => "Please Select a Sector") %>

我的问题是如何允许用户选择多个选项,然后将它们存储在模型中.我知道我需要使用

My question is how do i allow a user to select multiple options and then store them in the model. I know i need to use

:multiple => true

但不确定语法

通常对于一个模型的多个条目,我会使用 accepts_nested_attributes_for 但我认为我不需要这个例子是否正确?

Usually for multiple entries to a model i would use accepts_nested_attributes_for but am i correct in thinking i don't need to for this example?

谢谢

推荐答案

经过一些试验和错误后确定

Ok after some trial and error

<%= f.collection_select(:sector_id, Sector.all, :id, :name, {:prompt => "Please Select a Sector"}, {:multiple => true}) %>

让我选择多个选项

这篇关于在集合中选择多个选项_select rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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