There used to be no clean solution to this. Assuming you do not have control over the before_filters
(or do not want to change them), i would leave the skip_before_filter
and add an extra before_filter
that only executes the wanted methods if it is an xhr
method.
So something like
skip_before_filter :load_something, # how to skip these only
:load_something_else # if the request is xhr ?
before_filter :do_loads_if_xhr
def do_loads_if_xhr
if request.xhr?
load_something
load_something_else
end
end
The method described here only works because the conditional is global for the application: the conditional is only evaluated when the class is created. Not on each request.
[UPDATED]
There is however, a cleaner way to make the skip_before_filter
conditional. Write it like this:
skip_before_filter :load_something, :load_something_else, :if => proc {|c| request.xhr?}
Also note that while skip_before_filter
is still completely supported, and not deprecated, since rails 4 the documentation seems to prefer the (identical) skip_before_action
. Also the documentation is totally not clear about this, had to verify in code.