2

Supposedly installing erubis is as simple as:

gem install erubis

# And in environment.rb:
require 'erubis/helpers/rails_helper'

But I haven't found this to be so. Note that there are no evident errors in my code; it runs just fine and dandy with ERB.

  1. Where do I put this line? Directly after the boot.rb inclusion it fails to start the server, and at the end of the file I get an unexpected nil object error (nil.controller). Where is best?
  2. Are there known conflicts with the given versions?
  3. Are there any workarounds I can utilize to get erubis functioning?
Robert K
  • 30,064
  • 12
  • 61
  • 79

3 Answers3

1

The latest Erubis (2.6.4) and Rails 2.2 (and 2.3) are still not compatible. 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).

In your environment.rb file add:

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

And then you can add a config/initializers/erubis_config.rb where you can adjust the Erubis/Rails options.

 #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.

dave elkins
  • 331
  • 2
  • 4
  • Any ideas on how to make it work with concat? I've tried your gem but that isn't helping, see question http://stackoverflow.com/questions/1850398/erubis-block-helper-throwing-error-with-concat – DEfusion Dec 05 '09 at 12:44
1
  1. Either put it on the bottom or environment.rb, or put it in an initializer (config/initializers/anything.rb). When you put it before the Rails::Initializer block, the rails environment hasn't fully loaded yet, and erubis/helpers/rails_helpers seems to assume a fully loaded Rails environment.
  2. I have never used erubis, so I can't answer that.
  3. Workarounds? See #1, I guess.
August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
1

Apparently this is broken:

http://kleinptr.wordpress.com/2009/02/04/erubis-and-rails-222/

and they're working on a fix:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/328613

Will Sargent
  • 4,346
  • 1
  • 31
  • 53