如何在 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'
最佳答案
将您的 routes.rb
更改为:
resources :posts, path: '/' do
collection do
get 'about'
get 'feed'
get 'subscribe'
end
end
有关 Rails 路由检查的文档:http://guides.rubyonrails.org/routing.html
关于ruby-on-rails - 如何从 URL 中删除/发布/?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38447895/