Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails skip all before filter

can anyone tell me how to skip all before filters in rails 3.

In rails 2.x we could do

skip_filter filter_chain

however filter_chain is no longer supported in rails 3.

Thanks

like image 655
Hamish Avatar asked May 19 '11 08:05

Hamish


1 Answers

For Rails 5, I've used

class SomeController < ApplicationController    

  skip_before_action *_process_action_callbacks.map{|callback| callback.filter if callback.kind == :before}.compact

You must check the callback.kind, otherwise _process_action_callbacks will return all callbacks, including after and around, which will raise an exception with skip_before_action method.

The .compact at the end removes nils from the resulting array.

like image 78
sandre89 Avatar answered Nov 15 '22 19:11

sandre89