Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


content_for does not work when rendering erb from helper #2097

iamveen opened this Issue · 4 comments

4 participants

Gavin Dunne Brian Racer Isaac Sanders Steve Klabnik
Gavin Dunne

Ok, so this problem popped up when I upgraded my app from 3.0.x to 3.1.0.rc4.

I have erb content stored in the database that needs to be rendered in the correct context to use view helpers. I use the following helper for that.


# There very well might be a better/more proper way to do this,
# but it was working in 3.0.x and I'm noobish so I used it.
def render_erb (text)
  controller.render_to_string(:inline => text)

Now any time I call render_erb within a view, content_for no longer works properly. Views with no call to render_erb work as they should.


  = render_erb(@model.erb_field)
  - content_for(:right) { 'right' }


  = content_for? :right  # nil
  = yield :right # nothing
Brian Racer

It might just be easier to use the ERB class directly:

def render_erb(text)
Gavin Dunne

Ya... that is much easier, thanks!

Is this still a bug, or should I close it?

Isaac Sanders

@iamveen Is this still an issue?

Steve Klabnik

@iamveen since you're not even sure this is a bug, I'm closing. ;) I don't think it's a bug. @anveo's solution is much better in basically every way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.