Sharon Machlis
2007-Jul-09 01:41 UTC
Is there a way to get date_select to "select" another date besides "today"?
Is there a way to use date_select in the form_for helper and have the displayed date in the drop-down list be something besides "today"? I''m trying to get it to be "yesterday" without success. I also tried <% d = Date.today %> <% d = d-1 %> <%= select_date (date=d) %> and that didn''t work either. Thanks. Sharon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kennethkunz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-09 02:49 UTC
Re: Is there a way to get date_select to "select" another date besides "today"?
Sharon, I assume you''re trying to have a date field default to yesterday in the form if it hasn''t already been set by the user? Try setting it to yesterday in the controller. So if you have an ActiveRecord object called event that includes an attribute called scheduled_date, do something like this in the controller action: event.scheduled_date ||= 1.day.ago Now you should be able to use the form_for/date_select and get the right result. Alternatively, you could use the select_date helper... should look something like: select_date(1.day.ago) Cheers, Ken On Jul 8, 8:41 pm, Sharon Machlis <smach...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there a way to use date_select in the form_for helper and have the > displayed date in the drop-down list be something besides "today"? I''m > trying to get it to be "yesterday" without success. I also tried > > <% d = Date.today %> > <% d = d-1 %> > <%= select_date (date=d) %> > > and that didn''t work either. > > Thanks. > > Sharon--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Stefan Mahlitz
2007-Jul-09 21:19 UTC
Re: Is there a way to get date_select to "select" another date besides "today"?
Sharon Machlis wrote:> Is there a way to use date_select in the form_for helper and have the > displayed date in the drop-down list be something besides "today"? I''m > trying to get it to be "yesterday" without success. I also tried > > <% d = Date.today %> > <% d = d-1 %> > <%= select_date (date=d) %> > > and that didn''t work either.From api.rubyonrails.org you should use select_date(d) The notation select_date(date = Date.today, options = {}) means - if there is no parameter supplied it uses Date.today as first parameter and an empty hash as options. Stefan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---