Question

I haven't used optional parameters in routes often, and this problem has got me stumped: I have the following route defined as the first route in routes.rb:

get '/employees/hours_summary(/:year/:month/:day(:/prev_or_next))' => 'employees#hours_summary', as: :employees_hours_summary

rake routes indicates that it's OK:

employees_hours_summary GET /employees/hours_summary(/:year/:month/:day(:/prev_or_next))(.:format) employees#hours_summary

But this route fails:
localhost:3500/employees/hours_summary/2014/02/02/next

Routing Error: No route matches [GET] "/employees/hours_summary/2014/02/02/next"

while this one works fine (omitting the "/next" on the end): localhost:3500/employees/hours_summary/2014/02/02

Am I missing something really obvious here? This route seems to match the examples given in the Rails guide on routing.

Was it helpful?

Solution

You have a typo in the route. It should be /:prev_or_next not :/prev_or_next

get '/employees/hours_summary(/:year/:month/:day(/:prev_or_next))' => 'employees#hours_summary', as: :employees_hours_summary

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top