我使用Devise進行網站身份驗證。我有我的用戶模型設置如下:在登錄時設計401
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:token_authenticatable, :confirmable
attr_accessible :email, :name, :password, :password_confirmation, :remember_me, :college_id, :role
有以下途徑:
devise_for :users
as :user do
get 'sign_in' => 'devise/sessions#new', :as => :login
post 'sign_in' => 'devise/sessions#create', :as => :user_session
delete 'sign_out' => 'devise/sessions#destroy', :as => :logout
get 'signup' => 'devise/registrations#new', :as => :signup
get 'forgot_password' => 'devise/passwords#new', :as => :forgot_password
get 'resend_confirmation' => 'devise/confirmations#new', :as => :resend_confirmation
end
和我收到以下錯誤:
Started POST "/sign_in" for 127.0.0.1 at 2013-05-06 19:57:34 -0400
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"iy0BI3A6zY5TTIJ2eYkOpgwFIFubO2O8wII8GAmjDmE=", "email"=>"[email protected]", "password"=>"[FILTERED]", "x"=>"-630", "y"=>"-434"}
Completed 401 Unauthorized in 1ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"iy0BI3A6zY5TTIJ2eYkOpgwFIFubO2O8wII8GAmjDmE=", "email"=>"[email protected]", "password"=>"[FILTERED]", "x"=>"-630", "y"=>"-434"}
這是顯示在用戶界面上向上作爲「無效的電子郵件或密碼」。但是我確信輸入的密碼是正確的,並且用戶存在於數據庫中(通過控制檯驗證)。設計似乎沒有對數據庫進行任何查詢。這是正常的嗎?
任何想法?所有的幫助表示讚賞。
確保您的設計控制器的定製版本不要求您進行認證。確保它們是原始設計基類的擴展,而不僅僅是'ApplicationController'。它看起來像設置,以便應用程序要求您進行身份驗證才能進行身份驗證。你能告訴我們你的'SessionsController'嗎? – PaReeOhNos 2013-05-07 00:46:13
我沒有自定義的SesssionController,我完全使用Devise控制器。 – NolanDC 2013-05-07 01:40:39
嗯,爲什麼你有'as:用戶做'塊呢?對於普通的老設計,你只需要'devise_for:users'。嘗試評論整個區塊,看看是否有幫助? – PaReeOhNos 2013-05-07 01:41:39