How to define a custom path in rails?

和自甴很熟 提交于 2019-12-03 12:50:15

You can also customize restful routes. For example in my application only the index and show actions are appropriate for certain controllers. In my routes.rb file I have some routes like this:

map.resources :announcements, :only => [:index, :show]

You can also use :except if that's more appropriate.

Since I came here looking for a way to create helpers in routes.rb, here is the way to do it:

get '/users/:id/' =>'users#show', :as => :user

You can map custom routes in your routes.rb file like this...

map.users '/users', :controller => 'user', :action => 'index'

This gives you the users_path helper you're looking for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!