I have been struggling with this for a while and am at a loss. I have a
form allowing current users to log in and new users to create an
account. Upon hitting the submit buttons (one for each action) a method
gets called either ''new_user'' or
''create_user'', both makes use of a
method in my user model called ''authenticate''. The really
weird part is
that for creating a new user authenticate works fine but not for
''current_user''. To make things weirder, the calls are EXACTLY
the same!
In method new_user:
if request.post? and @user.save
session[:user] = User.authenticate( params[:user][:email],
params[:user]
[:password] ).id
redirect_to :action => ''welcome'', :id =>
@user.id
In current_user
if !@user.nil? and User.authenticate( params[:user][:email],
params[:user]
[:password] )
session[:user] = User.authenticate( params[:user][:email],
params[:user]
[:password] ).id
flash[:notice] = "<b style =
\"color:red\">Worked</b>"
redirect_to :action => ''welcome'', :id =>
@user.id
Authenticate looks like:
def self.authenticate(email, password)
user = User.find(:first, :conditions => [''upper(email) =
?'',
email.upcase])
if user.blank? ||
Digest::SHA256.hexdigest(password+user.password_salt)
!= user.password_hash
#raise "Unknown userid or password"
else
user
end
end
Erro message when current_user method is called:
can''t convert nil into String
#{RAILS_ROOT}/app/models/user.rb:18:in `+''
#{RAILS_ROOT}/app/models/user.rb:18:in `authenticate''
#{RAILS_ROOT}/app/controllers/music_controller.rb:64:in `current_user''
Now, given the fact that the call to new user works without throwing any
errors I''m amusing (aparently wrongfully) that the call to current_user
should work as well, especially since I can see that all the correct
parameters are being passed and therefore know that password is not
infact nil? Anyone have any ideas? Thanks,
-Shandy
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---