下面的例子:
devise_for :users, :path => 'accounts'
resources :users do
resources :orders
end
上面的意思是认证路径是"/accounts/sign_in"
,"/accounts_sign_up"
等等。有些人可能不知道承认devise_for :users
并没有实际映射到UsersController
模型是很重要的。它甚至不是资源路线,尽管许多人认为它看起来像。这就是为什么我们不能这样对待它:
devise_for :users do
resources: somereosouce
end
所做devise_for
的只是映射以下路线:
# Session routes for Authenticatable (default)
new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
destroy_user_session GET /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
# Password routes for Recoverable, if User model has :recoverable configured
new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
# Confirmation routes for Confirmable, if User model has :confirmable configured
new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
因此,说您可以执行以下操作但会产生一些冲突:
devise_for :users
resource :users do
resource :foo_object
end
如果您有以下内容,请稍微介绍一下嵌套资源:
class Users < ActiveRecord::Base
has_many :foo_object
end
class FooObject < ActiveRecord::Base
belongs_to :users
end
那么您的嵌套资源将是
resource :users do
resource :foo_object
end
希望这可以解决问题。此外,您可能想阅读带有设计的嵌套资源 - Rails3