我試圖(失敗)設置Authlogic我的Rails3中的項目。在user_sessions#新的觀點,我不斷收到以下錯誤:設置Authlogic我一直打:「爲#未定義的方法'登錄<UserSession:未提供憑證>」
undefined method `login' for #<UserSession: no credentials provided>
Extracted source (around line #7):
5: <%= form_for(:user_session, :url => user_session_path) do |f| %>
6: <%= f.label :login %><br>
7: <%= f.text_field :login %><br>
8: <%= f.password_field(:password) %>
9: <%= f.submit %>
10: <% end %>
我相信錯誤來,因爲Authlogic未能檢測到哪些數據庫列應該用於登錄域。
我的理解是下Authlogic應該依傍:電子郵件列,如果沒有登錄列是存在的。對於帶和揹帶我嘗試添加一個配置選項,用戶類,但它仍然沒有解決問題
這裏是我的代碼:
用戶模式
class User < ActiveRecord::Base
attr_accessible :password, :password_confirmation
acts_as_authentic do |c|
c.login_field = :email
end
end
UserSessions控制器
class UserSessionsController < ApplicationController
def new
@user_session = UserSession.new
end
# ...
end
UserSessions#新視圖
<%= form_for(:user_session, :url => user_session_path) do |f| %>
<%= f.label :login %><br>
<%= f.text_field :login %><br>
<%= f.password_field(:password) %>
<%= f.submit %>
<% end %>
UserSession模式
class UserSession < Authlogic::Session::Base
# configuration here, see documentation for sub modules of Authlogic::Session
end
DB模式(用於authlogic表)
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "users", :force => true do |t|
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
t.string "last_name"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
end
爲什麼不Authlogic使用登錄專欄中,我告訴它(或者甚至是這個問題)?
呃 - 謝謝!我花了很長時間試圖弄清楚,但還是像簡單的修復! – 2011-04-06 23:47:36