lo there, i have a page with a date_select on it. When the date is passed, i need it to pass back to the same action (reloading the page with a new date). Now, i want the default date to be yesterday. This is for the first time the page is hit, but i don''t know how to set my controller up like that. def pull_records_from_date @start = params[:start] do some stuff here end how do i let the controller know to pick yesterday for a start date ( ruby date object ) if nothing was passed to the action ? thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2007-Mar-26 19:52 UTC
Re: how to have default param if loading page the first time
Greatest little operator in Ruby: || def pull_records_from_date @start = params[:start] ### @start ||= Date.yesterday ### do some stuff here end Which basically says "if there''s nothing here yet, do another assignment check!" Jason On 3/26/07, nephish <nephish-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > lo there, > i have a page with a date_select on it. When the date is passed, i > need it to pass back to the same action (reloading the page with a new > date). Now, i want the default date to be yesterday. This is for the > first time the page is hit, but i don''t know how to set my controller > up like that. > > def pull_records_from_date > @start = params[:start] > do some stuff here > end > > how do i let the controller know to pick yesterday for a start date > ( ruby date object ) if nothing was passed to the action ? > > thanks > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
nephish
2007-Mar-26 19:56 UTC
Re: how to have default param if loading page the first time
way cool, thanks very much sk On Mar 26, 2:52 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Greatest little operator in Ruby: ||> > def pull_records_from_date > @start = params[:start] > ### > @start ||= Date.yesterday > ### > do some stuff here > end > > Which basically says "if there''s nothing here yet, do another assignment > check!" > > Jason > > On 3/26/07, nephish <neph...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > lo there, > > i have a page with a date_select on it. When the date is passed, i > > need it to pass back to the same action (reloading the page with a new > > date). Now, i want the default date to be yesterday. This is for the > > first time the page is hit, but i don''t know how to set my controller > > up like that. > > > def pull_records_from_date > > @start = params[:start] > > do some stuff here > > end > > > how do i let the controller know to pick yesterday for a start date > > ( ruby date object ) if nothing was passed to the action ? > > > thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ball, Donald A Jr \(Library\)
2007-Mar-26 21:58 UTC
Re: how to have default param if loading page the first time
def pull_records_from_date @start = params[:start] || (Date.today - 1).to_s ... end - donald --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
nephish
2007-Mar-27 10:13 UTC
Re: how to have default param if loading page the first time
hey, thanks for this, looks good sk On Mar 26, 4:58 pm, "Ball, Donald A Jr \(Library\)" <donald.b...-GjtI+QwuxAR68HQyEA6aog@public.gmane.org> wrote:> def pull_records_from_date > @start = params[:start] || (Date.today - 1).to_s > ... > end > > - donald--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---