我在哪里添加一个类在这个Rails collection_select中?

时间:2014-11-08 06:45:00

标签: ruby-on-rails ruby ruby-on-rails-3 devise

我无法在此collection_select中添加一个类:

<%= f.collection_select :category_id, Category.all, :id, :name, {:prompt => 'Choose a category'}, {:required => true} %> 

我试过这个:

<%= f.collection_select :category_id, Category.all, :id, :name, {:prompt => 'Choose a category'}, {:required => true}, {:class => "form_inputs"} %>

以及:

<%= f.collection_select :category_id, Category.all, :id, :name, {prompt: "Choose a category"}, {required: true}, {class: "form_inputs"} %>

但似乎都不起作用。是什么给了什么?

2 个答案:

答案 0 :(得分:0)

Try like this 
<%= f.collection_select :category_id, Category.all, :id, :name, {:prompt => 'Choose a category'}, :class => "form_inputs" %>

答案 1 :(得分:0)

试试这个...测试。

<%= f.collection_select 'category_id', Category.all, 'id', 'name', {prompt: "Choose a category"}, class: "form_inputs", required:true %>