2010-10-17 198 views
2

例如,考慮從耙路線下面的輸出: -
帖子 GET /posts(.:format){:行動=> 「索引」,:控制器=> 「職位」}
帖子POST /posts(.:format){:action =>「create」,:controller =>「posts」}
* new_post * GET /posts/new(.:format){:action =>「新的「,:控制器=>」帖子「}
* edit_post * GET /posts/:id/edit(.:format) {:action =>「edit」,:controller =>「posts」}
post GET /posts/:id(.:format){:action =>「show」,:controller =>「posts 「}如何自定義或更改軌道中的路徑路徑?

如果我想將」new_post「的路徑名更改爲」create_post「,我該怎麼做?

+0

是否運行的Rails版本的動詞? – ndrix 2010-10-17 19:47:52

回答

2

match '/posts/new' => 'posts#new', :as => :create_post在你的路線應該工作!

1

A '匹配' 在這裏是不恰當的。它可能會造成安全問題,因爲默認情況下,它會打開您匹配到每個請求動詞(get,post等)的路由。您應該指定地點比賽

get '/posts/new' => 'posts#new', as: :create_post 

,或者您可以指定要使用的動詞,用火柴

match '/posts/new' => 'posts#new', as: :create_post, via: [:get]