6

I have a couple of block helpers, here's a simple example of what I'm doing:

def wrap_foo foo, &block
    data = capture(&block)

    content = "
      <div class=\"foo\" id=\"#{foo}\">
        #{data}
      </div>"
    concat( content )
end

I'm just trying out erubis and it's giving me the following error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<

Removing the call to concat removes the error but ends up with my wrapper not being rendered

Using:

  • Rails 2.3.5
  • Erubis 2.6.5
  • And tried this gem that helps Erubis (though 2.6.4) and Rails 2.3 play better together
niton
  • 8,771
  • 21
  • 32
  • 52
DEfusion
  • 5,533
  • 5
  • 44
  • 60

4 Answers4

2

Actually using the rails_xss plugin, which was my ultimate goal contains a fix for this.

I just had to change my helper to do this concat( content.html_safe! )

DEfusion
  • 5,533
  • 5
  • 44
  • 60
2

since Erubis 2.7.0 you can exploit the :bufvar option in this way:

Erubis::Helpers::RailsHelper.init_properties = {:bufvar => '@output_buffer'}
pic
  • 433
  • 6
  • 8
  • 1
    This fixed a problem I was seeing under rails 2.3.14 where I saw the error `undefined method `safe_concat' for nil:NilClass` when calling form_for – robd Jul 07 '12 at 23:04
1

Erubis and Rails 2.3 don't work together well. Check out this post: http://daveelkins.com/2009/06/18/making-erubis-264-and-rails-23-work-together/ He has created a gem on github that gets them to work together.

Mike Dotterer
  • 1,198
  • 1
  • 11
  • 19
0

Adding

Erubis::Helpers::RailsHelper.init_properties = {:bufvar => '@output_buffer'}

to config/initializers/erubis.rb fixed it for me

Dandan
  • 650
  • 1
  • 10
  • 17