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:

On Thu, Jan 28, 2016 at 12:43 AM, Martin [email protected] wrote:

Thanks,

https://groups.google.com/d/msgid/rubyonrails-talk/2d11149f-2cba-4809-b769-ee9604636c11%40googlegroups.com?utm_medium=email&utm_source=footer

.
For more options, visit https://groups.google.com/d/optout.


Karthikeyan A K
https://cloud.openmailbox.org/index.php/s/u4sX065QRgjbJL2/download- My
Ruby
Book
diaspora social network - Join me on Diaspora

On Jan 27, 2016 1:13 PM, “Martin” [email protected] wrote:

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.

If not what else could work here?

Thanks,
Martin


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/2d11149f-2cba-4809-b769-ee9604636c11%40googlegroups.com
.

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


Lösungen statt Diagnosen