Hi All,
I want to create a select list on a form with an array of dates from
a DB similar to this.
The date is used to search another DB for documents to edit.
2007-08-15
2007-08-22
Which if any of the selects would be best for this and
allow what has been selected to be marked as selected
until the choice is changed.
I have been using but never get the selected item to stick:
<%= select_tag(:pubdate, options_for_select
(@pubdates, :selected=>@pubdate)) %>
Thanks for any hints/references/etc
Hi,
Tried it this morning but still won’t add the selected to the item
choosen.
Thanks for the quick rely
Dave
leave out “:selected =>” and it ought to work
<%= select_tag(:pubdate, options_for_select
(@pubdates, @pubdate)) %>
Hi,
I poked around and don’t know if it is a bug or feature ;-).
This works correctly:
<%= select_tag(:mydate, options_for_select( %w{ 2007-08-22 2007-08-29
2007-09-05 }, params[‘mydate’])) %>
Chosen item is selected when form is submitted
But this will not:
@pubdates is an array of dates from the DB same as above
@pubdates = Pubdates.find(:all, :order=>“pubdate”).map {|u|
[u.pubdate] }
<%= select_tag(:pubdate, options_for_select(@pubdates, params
[‘pubdate’])) %>
Any insight into making this work is appreciated
Hi,
I was using a different name to put a second select for testing.
What I found was that ActiveRecord maps the list of dates to a
different data type than the params that it is comparing to(this is a
guess).
What ended up working for me was casting what was returned from
the DB to a string(I am a little green so I am not sure why this
worked).
The solution was:
Controller-
@pubdates = Pubdates.find(:all, :order=>“pubdate”).map {|u|
[u.pubdate.to_s] }
View-
<%= select_tag(:pubdate, options_for_select(@pubdates, params
[‘pubdate’])) %>
Now the chosen date is selected when the form is submitted and
rendered again.
Thanks for pointing me in the right direction
Dave
<%= select_tag(:pubdate, options_for_select(@pubdates, params
[‘pubdate’])) %>
Any insight into making this work is appreciated
you’re using ‘mydate’ in the first example, but ‘pubdate’ in the
second