Wednesday, February 24, 2010

Rails - select class not applied

Hi, previously my code was like this, I tried much using, html_options, options, but class is not applied for select.

<%= f.select 'difficulty', options_for_select({ "Easy" => "1", "Medium" => "3", "Hard" => "5"}, get_difficulty(@tour).to_s), :class =>'input_text' %>
Right way to do:
<%= select :tour, :difficulty, { "Easy" => "1", "Medium" => "3", "Hard" => "5"}, {:selected=>get_difficulty(@tour).to_s}, :class=>"input_text" %>

Now class is applied!!!

Any other better way pls tel me,,.</span>

3 comments:

Unknown said...

Good catch Srikanth.
Looks like the kludge (bug workaround) is to add even just an empty hash {} argument before options. Seems to work for both FormHelper and FormBuilder (f.)

Unknown said...

good catch, even a dummy arg {} will do it in helper or builder (f.)

Unknown said...

{} does it also (f.)