marcamillion
marcamillion

Reputation: 33755

How do I generate this select tag in Rails?

I am trying to generate this:

<select class="input-small">
   <option value="1">1+ bd</option>
   <option value="2">2+ bd</option>
   <option value="3">3+ bd</option>
   <option value ="4">4+ bd</option>
   <option value ="5">PH</option>
</select>

I tried this:

<%= f.collection_select :num_bedrooms, ["1+ br", "2+ br", "3+ br", "4+ br", "PH"], [1, 2, 3, 4, 5], {}, {:class => "input-small"} %>

But that gives me this:

TypeError at /    
Message {} is not a symbol

How do I generate that select tag with the collection select?

Thanks.

Edit 1:

This is the output produced @shrimpsushi's answer:

<select id="search_num_bedrooms" name="search[num_bedrooms]"><option value="<option value="1">1+ bd</option>
<option value="2">2+ bd</option>
<option value="3">3+ bd</option>
<option value="4">4+ bd</option>">collection</option>
<option value="input_html" class="input-small">input_html</option></select>  

Notice the weird "> collection</option> tag after the 4th option. Not to mention the input_html option value that has the class applied to it.

Upvotes: 0

Views: 96

Answers (1)

JazzJackrabbit
JazzJackrabbit

Reputation: 515

<%= f.select :num_bedrooms, options_for_select({"1+ br" => 1, "2+ br" => 2}), {}, class: 'input-small' %>

Upvotes: 2

Related Questions