Extending ActionController

Reading time: ~1 min ❓Shorter than a Rails console boot time

In my pursuit yesterday to make add the desired functionality to ActionController (render string to string), I talked to bitsweat about this and he suggested that I just extend the class in my rails app.

So, I created a file in lib, called action_controller_ext.rb (a shim as he referred to it) and put this in the file:

require 'action_controller'

class ActionController::Base

  def render_string_to_string(text = nil, type = "rhtml") #:doc:
    add_variables_to_assigns
    @template.render_template(type, text) 
  end
  
end

Then in environment.rb, I changed:

require 'action_controller'

to

require 'action_controller_ext'

Now, I can move my clients app around dev/test/live servers and not need to modify the actual Rails source code. (still would be nice if it did that though)

Hi, I'm Robby.

Robby Russell

I run Planet Argon, where we help organizations keep their Ruby on Rails apps maintainable—so they don't have to start over. I created Oh My Zsh to make developers more efficient and host both the On Rails and Maintainable.fm podcasts to explore what it takes to build software that lasts.