No commit activity in last 3 years
No release in over 3 years
Ensure cookies are enabled in a Rails app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2.3.0
 Project Readme

CookieRequirement

CookieRequirement verifies that cookies are enabled in a Rails app. Include the module in a controller, and declare the actions that require cookies with the cookies_required class method.

Example

class UserController

  include CookieRequirement

  cookies_required :login

  # if login is accessed without cookies, handle_cookies_disabled is called
  def login
  end

  def cookie_instructions
    # show some instructions
  end

protected

  # override the default behavior to display instructions
  def handle_cookies_diabled
    redirect_to :action => "cookie_instructions"
  end

end

How It Works

CookieRequirement adds a before_filter to the controller in which it is included. This filter checks if the invoked action requires cookies. If so, it sets a test cookie and redirects to the same action, adding a query parameter to indicate that a test cookie should exist. If the cookie does not exist after the redirection, CookieRequirement concludes that cookies are disabled and calls handle_cookies_disabled, which, by default, raises CookieRequirement::CookiesDisabled.

Note: CookieRequirement adds the before_filter when it is included. If you want other before_filters to run before CookieRequirement, declare them before including CookieRequirement.

Acknowledgments

CookieRequirement is based on: