This seems like it should be easy to do, but I’m not sure how offhand.
I have State and Statute models, and currently use paths like these:
/california/statutes/robbery
/newyork/statutes/burglary
using this route:
match '/:state_id/statutes/:id' => 'statutes#show', :as => :state_statute, :id => /[^\/]+/
But the thing is, in California, statutes are called codes. And in NY, they’re laws.
My question is, how could I automatically support these more meaningful paths:
/california/codes/robbery
/newyork/laws/burglary
I have this information stored in the model, which can be used; Statute.meta_name.
This should work:
The problem with this is that both these urls would work:
Which is generally bad for SEO. You could fix that by adding a before filter like:
— Edit —
To make the generation of routes easier, use a route like:
And in application_controller, or preferably a lib file, you could add: