Extend ApplicationController via lib code

I have come across a problem when I am trying to extend ApplicationController with a .rb file containing a module inside /lib folder.

The problem is, let's say if I want to add a method called authenticate inside ApplicationController using ApplicationController.send(:include), I would do it as:

extension.rb module Extension   module ClassMethods   ...   end   def self.included(base)     base.extend(Extension.ClassMethods)   end end

ApplicationController.send(:include, Extension)

This would work only if I put the require statement at the end of application.rb, I want to know if there is any chance it would work too if I want to put the require statement at the top?

Have a think: if you do that you're trying to something to application controller even though it hasn't been defined yet.

Fred

Thats why its a difficult question :slight_smile: I managed to fix it by extend ActionController::Base instead, I have seen plugins doing that.