before_action for only one action

Hi there,

If I want a before_action for only one action, like

before_action check_something_with_redirect_if_any, only: :index

Is there another way doing that? Or is this the recommend way?

If not what else could work here?

Thanks,
Martin

You can put like this

before_action check_something_with_redirect_if_any, except: [all actions except index]

but its very verbose :smiley:

Hi there,

If I want a before_action for only one action, like

before_action check_something_with_redirect_if_any, only: :index

Is there another way doing that? Or is this the recommend way?

If you want it for only one action, Jay call it in the action.

Hi tamouse,

tamouse pontiki writes:

Is there another way doing that? Or is this the recommend way?

If you want it for only one action, Jay call it in the action.

I tried it, but I have a view, so interesting that it doesn't work,
because they have a redirect_to inside. If I put it in the action, i
get the "dont call more than one redirect_to or render" message, which I
could fix by using some if statements, but this looks ugly. I think the
before_action's will stop if the first gets a redirect_to, so the next
will not be run anymore, and this is what I want.

Martin