Reputation: 6264
This could be the dumbest question on SO but I can't figure the problem out. I'm using an old version of Rails 2.3.3 for a project and I am displaying a form using jQuery Dialog. The form has a select box which i am rendering like this.
<%= f.select :recurr_frequency, [["Daily", "Daily"], ["Weekly","Weely"], ["Monthly", "Monthly"]], {:selected => "Daily", :value => "Daily"} %>
I see that the html (when viewed in the javascript console) to display the selected attribute as expected but the form on the browser does not show this.
I am completely clueless if this is a browser issue (but i can't view this in any browser) or am i doing something wrong with Rails.
So when I submit the form without selecting anything from the drop down the default selected value never gets passed to the server. Would really really appreciate some help.
Upvotes: 2
Views: 1731
Reputation: 4499
I think the problem is you aren't setting the :selected option in the right spot. From your example, it looks like you're setting it in the select helper itself and not in the options. You'll want to use the :selected in the options_for_select.
For example, this should default to weekly:
<%= f.select :recurr_frequency, options_for_select([["Daily","Daily"], ["Weekly", "Weekly"], ["Monthly","Monthly"]], :selected => "Weekly") %>
Upvotes: 0
Reputation: 4578
This sound like a non-closed tag issue...
If you got something like this in your resulting HTML code
<input type="text" name="whatever" id="whatever" /
<select id="..." name="...>
<option value="Weekly">Weekly</option>
...
</select>
your select statement doesn't get rendered, cause the input tag before isn't closed. It has nothing to do with Rails itself but it can happen easily in views if you're writing HTML without the rails helpers...
Check you sourcecode before the select tag for non-closed tags..
Hope this helps!
Upvotes: 1