开发者

Add a class to a selectbox in Rails 3 [duplicate]

This question 开发者_JS百科already has answers here: Ruby on Rails form_for select field with class (4 answers) Closed 8 years ago.

I cannot figure out how to add a class to this select box in Rails 3.

<%= select(:item, :item_type, [['Phone', 1], ['Email', 2], ['Website', 3], ['Address', 4], ['Occupation', 5]]) %>

Is there anyone that knows how to do it?


Here's the official documentation for the select helper

<%= select(:item, :item_type, [['Phone', 1], ['Email', 2], ['Website', 3], ['Address', 4], ['Occupation', 5]], {}, :class => "myclass") %>


The parameters for select are the object, attribute, select list, a hash of method options, and a hash of html options, which have to be separate. If you want a 'toast' class, this works:

<%= select(:item, :item_type, [['Phone', 1], ['Email', 2], ['Website', 3], ['Address', 4], ['Occupation', 5]], {}, {:class => 'toast'}) %>

Note the empty hash - this needs to be here so that the method knows the following hash is for html options, which it passes directly onto the tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜