Reputation: 6695
Let's say I only want to display a specific layout when I'm on the home page.
The home page's controller and action is home#index
.
How do I display a different layout for business#new
?
Upvotes: 0
Views: 59
Reputation: 53038
There are couple of options:
Just create a layout file named business.html.erb
in app/views/layouts
and it will be automatically picked for rendering ALL the views of BusinessController
Create a layout file named my_custom_name.html.erb
in app/views/layouts
and in your controller specify it as:
class BusinessController < ApplicationController
layout "my_custom_name"
#...
end
my_custom_name
layout would be used for ALL the views corresponding to BusinessController
.
Create a layout file named layout_name.html.erb
in app/views/layouts
and in your controller specify it as:
class BusinessController < ApplicationController
def new
# ...
render :layout => "layout_name"
end
end
In this case, layout_name
layout would only be applied for rendering new.html.erb
page.
Upvotes: 1
Reputation: 21
you can specify the layout of a controller with
class businessController < ApplicationController
layout "business_layout"
#...
end
http://guides.rubyonrails.org/layouts_and_rendering.html 2.2.14 Finding Layouts
Upvotes: 0