Reputation: 5409
I'm new to RoR and using layouts/partials/rendering, all that good stuff, to make an app. At the beginning of my app I thought I would use the same header for the entire app, and thus wrote:
render 'layouts/header'
in my application.html.erb
file. Now, I realized that for certain pages (i.e. sign up page and blog) I want to use a simplified header called simple_header
. Do I write something like
<%= if @simple_header
render 'layouts/simple_header'
else
render 'layouts/header'
%>
and then test if @simple_header
is true or something in a controller, or is there a better way to do this. Thanks.
Upvotes: 1
Views: 1376
Reputation: 2493
Also (if you have simple logic) consider using
current_page?
method like this:
<% if current_page?(controller: 'sites', action: 'index') %>
...
<% else %>
...
<% end%>
Upvotes: 1
Reputation: 2520
In rails, you can create different layouts and choose which one to use for a particular action or a controller.
Watch this railscast http://railscasts.com/episodes/7-all-about-layouts
That should help you solve your problem.
For example.,
Create a new layout in app/views/layouts
, say, simple_header.html.erb
and in your controller, tell it to use that layout.
class BlogController < ApplicationController
layout :simple_header
def index
end
end
Upvotes: 3