I have a very straightforward user model that runs fine on my
development machine, but on Heroku attempting to create a user gives
me an undefined method error for 'salt=', even when using the console.
On my machine:
>> u=User.new
=> #<User id: nil, email: nil, hashpass: nil, login: nil, name: nil,
salt: nil, enabled: nil, created_at: nil, updated_at: nil>
>> u.email="ted"
=> "ted"
>> u.password="ted"
=> "ted"
>> u.password_confirmation="ted"
=> "ted"
>> u.save
=> true
On Heroku:
>> u=User.new
#<User id: nil, email: nil, hashpass: nil, login: nil, name: nil,
created_at: nil, updated_at: nil>
>> u.email="ted"
"ted"
>> u.password="ted"
NoMethodError: undefined method `salt=' for #<User:0xb68a7ae4>
Any tips on fixing are most appreciated. Does "private" mean something
different?
Code in .../app/models/user.rb:
require 'digest/sha1'
class User < ActiveRecord::Base
has_many :subjects
validates_presence_of :email
validates_uniqueness_of :email
attr_accessor :password_confirmation
validates_confirmation_of :password
def validate
errors.add_to_base("Missing password") if hashpass.blank?
end
def self.authenticate(email, password)
user = self.find_by_email(email)
if user
expected_password = encrypted_password(password, user.salt)
if user.hashpass != expected_password
user = nil
end
end
user
end
#'password' is a virtual attribute
def password
@password
end
def password=(pwd)
@password = pwd
return if pwd.blank?
create_new_salt
self.hashpass = User.encrypted_password(self.password, self.salt)
end
private
def self.encrypted_password(password, salt)
string_to_hash = password + "childdeverv" + salt
Digest::SHA1.hexdigest(string_to_hash)
end
def create_new_salt
self.salt = self.object_id.to_s + rand.to_s
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Heroku" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/heroku?hl=en
-~----------~----~----~----~------~----~------~--~---