I'm new to ROR. I tried for simple login with email and password. I can't authenticate the password. It's repeated question, and my error is not yet cleared with old questions. My code is
user = User.find_by_email(params[:email])
user.valid_password?(params[:password])
if @user = User.find_by_email(params[:user][:email]).valid_password?(params[:user][:password])
#render :json=> user.as_json(:status=>'success', :Message=>'Sucessfully Registered', :username=>user.username ), :status=>201
render :json=> {userDetails: [{:status=>'Success',:Message=>'Successfully Signed in', :username=>@user.name, :useremail=>@user.email, :usermobile=>@user.mobile_no }]}, :status=>200
else
render :json=> {:status=>'Failure',:message=>'Invalid Credentials'}, :status=>422
:message=>'Sucessfully Singed in', :auth_token=>user.authentication_token, :email=>user.email), :status=>201
end
I'm facing the below error
undefined method `valid_password?' for nil:NilClass
could anyone tell me what i'm doing incorrectly?
change the if line to