Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different layout for just one certain page in Rails

I want to have a different layout for just one certain action in my Rails app. How do I do that?

like image 794
Jason Swett Avatar asked Feb 26 '11 15:02

Jason Swett


People also ask

How do you render a partial?

You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .

How do you use nested layouts Rails?

Nesting layouts is actually quite easy. It uses the content_for method to declare content for a particular named block, and then render the layout that you wish to use. So, that's the normal application layout.

How can you tell Rails to render without a layout?

By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.


2 Answers

# controller that calls the page
def action
  render :layout => 'other'
end
like image 59
ecoologic Avatar answered Oct 18 '22 16:10

ecoologic


 layout :resolve_layout

  .
  .
  .
     private   
      def resolve_layout
       case action_name
         when "new"
          "alternate"
         else 
          "application"
         end
      end
like image 32
chief Avatar answered Oct 18 '22 16:10

chief