在执行以下操作后,我遇到了 Devise 的问题:
- 我注册了一个新用户(工作正常)
- 我确认用户邮件(工作正常)。那时我已正常登录,一切正常。
- 现在,如果我注销并尝试重新登录,则会收到未经授权的错误 (401)。
在这里查看服务器日志会发生什么:
Started POST "/users/sign_in" for 127.0.0.1 at 2012-10-26 10:26:23 +0200
Processing by Users::SessionController#create as JSON
Parameters: {"email"=>"olivier.milla@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}
WARNING: Can't verify CSRF token authenticity
User Load (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'olivier.milla@gmail.com' LIMIT 1
(1.0ms) BEGIN
(0.0ms) COMMIT
(1.0ms) BEGIN
(0.0ms) UPDATE `users` SET `current_sign_in_at` = '2012-10-26 08:26:23', `sign_in_count` = 2, `updated_at` = '2012-10-26 08:26:23' WHERE `users`.`id` = 1
(25.0ms) COMMIT
Rendered devise/sessions/create.json.rabl (1.0ms)
Completed 200 OK in 135ms (Views: 22.0ms | ActiveRecord: 27.0ms)
Started GET "/accounts/new" for 127.0.0.1 at 2012-10-26 10:26:23 +0200
Processing by AccountsController#new as HTML
Completed 401 Unauthorized in 0ms
如您所见,我已登录,甚至devise/sessions/create.json.rabl
在我被重定向到我不再被授权的“/accounts/new”之后得到了一个呈现的视图()。然后我可以尝试访问我想要的任何 URL 并不断收到未经授权的消息。
我在一个新的数据库(db:reset)上尝试了这个,我尝试在登录之前清理 cookie。
知道这种行为可能来自哪里吗?
我将 Devise 2.1.2 与 Rails 3.2.8 一起使用。
更新
根据要求: AccountsController 代码:
class AccountsController < ApplicationController
before_filter :authenticate_user!
def :index
@accounts = current_organization.accounts
end
def new
@account = Account.new(:organization => current_organization)
end
def create
@account = Account.new(params[:account])
@account.organization = current_organization
if @account.save
redirect_to :index
else
#TODO
end
end
end