potapuff
potapuff

Reputation: 1980

Rails. How to extend controller class from plugin without any modification in controller file?

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.

Upvotes: 1

Views: 1835

Answers (1)

alex.zherdev
alex.zherdev

Reputation: 24164

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

NameController.send(:include, Plug)

Upvotes: 2

Related Questions