views:

793

answers:

3

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?
+1  A: 
  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
Thanks, but there's still that pesky nil object error to get rid of. :/
The Wicked Flea
Impossible to tell what's causing this without seeing a full stack trace, and any relevant custom code the stack trace points to.
August Lilleaas
+1  A: 

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
Indeed it is broken, but I've since gone to HAML without looking back. But thanks for the answer, someone else may find it helpful. :)
The Wicked Flea
Since then Erubis 2.6.4 has come out, with support for Rails 2.2 and 2.3.
Will Sargent
+1  A: 

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