I am new at ruby on rails and I am trying to set up a simple log in for a part of the site. I have gotten the log in to work however when the user puts in a incorrect username, I want a message to say "Invalid log in. Try again." I can not figure this out any help would be greatly appreciated
HERE IS MY CODE IN MY CONTROLLER
class SimpleloginController < ApplicationController
def namein
end
def transmain
@familyname_out = params[:family_name_in] #textbox name from the input file
name_out = params[:family_name_in]
if found = Family.find_by_name(name_out)
redirect_to manin_manout_path, :notice => "Logged in successfully"
else
redirect_to simplelogin_namein_path, :notice => "Invalid login. Try again"
end
end
end
def transmain
unless Family.find_by_name(params[:family_name_in]).blank?
redirect_to manin_manout_path, :notice => "Logged in successfully"
else
redirect_to simplelogin_namein_path, :notice => "Invalid login. Try again"
end
end
Are you rendering the notice messages in your view?
<% flash.each do |name, msg| %>
<%= msg %>
<% end %>
I'm not sure about the behavior you're experiencing, but I think this line
if found = Family.find_by_name(name_out)
will return a RecordNotFound error if name_out doesn't exist in the db.
For a good look at authentication with rails check out Ryan Bates' Railcast Authentication from Scratch (Revised)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.