0

When rails renders this tag, it is not including the class

<%= f.collection_select(:native_language, Language.order('language ASC').all, :language, :language, class: "input_standard", :default => [Language.find_by(:language => "English")] ) %>

This is what is rendered:

<select name="user[native_language]" id="user_native_language">
    <option value="English">English</option>
    <option value="French">French</option>
    <option value="Spanish">Spanish</option>
</select>

Why isn't the class showing up? I've tried moving around class: "input_standard" with no luck.

user3006927
  • 484
  • 4
  • 15
  • @tstrass you're right, the answer is in that link, then my answer can be ignored and this post could be marked as duplicate. – fanta Oct 27 '16 at 15:55

1 Answers1

0

The Rails documentation for collection_select is this one: collection_select(method, collection, value_method, text_method, options = {}, html_options = {}). If you check it receives two hashes, the first one is options and the second one is the html_options. The second one is the one where you specify the class the html element will have. Something like:

<%= f.collection_select(:native_language, Language.order('language ASC').all, :language, :language, {}, {class: "input_standard", :default => [Language.find_by(:language => "English")]} ) %>

By te way, what do you want to accomplish with the default option ?, should that be the prompt option ?.

If you what you want is the prompt option instead of the default, then you need to add the prompt option to the first hash.

fanta
  • 1,489
  • 13
  • 15