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 Johnson (canadaduane) http://blog.inquirylabs.com/ On Aug 7, 2006, at 1:57 PM, Dark Ambient wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On Aug 7, 2006, at 12:57 PM, Dark Ambient 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/54fca71d/attachment.html
On Mon, 2006-08-07 at 13:57 -0600, Dark Ambient wrote:> 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. >---- 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