我有一班邮政
我希望每个帖子的默认网址为http://domain.com/9383而不是http://domain.com/posts/9383
我试图在路线中修复它.我设法接受domain.com/222但是如果我使用<%= url_for(@ postts)%>我仍然会收到domain.com/posts/222
我该怎么做?谢谢
您无法更改url_for(@post)路线的行为.如果实例传递给它,url_for将假设一个map.resources设置ActiveRecord.
你应该这样做:
# routes.rb
map.post ":id", :controller => "posts", :action => "show"
# named route
post_path(@post)
# full link_to
link_to @post.title, post_path(@post)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
371 次 |
| 最近记录: |