This project is archived and is in readonly mode.

#2134 ✓resolved
Steve Quinlan

Layouts with absolute path not found

Reported by Steve Quinlan | March 5th, 2009 @ 12:37 PM | in 2.x

Just upgraded to 2.3.1 RC2.

When I render a file with a layout that has an absolute path, rails can't find the layout file.

The following line appears to work in 2.2.2 but fails in 2.3.1


render :file=>"app/views/posts/index.html.erb", :layout=>"#{RAILS_ROOT}/app/views/layouts/posts.html.erb"

To replicate it quickly, make a new rails app, scaffold a 'post' object and put the above line in the index action of the posts controller.


def index
  @posts = Post.find(:all)
  render :file=>"app/views/posts/index.html.erb", :layout=>"#{RAILS_ROOT}/app/views/layouts/posts.html.erb"
end

Now try it on 2.2.2. It should work.

I think the problem is somewhere around layout.rb, having discovered where exactly yet, and haven't replicated a failing unit test.

Comments and changes to this ticket

  • Steve Quinlan

    Steve Quinlan March 5th, 2009 @ 01:40 PM

    Attempted to get a failing test for this but got into a horrible muddle over view paths. Here's my attempt, perhaps someone else can build on it:

    
    #here's my attempt at the fixture
    class AbsolutePathLayoutController < LayoutTest
      def hello
        template_path = File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/hello.rhtml'
        layout_path = File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/layouts/alt.rhtml'
        render :file => template_path, :layout => layout_path
      end
    end
    
    #and here's my attempt at the test
    def test_should_work_with_absolute_path
      @controller = AbsolutePathLayoutController.new
      get :hello
      assert_response 200
    end
    
    
  • thedarkone

    thedarkone March 5th, 2009 @ 04:36 PM

    • Assigned user set to “josh”

    Templates outside view_paths are a hack, layouts are kinda hackish, so here we are.. having fun with this mess again :).

    0001-clean-Fix-layouts-with-absolute-paths.patch hopefully a clean fix, we just keep the pick_layouted layout template around without going through view_paths twice (should also give tiny speed up). This might break some obscure behavior, I have no idea...

    0001-hackish-Fix-layouts-with-absolute-paths.patch keeps a status quo and just hacks around the issue of non-view_paths templates.

  • thedarkone
  • Repository

    Repository March 6th, 2009 @ 12:49 AM

    • State changed from “new” to “resolved”

    (from [3191535ff0912e751dcf411c57923ec79b72944d]) Fix layouts with absolute paths [#2134 state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages