scottc12
2008-Jun-19 22:55 UTC
Need Help on How to provide a Start and Stop Date range Dynamically to my ActiveRecord Find?
I''d like to have my index page present the user with a Form for selecting a Date range Example: Start 2008-06-19 End: 2008-06-29 and then pass this information into my ActiveRecord Find I''m working with a legacy DB and with the help of the list Im able to do all my queries and understand what''s going on but I''m having trouble figuring out the method to pass my gathered Date Range search to my Find. I''m assuming I would want to use form tag and present this from the index page and results to the index page as well? My Current Static Find: @reports = Report.find(:all, :conditions => "expiration_date between ''2008-06-19'' and ''2008-06-29''", :order => ''expiration_date DESC'') Still just a newb but the power of ActiveRecord is fantastic. thanks Sc- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brent Miller
2008-Jun-20 15:41 UTC
Re: Need Help on How to provide a Start and Stop Date range
On your homepage build a form with two date_select fields in it, one called start_date and one called end_date. Then, in your controller action, you do @reports = Report.find(:all, :conditions => {:expiration_date => (params[:start_date]..params[:end_date])}) ActiveRecord will automatically build the date range in the select statement based on your particular database adapter. scottc12 wrote:> I''d like to have my index page present the user with a Form for > selecting a Date range > > Example: > Start 2008-06-19 End: 2008-06-29 and then pass this information into > my ActiveRecord Find > > I''m working with a legacy DB and with the help of the list Im able to > do all my queries and understand what''s going on but I''m having > trouble figuring out the method to pass my gathered Date Range search > to my Find. > > I''m assuming I would want to use form tag and present this from the > index page and results to the index page as well? > > My Current Static Find: > @reports = Report.find(:all, :conditions => "expiration_date between > ''2008-06-19'' and ''2008-06-29''", :order => ''expiration_date DESC'') > > > Still just a newb but the power of ActiveRecord is fantastic. > > > thanks > > > Sc--- 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 -~----------~----~----~----~------~----~------~--~---
scottc12
2008-Jun-21 11:25 UTC
Re: Need Help on How to provide a Start and Stop Date range
Thanks Brent, I was thinking I needed to build things in reports/index and then have them display in show which from my reading is for single returned ID. Your saying I can just add this to my homepage and then render. I assume I could also make this a single page with inline results using AJAX? Thanks-- Sc- On Jun 20, 11:41 am, Brent Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> On your homepage build a form with two date_select fields in it, one > called start_date and one called end_date. Then, in your controller > action, you do > > @reports = Report.find(:all, :conditions => {:expiration_date => > (params[:start_date]..params[:end_date])}) > > ActiveRecord will automatically build the date range in the select > statement based on your particular database adapter. > > > > scottc12 wrote: > > I''d like to have my index page present the user with a Form for > > selecting a Date range > > > Example: > > Start 2008-06-19 End: 2008-06-29 and then pass this information into > > my ActiveRecord Find > > > I''m working with a legacy DB and with the help of the list Im able to > > do all my queries and understand what''s going on but I''m having > > trouble figuring out the method to pass my gathered Date Range search > > to my Find. > > > I''m assuming I would want to use form tag and present this from the > > index page and results to the index page as well? > > > My Current Static Find: > > @reports = Report.find(:all, :conditions => "expiration_date between > > ''2008-06-19'' and ''2008-06-29''", :order => ''expiration_date DESC'') > > > Still just a newb but the power of ActiveRecord is fantastic. > > > thanks > > > Sc- > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brent Miller
2008-Jun-22 05:48 UTC
Re: Need Help on How to provide a Start and Stop Date range
From a usability point of view I''d put the search form on the index page and all other pages in the controller. That''s up to you and your app design though. You''re right that the show action should only be used for displaying single records, if your app is sticking to the RESTful conventions. That''s not always appropriate, though, so it''s up to you. I tend to overload my index action to handle filtering: the view code for a search result is 99.9% the same as for a straight index -- the only difference is the line that generates the collection for display (and visual confirmation for the user that they''re looking at a subset). For maximum DRYness I just check at the top of my index action if I''m running a search or not: def index if params[:search_param] conditions = whatever end @reports = Report.find(:all, :conditions => conditions) end Doing the same thing w/ ajax is near trivial: you just need an RJS template to render the response. Brent scottc12 wrote:> Thanks Brent, > I was thinking I needed to build things in reports/index and then > have them display in show which from my reading is for single returned > ID. Your saying I can just add this to my homepage and then render. I > assume I could also make this a single page with inline results using > AJAX? > > Thanks-- > Sc- > > On Jun 20, 11:41�am, Brent Miller <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
scottc12
2008-Jun-23 13:05 UTC
Re: Need Help on How to provide a Start and Stop Date range
Thanks so much. I took your advice and created a new controller and have things successfully posting params. I should have started with a ROR complaint DB instead of working with a Legacy DB for my first "real" project. In any case I''m progressing and although its messy at the moment I''m functional. I''m going to spend the day soaking up ActiveRecord and cleaning up controllers and models. Thanks again. Sc- On Jun 22, 1:48 am, Brent Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> From a usability point of view I''d put the search form on the index page > and all other pages in the controller. That''s up to you and your app > design though. You''re right that the show action should only be used > for displaying single records, if your app is sticking to the RESTful > conventions. That''s not always appropriate, though, so it''s up to you. > > I tend to overload my index action to handle filtering: the view code > for a search result is 99.9% the same as for a straight index -- the > only difference is the line that generates the collection for display > (and visual confirmation for the user that they''re looking at a subset). > For maximum DRYness I just check at the top of my index action if I''m > running a search or not: > > def index > if params[:search_param] > conditions = whatever > end > @reports = Report.find(:all, :conditions => conditions) > end > > Doing the same thing w/ ajax is near trivial: you just need an RJS > template to render the response. > > Brent > > scottc12 wrote: > > Thanks Brent, > > I was thinking I needed to build things in reports/index and then > > have them display in show which from my reading is for single returned > > ID. Your saying I can just add this to my homepage and then render. I > > assume I could also make this a single page with inline results using > > AJAX? > > > Thanks-- > > Sc- > > > On Jun 20, 11:41�am, Brent Miller <rails-mailing-l...@andreas-s.net> > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---