Reputation: 1065
I have a home page with its own style (put in application.css
) but the rest of the website will be totally different.
Yet, it seems that Rails work with a "parent" file application.html.erb
and we can basically use yield
to include other .html.erb
pages.
However, it's not viable for my application because as I said the home page will have a totally different structure from the rest of my web app and I can't use a common application.html.erb
file.
What are the solutions for this situation?
Upvotes: 0
Views: 768
Reputation: 3002
You can specify the layout controller wide or for a specific action.
The layout file needs to be in the layouts
folder.
To specify the layout file controller wide you can do this
class BlogController < ActionController::Base
layout "unique_blog_layout"
def index
end
...
end
To set it for a single view
class BlogController < ActionController::Base
def index
render layout: "unique_blog_layout"
end
...
end
For a full rundown checkout the docs here and maybe here too.
Upvotes: 2
Reputation: 5977
To use a different layout for just a single template, do this:
views/layouts/name_of_my_new_layout.html.erb
render :index, layout: :name_of_my_new_layout
in the controller to tell Rails to use your new layout to render the templateUpvotes: 2