Forum: Ruby on Rails access a ActionControllers protected method from plugin?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-05-26 02:48
I can't belive I fit that in as the subject!

I'm writing a plugin that will allow me to grab some text from a
database and call the render method from ActionController on part of the
text.  I can't seem to figure out how to access the render method of
ActionController::Base.  I keep getting the "uninitialized constant
Execute" error.  How can I do this?  I'm I even barking up the right
tree?  Here's the relevent code

# ActsAsBlog - used to convert redcloth,markdown,smarty to html.  also
evals <ruby> code and escpates html if needed
require 'active_record'
require 'action_controller'

class Execute < ActionController::Base
  def self.execute_ruby_code( str )
    logger.error('test')
    str = str.gsub(/\<ruby\>(.*?)\<\/ruby\>/) do |match|
    match = self.render(:inline => $1, :type => 'rhtml')
    logger.error(match)
    end
    str
  end
end
module TextConversion
  module Acts
    module Blog
      def self.included(base)
        base.extend(ClassMethods)
      end
        def acts_as_blog
          class_eval do
            extend TextConversion::Acts::Blog::SingletonMethods
          end
        end
      end
      module SingletonMethods
        def convert_to_html(txt, text_filter, restrictions = [])
           txt = Execute.execute_ruby_code(txt)
          end
          return txt
        end
      end
   end
end
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-05-26 03:40
I've decided to go about it a different way.  I'm just trying to access
the method directly from the plugin without inheriting from
ActionController.  the ActionController::Base.render method fails now
because of this.

undefined method `render' for ActionController::Base:Class

The method is actually in ActionController but it is marked as
protected, therefore I recieve the above error.  How can I call this
method.  How can I alias it as public for this plugin?

def execute_ruby_code( str )
  logger.error('test')
  str = str.gsub(/\<ruby\>(.*?)\<\/ruby\>/) do |match|
  match = ActionController::Base.render(:inline => $1, :type => 'rhtml')
    logger.error(match)
  end
  str
end
This topic is locked and can not be replied to.