I am using nested resources as shown below, but I now need the ability to send in a date range parameter for paginating/filtering. I know the rule about no more than 1 nested resource, but I am not sure the proper way to apply a third variable to a route.
resources :projects do
resources :expenses
end
Should I just craft my own match statement, like:
match '/projects/:project_id/expenses/date/:start_date' => 'expenses#index', :as => 'view_expenses'
and then remove the nested resource?
I am concerned about sending a query string along, that I will have to somehow re-include it in all my paths, so I am guessing its something best handled with a route.
Just not sure if I am on the right track.
Thanks!
I think you would want to pass the date to the controller through a params hash. You could do this without having to mess with your paths. I’m not sure how you’re filtering the dates, but let’s say on your Expenses index page you have a search form that lets you filter by month and year.
The search form would look something like:
Then your Expense controller would look like:
You will of course want some default date range so that you don’t get an exception when no date params are passed.