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?

On 15 May 2008, at 08:45, goodwill wrote:

module 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.

On May 15, 5:09 pm, Frederick C. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs