views:

304

answers:

1

I'm use Rails 2.2.2. Rails manual said, the way to extend controller from plug-in is:

Plugin:

module Plug

def self.included(base)
  base.extend ClassMethods
  base.send :include, InstanceMethods
  base.helper JumpLinksHelper
end

 module InstanceMethods
   def new_controller_metod
     ...
   end
 end
 module ClassMethods
 end
end

app/controller/name_controller.rb

class NameController < ApplicationController
  include Plug
  ...

end

Question: is any way to extend controller from plug-in, without any modification of controller file, if we know controller name.

+1  A: 

Sure, if you know the name of your controller, do

NameController.send(:include, Plug)
neutrino
Rails initialize plug-ins in first, then controller. So I can run this code only in the end of environment.rb. But same construction: class_eval(%{class NameControler\n include Plung\n end;}) in the end of environment.rb (unexpectedly for me) give no result.
potapuff
@neutrino your solve almost perfect, but I can't understand? where i shell run this peace of code? if i shell run it in environment.rb it well be used **only** for first controller execution.
potapuff
can't think of anything particular right now. btw, for production this should be enough.
neutrino