选择框的Rails Simple Form自定义集合

时间:2014-02-22 17:43:45

标签: ruby-on-rails ruby simple-form

有没有办法在简单表单中的选择框中使用自定义Collection?

获得不同的标签值

以下是我的一个例子:

= f.input :hall_type, collection: ["Main", "Exhibition", "Conference", {"KnowedgeLibrary" => "Knowedge Library"}], prompt: "Choose a hall type"

我希望KnowledgeLibrary为值,Knowledge Library为选项的标签/文字

2 个答案:

答案 0 :(得分:0)

= f.select :hall_type, options_for_select(["Main", "Exhibition", "Conference", ["Knowedge Library", "KnowedgeLibrary"]], "KnowedgeLibrary"), {prompt: "Choose a hall type"}

答案 1 :(得分:0)

这是语法

:collection => [['label1', 'value1'], ['label2', 'value2']]