In my SessionController, I tried to authenticate the user but it's
failing to authenticate even though I output the information and it's
all correct.I'm following this tutorial:
https://youtu.be/Hw6WtWJwRtU?list=PLS-X3A6Dr2qPXTSxMf6XPiO9HCkJLe51z

Below is my code:

def create
    user = User.find_by(email: params[:email].downcase)
    if user && user.authenticate(params[:password])
        session[:user_id] = user.id
        flash[:notice] = "Welcome back, #{user.name}!"
        redirect_to user
    else
        flash.now[:alert] = "Invalid email/password combination!
#{user.name}, #{user.id}, #{params[:password]}"
        render :new
    end
end
def destroy
    session[:user_id] = nil
    redirect_to :new
end

The authenticate works fine in rails console but not when the rails
server. The problem is with this line
user.authenticate(params[:password]) of code.

Any help is much appreciated.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/13583a22448c3a38bc18dc44cf1a9e7a%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to