Generating a report by date range in rails

前端 未结 2 1179
礼貌的吻别
礼貌的吻别 2020-12-13 10:02

How would you go about producing reports by user selected date ranges in a rails app? What are the best date range pickers?

edit in response to patrick : I am look

2条回答
  •  有刺的猬
    2020-12-13 10:48

    It's not an unRESTful practice to have URL parameters control the range of selected records. In your index action, you can do what Patrick suggested and have this:

      #initialize start_date and end_date up here, by pulling from params probably
      @models = SomeModel.find(:all, :conditions => ['date >= ? and date <= ?', params[:start_date], params[:end_date]])
    

    Then in your index view, create a form that tacks on ?start_date=2008-01-01&end_date=2008-12-31 to the URL. Remember that it's user-supplied input, so be careful with it. If you put it back on the screen in your index action, be sure to do it like this:

    Showing records starting on 
    <%= h start_date %> 
    and ending on 
    <%= h end_date %>
    

提交回复
热议问题