This project is archived and is in readonly mode.
named routes not recognizing parameters
-
Andrew White
- State changed from new to invalid
- Importance changed from to Low
Firstly the reason that model_x_path(@instance) gives '/model_xs/1' is that the to_param method returns the model id by default. Override to_param to return the slug if that's what you want.
The second error is because multiple routes share the url helper model_x_path and the last one declared has precedence. In this case it's the destroy action so it's looking for an :id parameter rather than a :slug parameter. Moving the match route after the resources call makes it work but model_x_path(:id => @model.id) then doesn't work.
If you stick to positional arguments then it will work - model_x_path(@model.id) and model_x_path(@model.slug). Also using url_for will select the correct route. However it's easier to remove the match route and use the default show route generated by the resources call - the params in the url are not tied to the model in anyway.