开发者

Saving a record in Authlogic table

开发者 https://www.devze.com 2023-02-01 02:25 出处:网络
I am using authlogic to do my authentication. The current model that serves as the authentication model is the user model. I want to add a \"belongs to\" relationship to user which means that I need a

I am using authlogic to do my authentication. The current model that serves as the authentication model is the user model. I want to add a "belongs to" relationship to user which means that I need a foreign key in the user table. Say the foreign key is called car_id in the user's model. However, for some reason, when I do

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

I get

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

My guess is that this has something to do with authlogic. I do not have validation on password on the user's model. This is the migration for the user's table.

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.times开发者_Go百科tamps
    end
  end

And later I added the car_id column to it.

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

Is there anyway for me to turn off this validation?


Sure. Per the docs:

acts_as_authentic do |c|
  c.ignore_blank_passwords = true
end
0

精彩评论

暂无评论...
验证码 换一张
取 消