I've been trying to setup Authlogic for the first time but I'm confused.
I have set it up as per the example in the authlogic_example code however it doesn't appear to run:
u = User.new(:password=>'testpass',
:password_confirmation => 'testpass',
:email => 'test@test.com')
=> #<User id: nil, email: "test@test.com", created_at: nil, updated_at: nil,
first_name: nil, last_name: nil, crypted_password: nil,
password_salt: nil, persistence_token: nil>
>> u.valid?
=> false
>> u.errors
=> #< OrderedHash {:password=>["is too short (minimum is 4 characters)"],
:password_confirmation=>["is too short
(minimum is 4 characters)"]}>
It looked like :password and :password_confirmation simply weren't being set so in class User I made :password and :password_confirmation accessible attributes:
class User < ActiveRecord::Base
acts_as_authentic
attr_accessible :password, :password_confirmation # changed code
end
That worked:
>> u = User.new(:password=>'testpass',:password_confirmation => 'testpass',
:email => 'test@test.com')
=> #<User id: nil, email: "test@test.com", created_at: nil, updated_at: nil,
first_name: nil, last_name: nil,
crypted_password: "446edcbee34254ea83b8d469baef2dc34d723e710faf22efb97...",
password_salt: "hZFVKUo66meyrZ97Gb",
persistence_token: "b469fefd82a91683bf51b5eb9dbc15563b569a93ce973a42595...">
>> u.valid?
=> true
Whilst this worked, I'm concerned that I've been doing something wrong because in the authlogic_example, there are no attr_accessible set in user:
# Authlogic_example code
class User < ActiveRecord::Base
acts_as_authentic
end
Why is it that the authlogic_example code works without explicitly setting the attributes to be being accessible but mine doesn't?