I have a model called Result. I need to create a variable that returns all results that come in between a certain date range. On the Result model there is a field called date, and on a form I am capturing a start and end date as parameters and passing them back to the controller.
so if the user enters '01/01/2014' in the startdate parameter and '01/01/2015 in the parameters I need to return all results where the date is between this range.
When the user pressers a "filter" button the parameters end up being captured as variables startdate and enddate
I tried this but it doesn't seem to work
@results = Result.where("date >= ? and date <= ?", startdate, enddate")
I then looked at the resulting SQL and thought it needed to be this
@results = Result.where("date >= ? and date <= ?", '#{startdate)', '#{enddate}')
Any ideas?
Thanks