Modify behavior of named route in Rails 3
In my rails blog I'm writing I want the "show" route for posts to always have the form of:
/year/开发者_如何学编程month/day/title
Currently I can accomplish this using a generic match:
match "/:year/:month/:day/:url_title", :to => "posts#show", :constraints => {:year => /(19|20)\d\d/, :month => /[01]?\d/, :day => /[0-3]?\d/}
Where my model is responsible for converting the title into a hyphen delimited string.
However, I need a way to integrate this behavior into the resource routing so that my post_path methods will continue to work - preferably by just passing in a post object.
I'm wondering if there's some way I can use the :as option to set the route, or do it with a block.
You answered the question yourself just use :as => :post
then post_path(@post)
will work!
精彩评论