0

I have a custom module in my lib directory that I load in my Application controller. I started using cancan and now I am getting Access Denied error for all the actions in my custom module. I don't want cancan to check authorization on my custom module. One way to get around this is to use except => [:action_name_in_my_custom_module] but I have lot of actions that I use in my application at many places. I need a better solution.

user1570144
  • 479
  • 3
  • 17

1 Answers1

0

Assuming you have a module of controller actions and you are including it in your controllers, is there a reason you didn't put them all in ApplicationController?

One thing you can try is using skip_before_filter in the module. This will call the method on any class in which you include MyModule:

module MyModule
  def self.included(klass)
    klass.class_eval <<-filters
      skip_before_filter :filter_method_to_skip, only: [:method_a, :method_b, ...]
    filters
  end
end


class MyController < ApplicationController
  before_filter :filter_method
  include MyModule
end

I believe it needs to be included after your before filters are defined.

Zach Kemp
  • 11,736
  • 1
  • 32
  • 46