Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content_for does not work when rendering erb from helper #2097

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

content_for does not work when rendering erb from helper #2097

iamveen opened this issue Jul 15, 2011 · 4 comments

Comments

@iamveen
Copy link

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

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
Copy link
Author

iamveen commented Jul 18, 2011

Ya... that is much easier, thanks!

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

@isaacsanders
Copy link
Contributor

@iamveen Is this still an issue?

@steveklabnik
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants