1

I'm creating a gem to create an around_filter on my ApplicationController in all projects that the gem is in. This is my first gem and I'm having a few concerns.

I included rails as a dependency in the gemspec file, but how would I reference anything in rails?

Would I do something like require 'rails' at the top of my file, then do something like Rails::Path::To::ApplicationController? I understand I could do something like:

Module MyGem

  def self.included(klass)
      klass.class_eval do
        around_filter do |controller, action|
          #insert code here
        end
      end
  end
end

Then, in my Rails app I would include it in my Rails ApplicationController, but I don't want to have to include it. Of course, I might have to do some additional config for even that to work, but that is the gist of my crux. How would I reference ApplicationController in my gem? Do I just assume I have Rails since it is a dependency now and I should be able to freely call upon it in my ruby files?

David
  • 7,028
  • 10
  • 48
  • 95
  • not sure if your Q is a dupe, but this one helped me: http://stackoverflow.com/a/9641149/252799 - just replace the `helper` with your `around_filter` – oma Aug 16 '14 at 18:44

0 Answers0