0

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   
user3281827
  • 53
  • 2
  • 12

3 Answers3

0
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 
usha
  • 28,973
  • 5
  • 72
  • 93
0

Are you rendering the notice messages in your view?

<% flash.each do |name, msg| %>
  <%= msg %>
<% end %>
followfung
  • 53
  • 2
  • 7
  • Thank your for help this is close, when I type in the wrong username it says invalid user name which is what I want however, when I first go to the page it says invalid log in please try again before I put in a username – user3281827 Mar 06 '14 at 18:01
  • See this: http://stackoverflow.com/questions/5142527/how-to-show-the-flash-message-in-rails-only-once This is assuming that you hit the Back button or backspace on your browser – followfung Mar 06 '14 at 18:07
0

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)

rshibli
  • 11
  • 3