I’m trying to work out how to get a custom route working with rails to perform a date query. I’d like to call this report if possible. So I access my route on the browser and get the following.
http://localhost:3000/trips/report
Couldn't find Trip with id=report
Like it’s trying to read in report as an ID? I can’t quite work out where I’ve gone wrong here? In my routes.rb file I’ve create the following entry.
match 'trips/report' => 'trips#report'
With the following in my trips controller.
def report
@trips.all :condition => ["DATE(date) = DATE(?)", Time.now]
respond_to do |format|
format.html
format.json { render json: @trips }
end
end
I’m probably doing something very silly! Hopefully someone can help me along the right track?
You certainly have declared a
tripsresource in yourroutes.rb, and the routeGET 'trips/:id'generated by the resource have a higher priority then thematch 'trips/report'defined later (Rails uses the first matching rule). If it’s the case, declare yourreportroute like this:Look at this chapter in Rails Routing Guide for more information.