I'm quite new with Ruby language and Rails. I'm currently building some simple user registration process. When I used these codes Rails throws: no implicit conversion from nil to string
Here's the original code:
require 'digest'
class User < ActiveRecord::Base
before_save :encrypt_password
protected
def encrypt_password
return if password.blank?
password = encrypt(password)
end
def encrypt(string)
Digest::SHA1.hexdigest(string)
end
end
But it works if I changed this line password = encrypt(password)
, to self.password = encrypt(password)
. I'm just curious, what's wrong with the first code?