#974 ✓resolved
Arnaud D.

Partial tag not html_safe with rails 3.0.10

Reported by Arnaud D. | October 28th, 2011 @ 07:46 AM

Hi,

After gems update of one of my projects, I encounter issue that tag partial becomes html_unsafe.
I was using hobo 1.3.0.RC3 and rails 3.0.10.

As a solution, I redefined the tag partial like this :
<%=
locals ||= {}
render(:partial => name, :locals => locals.merge(:this => this)).html_safe
%>

Where I just added ".html_safe at the end of the render.

Regards,
Arnaud.

Comments and changes to this ticket

  • Matt Jones

    Matt Jones November 9th, 2011 @ 12:55 AM

    More specifically, it appears to only affect DRYML partials - I couldn't reproduce this behavior with an ERB partial at all.

    This is definitely an issue, but on the other hand rendering DRYML partials (from DRYML) isn't a preferred idiom...

  • Bryan Larsen

    Bryan Larsen May 25th, 2012 @ 03:22 PM

    • State changed from “new” to “resolved”

    fix pulled from Arnaud's tree

  • Bryan Larsen

    Bryan Larsen September 12th, 2012 @ 05:17 PM

    Krister, can you send me a failing example and/or put one up on Github?

  • Bryan Larsen

    Bryan Larsen September 13th, 2012 @ 02:08 PM

    Yes, I did, thank you. I'll take a look later today.

  • Bryan Larsen

    Bryan Larsen September 17th, 2012 @ 04:35 PM

    Yes, I took a look and figured out what the basic problem was. It's more surprising that 1.3/3.0 works than that 1.4/3.2 doesn't. So I need to take a look at how Rails 3.2 does it differently than 3.0 to get inspiration on how to fix it.

  • Bryan Larsen

    Bryan Larsen September 21st, 2012 @ 09:16 PM

    OK, I think I've got a workaround for you that restores the behaviour from 1.3. Unfortunately, the 1.3 behaviour is suboptimal: it recompiles the partial template every time rather than just the first time. Is this good enough for you?

  • Bryan Larsen

    Bryan Larsen September 27th, 2012 @ 02:38 PM

    I've attached a patch file that you can apply to your example via git am to get it working. It's a monkey patch for Rails. I'm not sure yet if I want to put it into Hobo proper. It's pretty ugly, and as mentioned, inefficient. But it restores your previous behaviour, except you call 'sub_render' instead of 'render'.

  • Bryan Larsen

    Bryan Larsen September 27th, 2012 @ 04:37 PM

    Yes, it was just a quick hack. if you look at config/initializers/sub_render.rb, you'll see that ActionView::Template#sub_render supports locals but that ActionView::Helpers::RenderingHelper#sub_render doesn't. To fix it, try adding locals to ActionView::Template#sub_render and changing its last line to template.sub_render(self, options, locals). That should be enough. If it isn't, one of the other three lines needs it too. Most likely :setup.

  • Bryan Larsen

    Bryan Larsen September 28th, 2012 @ 12:47 PM

    Now we just have to figure out what your longer-term solution will be
    as well as Hobo's. We do want to support some variant of what you're
    doing, but this solution is decidedly sub-optimal.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Attachments

Pages