We have a structure where we want to view and edit records, filtered by day. But we want the day to be part of the url
/time_records/day
This view shows time_records for a particular day. But when we add a time_record, it needs to redirect back to the same page.
However, it invokes time_records without the “day” part in order to call create. In order to redirect back to the same page, I think I have to pass a model object to redirect_to, but that model would have to be the day itself.
Is the only solution to add a Day object to my model? This seems a bit of a waste as a DateTime is sufficient already logically, this is just about routing.
With:
in
routes.rbyou can use the url helper method:to generate
"/time_records/2011-01-21". This works in part because in Rails, Date objects respond to theto_parammethod.This all assumes you’re using ruby 1.9.x and rails 3.0.x