Cookie requirement plugin

Plugin details

CookieRequirement is a Rails plugin that lets you ensure that cookies are enabled. Include the module in a controller, and declare the actions that require cookies with the +cookies_required+ class method.

Websitehttp://blog.jonahb.com/?p=9 Repositoryhttp://svn.jonahb.com/projects/cookie_requirement/ Author Jonah Burke Tags Cookie LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.jonahb.com/projects/cookie_requirement/

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

    # we override the default behavior (an exception) 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 +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.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: scott, about 1 year ago