Wrong number of bind variables

I’m getting this error message since i moved alot of the database
logic to the model.
wrong number of bind variables (0 for 2) in: first_name = ? AND
last_name = ?

def self.authenticate(first_name, last_name, password)
user = User.find(:first, :conditions => [‘first_name = ? AND
last_name = ?’])
if user.blank?
Digest::SHA256.hexdigest(password + user.password_salt) !=
user.password_hash
raise “Username or password invalid”
end
user
end
end

I’m basically copying this out of Rails Recipes so not sure where the
error is.

Stuart

You’ll want to add the variables in at the end of the list,
indicating what you want to substitute in place of the question marks
(?):

user = User.find(:first, :conditions => [‘first_name = ? AND
last_name = ?’, first_name, last_name])

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

On Aug 7, 2006, at 12:57 PM, Dark A. wrote:

user = User.find(:first, :conditions => [‘first_name = ? AND
last_name = ?’])

user = User.find(:first, :conditions => ['first_name = ? AND

last_name = ?’ , first_name, last_name])

You left out the actual variables in that call. WHat I posted will

work fine.

-Ezra

On Mon, 2006-08-07 at 13:57 -0600, Dark A. wrote:

  raise "Username or password invalid"
  end
  user
  end
end

I’m basically copying this out of Rails Recipes so not sure where the error is.


I thought you’ve been at this long enough to spot it…

User.find(:first,
:conditions => [‘first_name =? AND last_name =?’, first_name,
last_name])

You’ve got 0 variables where 2 are needed for the find conditions

Craig

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs