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

:layout => !request.xhr? doesn’t fallback to the custom layout option #563

Closed
EtienneLem opened this issue Aug 20, 2012 · 10 comments
Closed
Labels
Milestone

Comments

@EtienneLem
Copy link

module MyApp
  class App < Sinatra::Base
    set :erb, :layout => :'layouts/application'

    get '/does-not-work' do
      erb :view, :layout => !request.xhr?
      #=> No such file or directory - myapp/views/layout.erb
    end

    get '/does-work' do
      erb :view
      #=> Render with myapp/views/layouts/application.erb layout
    end

    get '/does-work-too' do
      if request.xhr?
        erb :view, :layout => false
      else
        erb :view
      end
    end

  end
end

Or maybe I’m missing something and it’s meant to be that way?

@EtienneLem
Copy link
Author

FWIW; erb :view, :layout => true also tries to use the myapp/views/layout.erb layout instead of the one set in the options

@zzak
Copy link
Member

zzak commented Aug 20, 2012

You could try something like: erb :view, :layout => :'layouts/application' unless request.xhr?.

Even set the :'layouts/application' to a constant or something.

@EtienneLem
Copy link
Author

Yeah, workarounds are pretty easy.
But it just seems wrong that :layout => true ignores the layout option

@rkh
Copy link
Member

rkh commented Aug 20, 2012

Agreed. Let's change this for 1.4.

@zzak
Copy link
Member

zzak commented Aug 20, 2012

I believe this patch covers the test case:

diff --git a/test/templates_test.rb b/test/templates_test.rb
index e426d32..91f8572 100644
--- a/test/templates_test.rb
+++ b/test/templates_test.rb
@@ -34,6 +34,14 @@ class TemplatesTest < Test::Unit::TestCase
     File.unlink(layout) rescue nil
   end

+  it 'falls back to default layout' do
+    with_default_layout do
+      render_app(:layout => :layout2) { render(:test, :hello, :layout => true) }
+      assert ok?
+      assert_equal "Layout 2!\nHello World!\n", body
+    end
+  end
+
   it 'renders String templates directly' do
     render_app { render(:test, 'Hello World') }
     assert ok?

@rkh
Copy link
Member

rkh commented Aug 20, 2012

Yes, thanks!

@zzak
Copy link
Member

zzak commented Sep 13, 2012

See #574

rkh added a commit that referenced this issue Sep 13, 2012
Templates: render should fall back to engine layout #563
@zzak
Copy link
Member

zzak commented Sep 15, 2012

@EtienneLem Could you test this again against master? Should be fixed by d8f1d8e

@EtienneLem
Copy link
Author

Oh! It does. Thanks & good job 😉

@zzak
Copy link
Member

zzak commented Sep 15, 2012

@EtienneLem Mind closing this then?

Thanks!

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

No branches or pull requests

3 participants