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.

Layouts with absolute path not found

#2134

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.

Reported by Steve Quinlan · March 5th, 2009 @ 12:37 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. Steve Quinlan
    Steve Quinlan

    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
    
    

    March 5th, 2009 @ 01:40 PM

  2. thedarkone
    thedarkone
    • 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.

    March 5th, 2009 @ 04:36 PM

  3. thedarkone
  4. Repository
    Repository
    • State changed from new to resolved

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

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

    March 6th, 2009 @ 12:49 AM