开发者

how does _path in views work?

开发者 https://www.devze.com 2023-03-29 05:50 出处:网络
开发者_运维百科I noticed in a couple of places either in the link_to method or the form_for method, while mentioning the url path, it been simply referred as model_path(eg product_path,users_path, ses

开发者_运维百科I noticed in a couple of places either in the link_to method or the form_for method, while mentioning the url path, it been simply referred as model_path(eg product_path,users_path, sessions_path). I wanna know how does it exactly works?


it will be clear to you if you go to your rails application folder in the console and type rake routes. This will show you all the routes in your application, in terms of _path.

For example if you have a scaffold for User. Then, here's the routes you will have:

users_path -> /yourapp/users/index        # route to your index action in the controller
new_user_path -> /yourapp/users/new       # route to your new action in the controller
edit_user_path -> /yourapp/users/:id/edit # route to your edit action in the controller
user_path -> /yourapp/users/:id/show      # route to your show action in the controller

I hope it is clear, what you wanted to know.

0

精彩评论

暂无评论...
验证码 换一张
取 消