Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `layout nil` not working?

I just upgraded my Rails site from Rails 2 to Rails 3.2.

On my old controller I had:

class Foo::BarController < ApplicationController
   layout nil 
   ... 
end

However now that I upgraded to Rails 3 it seems I need to change that to:

layout false

The documentation on Rails Guides claims that layout nil should work fine:

Layout declarations cascade downward in the hierarchy ...

class OldPostsController < SpecialPostsController
layout nil

I have the following relevant gems in my Gemfile.lock

GEM

actionpack (3.2.6)
  activemodel (= 3.2.6)
  activesupport (= 3.2.6)
  builder (~> 3.0.0)
  erubis (~> 2.7.0)
builder (3.0.0)
erubis (2.7.0)
haml (3.1.6)

jquery-rails (2.0.2)
  railties (>= 3.2.0, < 5.0)

Is this a documented change somewhere, or is it a related gem monkey patching something?

like image 966
Sam Saffron Avatar asked Jul 06 '12 02:07

Sam Saffron


1 Answers

The API explains it like this:

If the specified layout is:

  • a string: the string is the template name
  • a symbol: call the method specified by the symbol, which will return the template name
  • false: there is no layout
  • true: raise an ArgumentError
  • nil: force default layout behavior with inheritance

So the meaning of nil changed from no layout to "force default layout behavior with inheritance". Seems the explanation in Rails Guides is incorrect.

like image 55
Mischa Avatar answered Oct 11 '22 18:10

Mischa