I get wrong number of arguments (0 for 1) error.
The create action works with regular validates but authenticate/salt processing.
Please point out what does the message mean?
The create action works fine without calling and authenticate(us er_id, password).
But if put following code to model/ctkuser.rb, the error happens:
The create action works with regular validates but authenticate/salt processing.
Please point out what does the message mean?
The create action works fine without calling and authenticate(us er_id, password).
Code:
require 'digest/sha1'
class Ctkuser < ActiveRecord::Base
validates_presence_of :user_id
validates_uniqueness_of :user_id
attr_accessor :password_confirmation
validates_confirmation_of :password
validate :password_non_blank
#'passwrod' is a virtal attribute?
def password
@password
end
def password_non_blank
errors.add(:password, "Missing password") if hashed_password.blank?
end
end
Code:
def self.authenticate(user_id, password)
ctkuser = self.find_by_user_id(user_id)
if ctkuser
expected_password = encrypted_password(password, ctkuser.salt)
if ctkuser.hashed_password != expected_password
ctkuser = nil
end
end
ctkuser
end
#'passwrod' is a virtal attribute?
def password
@password
end
def password(pwd)
@password = pwd
return if pwd.blank?
create_new_salt
self.hashed_password = Ctkuser.encrpyted_password(self.password, self.salt)
end
private
def password_non_blank
errors.add(:password, "Missing password") if hashed_password.blank?
end
def create_new_salt
self.salt = self.object_id.to_s + rand.to_s
end
def self.encrypted_password(password, salt)
string_to_hash = password + "wibble" + salt
Digest::SHA1.hexdigest(string_to_hash)
end
Code:
ArgumentError in CtkusersController#create
wrong number of arguments (0 for 1)
Request
Parameters:
{"commit"=>"Add User",
"authenticity_token"=>"Yylcw4I9jalsAPL3sCNL8rmcAOr4GhaZiQ42fCv4IK4=",
"ctkuser"=>{"is_locked"=>"NO",
"user_role"=>"1",
"added_by"=>"SESSION-USER",
"hashed_password"=>"e343",
"updated_on"=>"2011-04-29",
"user_id"=>"TEST04282011_No51",
"updated_by"=>"SESSION-USER",
"last_name"=>"Chrey",
"agency_sequence"=>"2",
"added_on"=>"2011-04-29",
"is_change_password"=>"NO",
"first_name"=>"Melissa",
"email"=>"mCherey@mas.com"}}