I have a controller with many actions (let's say action1, action2, action3, and action4). I have a before_action filter I'd like to exclude on some actions, close to:
before_action :filter_thing, except: [:action3, :action4]
However, I want the filter to be conditionally called for action2.
I tried simply splitting it into two before_actions but the second seemed to overwrite the first; in the following code filter_thing wasn't called for action1:
before_action :filter_thing, except: [:action3, :action4]
before_action :filter_thing, only: [:action2], unless: :should_not_filter?
I thought that maybe I could use a conditional skip_before_action:
skip_before_action :filter_thing, only: :action2, if: :should_not_filter?
but it seems to ignore the if: argument.
Is there a way to conditionally apply a filter to only some actions?
This is the workaround I came up with:
I'm still not wholly satisfied because the above is convoluted and tough to read.