没有型号名称的路由 [英] Routing without the model name
问题描述
使用此问题和 railscast 63 我已将我的文章发送到article / article_permalink。
Using this question and railscast 63 I've got my articles routed to articles/article_permalink.
我希望可以在URL中没有模型名称的情况下访问它们,因此my-domain.com/article_permalink可直接将其路由到文章。我只希望在表演动作中发生这种情况。
I'd like them to be accessible without the model name in the url so my-domain.com/article_permalink routes directly to the article. I'd only want this to happen on the show action. Is this possible?
推荐答案
我认为您需要类似...
I think you need something like ...
(在routes.rb中)
(in routes.rb)
match '/:id' => 'articles#show', :via => 'get'
(需要倒数第二条路线,因为它可以匹配请求
(needs to be last, or towards the end of the routes as it can match requests intended for other routes)
要更改article_path(...)助手, as可能会有所帮助: http://guides.rubyonrails.org/routing.html#overriding-the-named-helpers
To change the article_path(...) helpers, "as" might help: http://guides.rubyonrails.org/routing.html#overriding-the-named-helpers
或者您可以为该特定路径添加帮助器。
Or you can add a helper for that specific path.
这篇关于没有型号名称的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!