我正在尝试使用 Rails 4.0.0 设置 Devise 3.1.0。
我已经像这样配置了我的路由器:
devise_for :users,
:controllers => {
:registrations => 'users/registrations',
:sessions => 'users/sessions'
},
:path_names => {
:sign_in => 'login',
:sign_out => 'logout',
:sign_up => 'new'
}
new_user_session GET /users/login(.:format) users/sessions#new
user_session POST /users/login(.:format) users/sessions#create
destroy_user_session DELETE /users/logout(.:format) users/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/new(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
我还打开了作用域视图,并覆盖了默认视图和注册控制器:
# config/initializers/devise.rb
config.scoped_views = true
rails generate devise:views users
# app/controllers/users/registrations_controller.rb
#
# NOTE: I created this class, so creating new users could only be done by authenticated users.
#
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!
prepend_before_filter :authenticate_scope!
skip_before_filter :require_no_authentication
end
# app/controllers/users/sessions_controller.rb
# (currently empty)
class Users::SessionsController < Devise::SessionsController
end
问题:
为什么设计:path_names
在某些情况下会忽略上述设置?
例如,此方法不会使用:sign_in
上面的设置,并返回错误的路径:
new_session_path(resource_name)
=> /users/sign_in
resource_name
=> user
而此方法返回正确的路径:
new_user_session_path
=> /users/login
问题是,Devise 内部使用前一种方法,并且在用户未登录时不断重定向到错误的路径。
我是否配置错误,或者设计工作不正常?这可能是 Rails 4 的问题吗?