2010-12-23 28 views
0

我正在使用authlogic進行身份驗證。用作認證模型的當前模型是用戶模型。我想爲用戶添加「屬於」關係,這意味着我需要在用戶表中使用外鍵。假設外鍵在用戶模型中被稱爲car_id。然而,由於某些原因,當我做在Authlogic表中保存記錄

u = User.find(1) 
u.car_id = 1 
u.save! 

我得到

ActiveRecord::RecordInvalid: Validation failed: Password can't be blank 

我的猜測是,這已經是與authlogic。我沒有驗證用戶模型的密碼。這是用戶表格的遷移。

def self.up 
    create_table :users do |t| 
     t.string :email 
     t.string :first_name 
     t.string :last_name 
     t.string :crypted_password 
     t.string :password_salt 
     t.string :persistence_token 
     t.string :single_access_token 
     t.string :perishable_token 
     t.integer :login_count,   :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns 
     t.integer :failed_login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns 
     t.datetime :last_request_at         # optional, see Authlogic::Session::MagicColumns 
     t.datetime :current_login_at         # optional, see Authlogic::Session::MagicColumns 
     t.datetime :last_login_at          # optional, see Authlogic::Session::MagicColumns 
     t.string :current_login_ip         # optional, see Authlogic::Session::MagicColumns 
     t.string :last_login_ip          # optional, see Authlogic::Session::MagicColumns 
     t.timestamps 
    end 
    end 

後來我在其中添加了car_id列。

def self.up 
    add_column :users, :user_id, :integer 
    end 

是否有反正我關閉此驗證?

回答

0

當然。每the docs

acts_as_authentic do |c| 
    c.ignore_blank_passwords = true 
end