开发者

Mask the name of a controller, Rails

开发者 https://www.devze.com 2022-12-20 11:28 出处:网络
I have a controller posts: www.mydomain.com/posts/123-hello Please bear in mind that the 123 is unique for each post but is not the correlative id (post.permalink)

I have a controller posts: www.mydomain.com/posts/123-hello

Please bear in mind that the 123 is unique for each post but is not the correlative id (post.permalink)

I want to access the posts through addresses like:

www.mydomain.com/is/123-hello

not

www.mydomain.com/posts/123-hello

I have a to_param in my Post m开发者_StackOverflowodel to construct the "123-hello", but when I use redirect_to @post I end in www.mydomain.com/posts/123-hello

How can I do this? Thanks in advance!


map.resources :posts, :as => "is"

For the permalink part, see this question (but it looks like you've already got it right):

Rails routing - custom routes for Resources

0

精彩评论

暂无评论...
验证码 换一张
取 消