Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

render_to_string :template before normal render causes assert_template failures

#5891

When render_to_string :template => ... is called in a controller action and a normal template render later occurs

Tests that uses assert_template will fail claiming that the template is ''

See also ticket #1383 render_to_string :inline before normal render causes assert_template failures for an earlier similar problem.

Jarl

Reported by Jarl Friis · October 29th, 2010 @ 11:51 PM

State: open
Milestone: 2.x
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Jarl Friis
    Jarl Friis

    The same problem occurs when using render_to_string :file => ...

    October 30th, 2010 @ 12:00 AM

  2. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:02 PM

  3. Jarl Friis
    Jarl Friis
    • Tag set to 2.3.9, actionpack, activeview, render_to_string

    November 1st, 2010 @ 07:36 PM

  4. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 01:49 AM

  5. Jarl Friis
    Jarl Friis
    • Tag set to 2.3.9, actionpack, actionview, render_to_string

    Added tags again after spam.

    November 9th, 2010 @ 11:18 AM

  6. Neeraj Singh
    Neeraj Singh

    I am not able to reproduce it. Look at the attached test case.

    Even if this ticket is rendered as invalid the attached patch could be merged because it is strengthening the existing test case. I checked and did not find any test covering the scenario mentioned in the patch.

    @Jal can you create a small app on github so that I could reproduce the error. Thanks.

    November 9th, 2010 @ 03:57 PM

  7. Neeraj Singh
    Neeraj Singh

    not open to open the attachment. not sure why. uploading again.

    November 9th, 2010 @ 03:58 PM

  8. Jarl Friis
    Jarl Friis

    Neeraj, done as you requested:
    https://github.com/jarl-dk/bug5891

    This is a simple project created with

    rails bug5891
    cd bug5891
    ./script/generate scaffold notes
    

    Now commit ffa0afcc94f5e9d357ee8d5c5ef94d9a0dd09d7a introduces a reasonable test that assert that the show action uses correct template. This test passes until commit a1ba70ae15a5e114419b2662ecb743f6b4d9a74d) that introduces a render_to_string in the controller that renders some other template (into a string).

    @Neeraj, could you please from that create a failing test in rails 2.3-stable. I think the reason that you test (in your patch) does not fail is because both

    render_to_string :template => "test/hello_world"
    

    and

    render :template => "test/hello_world"
    

    renders the same template, try to change render_to_string to render some other template

    November 10th, 2010 @ 01:04 PM

  9. Neeraj Singh
    Neeraj Singh

    @Jal thank you.

    Now I am able to reproduce it.

      def render_to_string_template_with_template_render
        #render_to_string :template => "test/hello_world"
        render_to_string :template => "shared"
        render :template => "test/hello_world"
      end
    

    I will look into it.

    November 10th, 2010 @ 02:25 PM

  10. Neeraj Singh
    Neeraj Singh
    • State changed from new to open
    • Tag changed from 2.3.9, actionpack, actionview, render_to_string to 2.3.9, actionpack, actionview, patched, render_to_string

    Attached is a patch with test cases. Big thanks to Jal for all the help.

    November 10th, 2010 @ 03:02 PM

  11. Neeraj Singh
  12. Neeraj Singh
    Neeraj Singh
    • Assigned user changed from josh to José Valim

    Assigning it to Mr. Valim as Josh was last seen in action at LH was in June.

    November 10th, 2010 @ 08:02 PM

  13. Jarl Friis
    Jarl Friis

    @Neeraj: As I mention in comment 2. The problem also occurs if I use render_to_string :file =>

    Could you make a test that covers that situation as well.

    November 11th, 2010 @ 09:17 AM

  14. Neeraj Singh
    Neeraj Singh

    Verified that this is not an issue with Rails 3.

    @Jarl I lost my setup for this ticket. Will add to patch once I hear from José Valim to see if I am heading in the right direction.

    Thanks.

    November 11th, 2010 @ 04:13 PM

  15. bingbing