S
Sathiyaraj Gurusamy
Hi,
ruby=1.9.2
rails=3.0.1
I am developing simple user registration application using ruby on rails
my model is
require 'digest/sha2'
class User < ActiveRecord::Base
has_many :user_sessions,
rder => "created_at DESC"
has_many :sessions, :through => :user_sessions
attr_accessor
assword,
assword_confirmation
validates_uniqueness_of :username,:email_address,:mobile,:scope =>
"active"
validates_confirmation_of
assword,
n => :create, :message =>
"Passwords does not match"end
before_create :hash_password
private
# Digests the password given and stores a unique salt and hash as a
results
def hash_password
return if self.password.blank?
self.password_salt =
[Array.new(6){rand(256).chr}.join].pack("m").chomp
self.password_hash = generate_password_hash(self.password) unless
self.password.blank?
end
def generate_password_hash(password)
Digest::SHA256.hexdigest(password + self.password_salt)
end
controller
def new
if request.post? and params[:user]
@user = User.new(params[:user])
if @user.save
session[:user_id] = @user.id
flash[:notice] = "User #{@user.username} created!"
redirect_to :action => "index"
end
end
end
But when i try to registration i got below error
"undefined method `before_create' for main:Object"
Any help would be appreciate
thanks and regards,
sathiya_rails
ruby=1.9.2
rails=3.0.1
I am developing simple user registration application using ruby on rails
my model is
require 'digest/sha2'
class User < ActiveRecord::Base
has_many :user_sessions,
has_many :sessions, :through => :user_sessions
attr_accessor
validates_uniqueness_of :username,:email_address,:mobile,:scope =>
"active"
validates_confirmation_of
"Passwords does not match"end
before_create :hash_password
private
# Digests the password given and stores a unique salt and hash as a
results
def hash_password
return if self.password.blank?
self.password_salt =
[Array.new(6){rand(256).chr}.join].pack("m").chomp
self.password_hash = generate_password_hash(self.password) unless
self.password.blank?
end
def generate_password_hash(password)
Digest::SHA256.hexdigest(password + self.password_salt)
end
controller
def new
if request.post? and params[:user]
@user = User.new(params[:user])
if @user.save
session[:user_id] = @user.id
flash[:notice] = "User #{@user.username} created!"
redirect_to :action => "index"
end
end
end
But when i try to registration i got below error
"undefined method `before_create' for main:Object"
Any help would be appreciate
thanks and regards,
sathiya_rails