Ok, this should be simple but I am finding it's not and previous
postings don't seem to shed too much light on this.
I have a select_tag with 4 values pulled in via a helper:
def filter_hours
filter_hours = [
["1 hour", 1],
["24 hours", 24],
["7 days", 168],
["14 days", 336],
]
end
The select_tag looks like the following:
select_tag :order_hours, options_for_select(filter_hours, :selected =>
@selected_order_hours)
@selected_order_hours is being set in the controller when the form is
posted. It comes back as either 1, 24, 168, 336 and is definitely
being set as confirmed through logging and printing from the view.
However, the selected valued is never set!
I have tried all combinations of :selected, selected=, etc to no
avail.
What's wrong?
Thanks,
Scott
on 2007-05-11 21:13
on 2007-05-15 15:16
On 5/11/07, Scott <tamosunas@gmail.com> wrote: > The select_tag looks like the following: > > select_tag :order_hours, options_for_select(filter_hours, :selected => > @selected_order_hours) > > @selected_order_hours is being set in the controller when the form is > posted. It comes back as either 1, 24, 168, 336 and is definitely > being set as confirmed through logging and printing from the view. > > However, the selected valued is never set! It should just be: options_for_select(filter_hours, @selected_order_hours)
on 2007-05-28 00:39
Tried that ... doesn't work. @selected_order_hours is definitely being set. Any other ideas? Thanks, Scott
on 2007-05-28 00:52
Figured it out. Had to change: select_tag :order_hours, options_for_select(filter_hours, @selected_order_hours) to select_tag :order_hours, options_for_select(filter_hours, @selected_order_hours.to_i) Picky picky! Scott
on 2011-08-17 21:47
Scott wrote in post #251131: > Figured it out. Had to change: > > select_tag :order_hours, options_for_select(filter_hours, > @selected_order_hours) > to > select_tag :order_hours, options_for_select(filter_hours, > @selected_order_hours.to_i) > > Picky picky! > > Scott was stuck on a similar problem, my solution was <%= f.select :grade, ((1..9).to_a) %>
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.