# Display message if cookies are off?

**URL:** <https://www.ruby-forum.com/t/display-message-if-cookies-are-off/103708>\
**Category:** Rails\
**Created:** [May 9, 2007, 3:04pm UTC](https://www.ruby-forum.com/t/display-message-if-cookies-are-off/103708 "2007-05-09T15:04:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [May 9, 2007, 3:04pm UTC](https://www.ruby-forum.com/t/display-message-if-cookies-are-off/103708/1 "2007-05-09T15:04:19Z")

</div>

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?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [May 9, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/display-message-if-cookies-are-off/103708/2 "2007-05-09T16:27:33Z")

</div>

Hi,

> 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  
…

protected

def check\_if\_cookies\_work  
flash[:alert] = “Please enable cookies!” if  
cookies[:\_projectname\_session\_id].nil?  
end  
…  
end

Hope this helps.

Regards,  
Timo

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [May 12, 2007, 9:27am UTC](https://www.ruby-forum.com/t/display-message-if-cookies-are-off/103708/3 "2007-05-12T09:27:08Z")

</div>

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.

On May 9, 10:26 pm, Timo S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
