【发布时间】:2016-11-21 17:17:52
【问题描述】:
如何在 URL 中显示没有 /posts/ 的博客文章?
http://www.anthonygalli.com/posts/i-walk-the-line
http://www.anthonygalli.com/posts/50-shades-of-galli
http://www.anthonygalli.com/posts/tips-for-regaining-momentum
缩短版(问题目标):
http://www.anthonygalli.com/i-walk-the-line
http://www.anthonygalli.com/50-shades-of-galli
http://www.anthonygalli.com/tips-for-regaining-momentum
我有 post 作为 MVC。
routes.rb
resources :posts
get 'about' => 'posts#about'
get 'feed' => 'posts#feed'
get 'subscribe' => 'posts#subscribe'
【问题讨论】:
-
你可以使用
'/:title' => 'posts#show'和resources :posts ,:except => :show -
后一行会产生这个错误:
undefined local variable or method 'except' for #<ActionDispatch::Routing::Mapper:0x007ff02d549fc8>我希望链接的两个版本都能正常工作,即缩短版本和当前版本@uzaif -
get :title => 'posts#show'试试这个
标签: ruby-on-rails ruby model-view-controller routes