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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Springmann <t.springm...-yM2StcZat7YdDX0dnZFiFbNAH6kLmebB@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---