Is there any way to skip the before filter for an action when an API call is being made?
So generally I want before_filter x to be executed EXCEPT when I'm doing an API call.
skip_before_filter :x, :except => API CALL BEING MADE
It depends a little in how you define an API call. If it's any request with a JSON format you could do something like this:
skip_before_action :x if: -> { request.format.json? }
This doesn't seem to be an ideal solution though, and it might be better to make separate controllers for Web and API. You might do something along these lines:
class APIController < ApplicationController
# API-specific filters
end
class SomeOtherController < APIController
# your API actions
end
And you'd do the same for web, then configure your routes to take the request to the correct controller action.
Hope that helps.
In your controller you can add
skip_before_action :x, only: WHEN API CALL BEING MADE
I guess, you would want only
and not except
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With