lib/pjax.rb in pjax_rails-0.2.2 vs lib/pjax.rb in pjax_rails-0.3.0
- old
+ new
@@ -7,10 +7,15 @@
before_filter :strip_pjax_param, :if => :pjax_request?
before_filter :set_pjax_url, :if => :pjax_request?
end
+ class Error < StandardError; end
+ class Unsupported < Error; end
+
+ rescue_from Pjax::Unsupported, :with => :pjax_unsupported
+
protected
def pjax_request?
env['HTTP_X_PJAX'].present?
end
@@ -21,12 +26,31 @@
def pjax_container
return unless pjax_request?
request.headers['X-PJAX-Container']
end
+ def pjax_unsupported
+ head :not_acceptable
+ end
+
+ # Call in a before_filter or in an action to disable pjax on an action.
+ #
+ # Examples
+ #
+ # before_filter :prevent_pjax!
+ #
+ # def login
+ # prevent_pjax!
+ # # ...
+ # end
+ #
+ def prevent_pjax!
+ raise PjaxUnsupported if pjax_request?
+ end
+
def strip_pjax_param
params.delete(:_pjax)
- request.env['QUERY_STRING'].sub!(/_pjax=[^&]+&?/, '')
+ request.env['QUERY_STRING'] = request.env['QUERY_STRING'].sub(/_pjax=[^&]+&?/, '')
request.env.delete('rack.request.query_string')
request.env.delete('rack.request.query_hash')
request.env.delete('action_dispatch.request.query_parameters')