undefined method `before_create' for main:Object

  • Thread starter Sathiyaraj Gurusamy
  • Start date
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, :eek:rder => "created_at DESC"
has_many :sessions, :through => :user_sessions
attr_accessor :password,:password_confirmation
validates_uniqueness_of :username,:email_address,:mobile,:scope =>
"active"
validates_confirmation_of :password, :eek: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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top