综合编程

Searching for a range of dates in Rails 3.2 does not work

微信扫一扫,分享到朋友圈

Searching for a range of dates in Rails 3.2 does not work
0

I have a Report page that generates reports of events. There is a datepicker and the user can put in a date range (Ex. March 1st – March 20th) and return all events where the event’s :start_at begins within that range. I recently upgraded from Rails 3.0.11 to Rails 3.2.13 (I was careful to follow the RailsCasts episodes directly and jump from 3.0 to 3.1 and then from 3.1 to 3.2) and noticed that my reports no longer work but I have not made any changes to the Events controller or the Event model. My code looks as follows:

events_controller.rb

def reports
  if !params[:report_start].blank? && !params[:report_end].blank?
    @events = current_user.events.report(params[:report_start], params[:report_end])
  else
    @events = current_user.events.where(params[:search]).order(sort_column + " " + sort_direction)
  end

  respond_to do |format|
    format.html do
      @events = @events.paginate(:per_page => 5, :page => params[:page])
    end
    format.xml  { render :xml => @events }
    format.pdf do
      pdf = ReportPdf.new(@events)
      send_data pdf.render, filename: "Event_Report.pdf",
                          type: "application/pdf"
    end
  end
end

event.rb

def self.report(report_start, report_end)
  where(:start_at => report_start.to_date..report_end.to_date)
end

Has the syntax of a query like this changed somewhere in the upgrade process?

I verified that Rails is still saving the date in the same format and it is working correctly everywhere else. The date output in Rails Console looks as follows:

start_at: "2013-04-25 00:00:00"

Any help would be appreciated as this is driving me crazy and looks correct to me. Thanks!

Edit:I found this Stack Overflow post
on the topic and it looks like that response says to do it the way I am but nothing is happening.

The URL does change after cliking to generate the report and the URL generated looks as follows:

http://localhost:3000/reports?utf8=%E2%9C%93&direction=&sort=&event%5Breport_start%5D=&event%5Breport_end%5D=&commit=Generate+Report

阅读原文...


Hello, buddy!

Live回顾:值得你去了解的“存算一体AI芯片技术”

上一篇

蔚来汽车股价暴跌,李斌说“没什么大不了”,情况真的这么乐观吗?

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Searching for a range of dates in Rails 3.2 does not work

长按储存图像,分享给朋友