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. <select id="pubdate" name="pubdate"> <option value="2007-08-15">2007-08-15</option> <option value="2007-08-22">2007-08-22</option> </select> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
leave out ":selected =>" and it ought to work <%= select_tag(:pubdate, options_for_select (@pubdates, @pubdate)) %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Tried it this morning but still won''t add the selected to the item choosen. Thanks for the quick rely Dave On Aug 13, 2007, at 5:23 PM, jemminger wrote:> > leave out ":selected =>" and it ought to work > > <%= select_tag(:pubdate, options_for_select > (@pubdates, @pubdate)) %> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Aug 13, 2007, at 5:23 PM, jemminger wrote:> > leave out ":selected =>" and it ought to work > > <%= select_tag(:pubdate, options_for_select > (@pubdates, @pubdate)) %> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 >you''re using ''mydate'' in the first example, but ''pubdate'' in the second --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Aug 15, 2007, at 9:32 AM, jemminger wrote:> > >> 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 >> > > you''re using ''mydate'' in the first example, but ''pubdate'' in the > second > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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).yes, if you store that field in the db as date or datetime, AR will return it as a Date object. AR will return the column''s data cast to the appropriate ruby type. i''m pretty sure all form params will be strings by default. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---