Dave Elkins

Search It!

Making Erubis 2.6.4 and Rails 2.3 work together

June 18th, 2009 · No Comments

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

I decided about a week ago that I wanted to try Erubis with a Rails project to see if I got any performance boost.  So after reading the documentation, it appeared to be straightforward to install.  So I did.

But I discovered that the latest Erubis (2.6.4) and Rails 2.3 are not compatible.  After doing some googling and looking at stackoverflow solutions, the problem was still not resolved.  So I started to dig into  the problem.

I found that the main issue is that the generated ruby code from Erubis uses “_buf” as the buffer variable and Rails 2.2 and 2.3 require “@output_buffer” to be used.

The reason for “@output_buffer” to be used is that ActionView helpers like CaptureHelper are designed around “@output_buffer” being the primary buffer in the generated code.

I have created a gem called elkinsware-erubis_rails_helper that fixes these issues and allows Erubis and Rails 2.3 (for sure but it should work for 2.2).

Here is how to use it:

inside config/environment.rb and the following


config.gem 'erubis' , :version => '2.6.4'
config.gem 'elkinsware-erubis_rails_helper', :lib => 'erubis_rails_helper', :source => 'http://gems.github.com'

You can customize some of the options for Erubis still if you want to by adding config/initializers/erubis_config.rb to your initializers folder


#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
#Erubis::Helpers::RailsHelper.init_properties = {}
#Erubis::Helpers::RailsHelper.show_src = false
#Erubis::Helpers::RailsHelper.preprocessing = true

The source is at http://github.com/elkinsware/erubis_rails_helper/tree/master

Let me know if you have any issues with the gem.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Wists
  • BlinkList
  • blogmarks
  • Ma.gnolia
  • NewsVine
  • Slashdot
  • StumbleUpon
  • Technorati
  • Facebook
  • TwitThis

Tags: Rails Plugins · code · rails

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment