This project is archived and is in readonly mode.

#6587 new
Elben Shira

layouts inheritance in controllers

Reported by Elben Shira | March 15th, 2011 @ 08:14 PM

I have a snippet:

class ProjectsController < ApplicationController
  layout "stream", :only => [:stream]
end

When I render projects#stream, it correctly uses the :stream layout. But when I render projects#show, it uses neither the :application nor the :stream layouts. It uses nothing, rending only show.html.erb.

Comments and changes to this ticket

  • ifesdjeen

    ifesdjeen March 19th, 2011 @ 10:33 AM

    You can use conditions for layouts, just give layouts a name of method to calculate current layout

    class ProjectsController < ApplicationController

    layout :get_layout_name
    
    def get_layout_name
       if action_name == "stream"
          "stream"
       else
          "application"
       end
    end
    

    end

    This way you will get your layouts working correctly

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>

People watching this ticket

Pages