Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Fredy Mena Andrade's Profile

GitHub User: xfry

Comments by Fredy Mena Andrade

Avatar

Hi guys, some of you can help me?
I have made all the video tutorial Rails Authentication Form Scratch Revised full.
But when i try to login with a email and one passowrd seems that my if statement has not evaluated the user.authenticate(params[:password]) because its never began login, in fact it is always evaluated the else statement of my if statement

this is my source code: SessionsController

def new
end

def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password_digest])
session[:user_id] = user.id
redirect_to root_path, :notice => "Bienvenido a Alertab"
else
flash.now.alert = "Tu correo o clave es invalida, intenta de nuevo"
render "new"
end
end

def destroy
session[:user_id] = nil
redirect_to root_path, :notice => "Session cerrada"
end

And here are my view source code:

Inicia Sección
<%=form_tag login_path do%>

<%= label_tag "Correo" %>
<%= email_field_tag :email, params[:email] %>


<%= label_tag "contraseña" %>
<%= password_field_tag :password %>


<%= submit_tag "Inicia Sección"%>

<%end%>
<%= link_to raw("← Regresar"), root_path %>

And here are console response:

Started POST "/login" for 127.0.0.1 at 2013-02-24 09:50:26 -0500
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"3xavsOw949fhLAIj/ypGq4eNpsQ2x3TSEx7/JS/898s=", "email"=>"my@gmail.com", "password"=>"[FILTERED]", "commit"=>"Inicia Sección"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'my@gmail.com' LIMIT 1
Rendered sessions/new.html.erb within layouts/application (1.3ms)
Completed 200 OK in 13ms (Views: 11.7ms | ActiveRecord: 0.2ms)