我希望发生的情况是,一旦用户单击确认链接,并成功确认他们的账户,如果他们有特定的角色分配(在
我创建了一个
User
模型上的after_create
回调中已成功分配),则应将他们重定向到某个指定路径。我创建了一个
RegistrationsController
:class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
if resource.has_role? :seller
new_item_path
else
root_path
end
end
end
但是,这总是重定向到root_path
......尽管我已经验证了,用户确实拥有该角色。
编辑1
似乎确认请求从未发送到RegistrationsController
:
Started GET "/users/confirmation?confirmation_token=KRwZ7MChtxxq4sxxkDLq" for 127.0.0.1 at 2013-05-07 03:52:56 -0500
Processing by Devise::ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"KRwZ7MChtxxq4sxxkDLq"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'KRwZ7MChtxxq4sxxkDLq' LIMIT 1
(0.1ms) BEGIN
(0.5ms) UPDATE "users" SET "confirmation_token" = NULL, "confirmed_at" = '2013-05-07 08:52:56.846852', "updated_at" = '2013-05-07 08:52:56.847730' WHERE "users"."id" = 9
(0.8ms) COMMIT
(0.1ms) BEGIN
(0.4ms) UPDATE "users" SET "last_sign_in_at" = '2013-05-07 08:52:56.852250', "current_sign_in_at" = '2013-05-07 08:52:56.852250', "last_sign_in_ip" = '127.0.0.1', "current_sign_in_ip" = '127.0.0.1', "sign_in_count" = 1, "updated_at" = '2013-05-07 08:52:56.853180' WHERE "users"."id" = 9
(0.7ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 31ms (ActiveRecord: 3.2
编辑2
这是我的routes.rb
文件的内容:
devise_for :users, :path_names => { :sign_up => "register",
:sign_in => "login",
:sign_out => "logout",
:settings => "settings" },
:controllers => { :registrations => "registrations" }
devise_scope :user do
get "login", :to => "devise/sessions#new"
get "register", :to => "registrations#new"
get "settings", :to => "devise/registrations#edit"
get "logout", :to => "devise/sessions#destroy"
end