Forum: Ruby on Rails Flashing Login Notice To Non Authenticated Users

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Justin W. (Guest)
on 2006-01-15 21:03
Greetings,

I'm working with the salted hash login generator.  Is there a way to
post a flash message if the user isnt authenticated for a section of my
site and has to login?  If so, where should I implement it?

To understand what I am talking about, try and visit a Basecamp page
without being authenticated.  It posts a notice flash telling you to
login.  If you just directly visit the login page, however, there is no
flash.

Thanks for the help.

- justin
Jules (Guest)
on 2006-01-15 22:38
I don't know how this logingenerator works, but:

there should be a before_filter somewhere, this executes a method before
each request. It could be in app/controllers/application_controller.rb.
In this before_filter there should be something like:

def authenticate
  if {valid_login}
    true
  else
    redirect_to :controller => 'login'
    false
  end
end

You can insert the flash here:

def authenticate
  if {valid_login}
    true
  else
    flash[:notice] = 'Not logged in'
    redirect_to :controller => 'login'
    false
  end
end
This topic is locked and can not be replied to.