anyone know any examples of good code for a date range filter i can add to my app to return only selected articles within that range based on their created at date. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello You could use named_scope (starting with rails 2.1). There is a good rails cast presenting them with an example with dates : http://railscasts.com/episodes/108-named-scope --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tranquiliste wrote:> Hello > > You could use named_scope (starting with rails 2.1). > > There is a good rails cast presenting them with an example with > dates : http://railscasts.com/episodes/108-named-scopeHi, thanks for the response. I am wondering how to do this in my app. I can see the example code named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } } and examples on the net state the same, but I want to be able to input two dates into boxes and call the filter from the view page, which I also am not sure how to do. any help would be greatly appreciated. dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > and examples on the net state the same, but I want to be able to input > two dates into boxes and call the filter from the view page, which I > also am not sure how to do. > > any help would be greatly appreciated. > > daveim pretty sure this would work. But am wondering how I can call this filter from my page. so for example have two text boxes and a button that calls somthing similar to " @article.comments.in_period(@start_date, @end_date)" named_scope :in_period, lambda { |start_date, end_date| { :conditions => ["articles.created_at >= ? and " + "articles.created_at <= ?", start_date, end_date] } any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry... @articles.in_period(@start_date, @end_date) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dave Smith wrote:> > sorry... @articles.in_period(@start_date, @end_date)anyone have any idea? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dave Smith wrote:> anyone know any examples of good code for a date range filter i can add > to my app to return only selected articles within that range based on > their created at date. >Here is how I fetch something similar. It is just a simple find. Substitute the created_at field and it should work. Is that what you are looking for? @res = Reservation.find(:all, :conditions => [ "enddate >= ? and startdate <= ?",Date.today,Date.today+120], :order => "space_id,startdate ASC") --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Norm wrote:> Dave Smith wrote: >> anyone know any examples of good code for a date range filter i can add >> to my app to return only selected articles within that range based on >> their created at date. >> > > Here is how I fetch something similar. It is just a simple find. > Substitute the created_at field and it should work. Is that what you > are looking for? > > @res = Reservation.find(:all, > :conditions => [ "enddate >= ? and startdate > <= ?",Date.today,Date.today+120], > :order => "space_id,startdate ASC")ok thats great but how do I initiate that from the code. so for example the page will load index and collect the articles normally. but how do i then get it to collect the articles using the date filter code here!? sorry for such a noob question -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dave Smith wrote:> Norm wrote: > >> Dave Smith wrote: >> >>> anyone know any examples of good code for a date range filter i can add >>> to my app to return only selected articles within that range based on >>> their created at date. >>> >>> >> Here is how I fetch something similar. It is just a simple find. >> Substitute the created_at field and it should work. Is that what you >> are looking for? >> >> @res = Reservation.find(:all, >> :conditions => [ "enddate >= ? and startdate >> <= ?",Date.today,Date.today+120], >> :order => "space_id,startdate ASC") >> > > ok thats great but how do I initiate that from the code. so for example > the page will load index and collect the articles normally. but how do i > then get it to collect the articles using the date filter code here!? > sorry for such a noob question >I am not sure I understand what you are trying to do. Are you trying to collect a set of information and then letting the user specify some conditions (date range) so you would then display only those objects that meet that condition? If that is what you are doing you could treat it as two separate actions in the controller each of which will do the appropriate find from which you then render using the same view. There might be another way to do it but I would probably first do it that way and worry about optimizing when that becomes important. Sorry if I misunderstand your problem. Norm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---