Sha256: 55685c731587e53a81fa9d5751a04f4983ec9caf2d93221d5d83d67c3eedc1f1

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

##
# Installs a before_filter into all controllers which echoes the
# request's method as a cookie named `_up_request_method`.
#
# The Unpoly requires this cookie to detect whether the initial page
# load was requested using a non-GET method. In this case the Unpoly
# framework will prevent itself from booting until it was loaded
# from a GET request. For the terrible reasons behind this see:

# - <https://github.com/rails/turbolinks/search?q=request_method&ref=cmdform>
# - <https://github.com/rails/turbolinks/blob/83d4b3d2c52a681f07900c28adb28bc8da604733/README.md#initialization>
module Unpoly
  module Rails
    module RequestMethod

      COOKIE_NAME = '_up_method'

      def self.included(base)
        base.before_filter :set_up_request_method_cookie
      end

      private

      def set_up_request_method_cookie
        if !request.get? && !up?
          cookies[COOKIE_NAME] = request.request_method
        else
          cookies.delete(COOKIE_NAME)
        end
      end

      ActionController::Base.send(:include, self)

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
unpoly-rails-0.35.1 lib/unpoly/rails/request_method_cookie.rb
unpoly-rails-0.35.0 lib/unpoly/rails/request_method_cookie.rb
unpoly-rails-0.34.2 lib/unpoly/rails/request_method_cookie.rb
unpoly-rails-0.34.1 lib/unpoly/rails/request_method_cookie.rb
unpoly-rails-0.34.0 lib/unpoly/rails/request_method_cookie.rb