[英]How to embed a route resource in a Devise route in Rails 6
Under normal circumstances if one wants to embed resources within other resources in Ruby on Rails in the routes.rb
file it would look like this:在正常情况下,如果想在 Ruby on Rails 的routes.rb
文件中嵌入其他资源,它看起来像这样:
# routes.rb
resources :parents do
resources :children
end
The above will allow for a url like http://localhost:3000/parents/1/children.以上将允许 url,如 http://localhost:3000/parents/1/children。
My question is how to achieve the same result with the default devise_for:parents
that exists in my routes.rb
file?我的问题是如何使用存在于我的routes.rb
文件中的默认devise_for:parents
获得相同的结果?
I tried:我试过:
# routes.rb
devise_for :parents do
resources :children
end
and it did not work properly.它不能正常工作。
Any help is greatly appreciated!任何帮助是极大的赞赏!
devise_for
only creates the routes related to signing up and in, so you would still use devise_for
只创建与注册和登录相关的路由,所以你仍然会使用
resources :parents do
resources :children
end
in your routes for nested resource paths.在嵌套资源路径的路由中。 There is a detailed answer here: Nested Resource with Devise - Rails3这里有一个详细的答案: Nested Resource with Devise - Rails3
If you generate the Devise controllers and views, you also need to specify those in your routes like this如果生成 Devise 控制器和视图,则还需要像这样在路由中指定它们
devise_for :parents, controllers: {
sessions: 'parents/sessions',
registrations: 'parents/registrations'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.