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.

layout with :only/:except options makes other actions render without layouts

#5371

In a controller, after declaring a layout for some particular actions, the remaining actions are processed without any layouts at all.

I wasn't sure how to reproduce this on a smaller scale, so I generated a new Rails app to demonstrate it:

http://github.com/chanks/layout_bug

So, if you do:

class PostsController < ApplicationController
  layout 'other_layout', :only => :new

Then the index, show and edit actions are all rendered without a layout. I've tried to force the correct behavior by doing:

class PostsController < ApplicationController
  layout 'other_layout', :only => :new
  layout 'application', :only => [:index, :show, :edit]

But this just makes the new action render without a layout.

I've reproduced it in the demo app with both RC1 and master.

Reported by PreciousBodilyFluids · August 13th, 2010 @ 01:59 AM

State: open
Milestone: 3.1
Assigned to: nobody
Importance: Low

Activity

  1. PreciousBodilyFluids
    PreciousBodilyFluids

    This bug is still present in RC2. Can anyone else reproduce this, to make sure it's not just me? This seems like a major problem with the layout system to me, and I'm not sure how it's gone unnoticed for so long.

    August 24th, 2010 @ 04:38 AM

  2. Roberto Thais
    Roberto Thais

    I'm not sure if this is a bug. Why don't you simply do

    render :layout => 'other_layout'
    

    inside your 'new' action? This will render the application layout for all the remaining ones.

    August 24th, 2010 @ 05:59 AM

  3. PreciousBodilyFluids
    PreciousBodilyFluids

    It's pretty unexpected, don't you agree? Why would naming a layout for some specific actions imply that you want the others to go layoutless? And, of course, it goes against the Rails convention (of using the application layout as the default).

    I actually have hacked around it by using render :layout in that one action, but with the release of Rails 3 I'm trying to standardize my apps on respond_with, and you can't use both an explicit render and respond_with in an action (double render error).

    August 24th, 2010 @ 06:45 AM

  4. Cyrille
    Cyrille
    render :layout => 'other_layout'
    

    is definitely working however I personally think layout is better in controller class declaration

    layout 'other_layout', :only => :new
    

    is not working for me as well

    August 24th, 2010 @ 08:23 AM

  5. Cyrille
  6. Neeraj Singh
    Neeraj Singh
    • Milestone set to 3.1
    • State changed from new to open
    • Tag set to rails 3
    • Importance changed from to Low

    It is not being ignored. Any fix is going to have some performance penalty unless the whole conditions track is compiled into a single method call the way it is done for before_filter callbacks.

    August 24th, 2010 @ 11:55 AM

  7. Santiago Pastorino
    Santiago Pastorino

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:33 PM

  8. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:33 PM

  9. PreciousBodilyFluids
    PreciousBodilyFluids
    • State changed from stale to open

    [state:open]

    I've reproduced this on the current 3-0-stable branch (and updated my reproduction: http://github.com/chanks/layout_bug). I tried it on master, but the app wouldn't even boot up, which is probably an unrelated issue with master.

    February 2nd, 2011 @ 05:26 PM