Luccas
Luccas

Reputation: 4268

How say to a view to not import default application layout in Rails?

I want to all my views from different paths to use the 'layouts/application.html.erb', except a view that has a specific structure. Is that possible without forcing to create a layout for this view and each one for others?

The 'index.html.erb' couldn`t use the layout 'application.html.erb' in my case.

enter image description here

Upvotes: 2

Views: 162

Answers (2)

Harish Shetty
Harish Shetty

Reputation: 64363

You can override the default layout by passing an explicit layout name in the render call.

class FoosController < ApplicationController
  def index
    # call below uses layouts\new_layout.html.erb as the layout
    render :layout => 'new_layout'
    # if you want to render without a layout
    # render :layout => false
  end
end

Upvotes: 3

Max
Max

Reputation: 15955

This is easy. If you want to use a different layout for the entire controller, just put the following at the top of that controller:

class ItemsController < ApplicationController
  layout "inventory"
  #...
end

Upvotes: 0

Related Questions