Display message if cookies are off?


How do I determine if a user has cookies turned off? Some of our users
in the corporate environment have cookies turned off and are complaining
that they can't log in. I'd like to display a message if this is the
case. How do I do this?

I've implemented something like this with a before_filter in my application
controller. Rails send a session cookie to the client after the first user
request. Check your application_controller.rb what it's called. Most times
it's called something like "_projectname_session_id" with projectname
replaced with the name of your application.

class ApplicationController < ActionController::Base
  session :session_key => '_projectname_session_id'
  before_filter :check_if_cookies_work


  def check_if_cookies_work
    flash[:alert] = "Please enable cookies!" if

Hope this helps.


You can also check session.new_session in the login action. If
cookies are turned off, this will be true all the time since rails
will attempt to set it on every request.