rails routes中resource和resources的区别
source link: http://blog.ilibrary.me/2020/09/13/rails-routes%E4%B8%ADresource%E5%92%8Cresources%E7%9A%84%E5%8C%BA%E5%88%AB
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
rails routes中resource和resources区别是什么?
区别是, resource生成的路径永远不带id, 也没有index路径. 即使嵌套memmber do
,路径里面也不会有/:id/
这部分值。
resources生成的路径带id, 还会默认生成 index. resources :classes do
下面的路径默认会添加/:class_id/
.
可以在resources下面嵌套resources, 这样就可以在rails routes
里面清楚得看到嵌套的id代办的是啥. /:resource1_id/resource2/:resource2_id/
resources下面member do
下面的路径默认添加/:id/
做为路径的一部分。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK