content_for does not work when rendering erb from helper #2097

Closed
iamveen opened this Issue Jul 15, 2011 · 4 comments

Comments

Projects
None yet
4 participants
@iamveen

iamveen commented Jul 15, 2011

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.

application_helper.rb:

# 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)
end

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.

index.html.haml

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

application.html.haml

  = content_for? :right  # nil
  = yield :right # nothing
@anveo

This comment has been minimized.

Show comment Hide comment
@anveo

anveo Jul 16, 2011

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

def render_erb(text)
  ERB.new(text).result(binding)
end

anveo commented Jul 16, 2011

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

def render_erb(text)
  ERB.new(text).result(binding)
end
@iamveen

This comment has been minimized.

Show comment Hide comment
@iamveen

iamveen Jul 18, 2011

Ya... that is much easier, thanks!

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

iamveen commented Jul 18, 2011

Ya... that is much easier, thanks!

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

@isaacsanders

This comment has been minimized.

Show comment Hide comment
@isaacsanders

isaacsanders Apr 28, 2012

Contributor

@iamveen Is this still an issue?

Contributor

isaacsanders commented Apr 28, 2012

@iamveen Is this still an issue?

@steveklabnik

This comment has been minimized.

Show comment Hide comment
@steveklabnik

steveklabnik Apr 28, 2012

Member

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

Member

steveklabnik commented Apr 28, 2012

@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