rails嵌套资源的具名路由

假设有一个user模型,那么,users_path对应index的action,不需要参数,而对于user_path(),后面需要一个参数作为id,例如user_path(@user),表示@user对应的页面,具体含义与get/patch/delete有关

而edit_user_path(@user)和new_user_path与edit和new有关,create没有对应的具名路由。

如果给user嵌套了post资源,其实并没有太过复杂。

index对应了user_posts_path(@user)

get/patch/delete对应了user_post_path(@user,@post),只不过需要两个参数而已。

edit对应edit_user_post_path(@user,@post)

new对应new_user_post_path(@user,@post)

原文地址:https://www.cnblogs.com/lilyxue/p/5453312.html