Forum: Ruby on Rails aliasing, require_dependency and require

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
982c3f128bb78678033c0bf8c0e226bc?d=identicon&s=25 Saimon Moore (saimon)
on 2007-03-13 18:38
I'd really appreciate it if someone [with a decent understanding of the
rails Dependencies mechanism] could help me explain the behaviour seen
in this pastie.

The desired behaviour is simply aliasing a method in
ApplicationController from a plugin while retaining automatic reloading
in dev mode.

The pastie is basically divided into 4 parts:

- Setup of rails app and initial version of

- Setup of plugin which will alias the method in application.rb and
initial attempt without loading 'application'

The interesting parts (for me) are the last two frames:

Firstly, I use require_dependency to load ApplicationController but as
you can see the aliasing doesn't work (funnily enough the xxx_with/out
methods are defined).

Secondly, I use 'require' to load ApplicationController and here
aliasing works as it should but I'm losing reloading of application.rb.

The same behaviour is observed if I use the following module included

#speaker plugin init.rb

#require 'application'
require_dependency 'application'

module Speaker
  def self.included(base)
    base.alias_method_chain :say_hello, :speaker


    def say_hello_with_speaker
      puts "Hello speaker...."

ApplicationController.send(:include, Speaker)

Any help heres is much appreciated...


This topic is locked and can not be replied to.