views:

808

answers:

1

In my rails form I'm using the select tag.

<%= f.select :featured,
         Timeline::TIMELINE_FEATURED,
         :prompt => "Select" %>

The definition of TIMELINE_FEATURES is Yes and No to be displayed, but stored as INT in database:

TIMELINE_FEATURED = [
 # Displayed   stored in db
 ["No",     "0"],
 ["Yes",    "1"]
]

My problem is that when I go to the edit page the dropdown value is NOT selected correctly.

For example, if I had set the dropdown to Yes, and store the value of 1 in the database if I come back to this dropdown Yes is NOT selected like it should be. Is it because the value is stored as an Integer in DB but it's a string in the option tag? How do I solve?

I have other selects in the same form that are working correctly but the value stored in the DB is a string.

Thank you in advance.

A: 
<%= f.select :featured, options_for_select(Timeline::TIMELINE_FEATURED, @zero_or_one), :prompt => "Select" %>
Apie
Yes. Thank you Apie. Here is how I did it. In my controller:@featured_string_value = @timeline.featured.to_sIn my view:<%= f.select :featured, options_for_select(Timeline::TIMELINE_FEATURED, @featured_string_value), :prompt => "Select" %>
Kristen Hazard