This project is archived and is in readonly mode.

#5371 open
PreciousBodilyFluids

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

Reported by PreciousBodilyFluids | August 13th, 2010 @ 01:59 AM | in 3.1

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.

Comments and changes to this ticket

  • PreciousBodilyFluids

    PreciousBodilyFluids August 24th, 2010 @ 04:38 AM

    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.

  • Roberto Thais

    Roberto Thais August 24th, 2010 @ 05:59 AM

    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.

  • PreciousBodilyFluids

    PreciousBodilyFluids August 24th, 2010 @ 06:45 AM

    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).

  • Cyrille

    Cyrille August 24th, 2010 @ 08:23 AM

    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

  • Cyrille

    Cyrille August 24th, 2010 @ 08:26 AM

    See also #3619 that seems to be related

  • Neeraj Singh

    Neeraj Singh August 24th, 2010 @ 11:55 AM

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

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:33 PM

    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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:33 PM

    • State changed from “open” to “stale”
  • PreciousBodilyFluids

    PreciousBodilyFluids February 2nd, 2011 @ 05:26 PM

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

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>

Tags

Pages