I have a _header.html.erb partial which is where I put my navbar
on my launch page I don't want to display the navbar.
this is the body
of application.html.erb
<body>
<%= render 'layouts/header' %>
<div id="container">
<%= yield %>
</div>
</body>
How do I render it on every action except specific actions on specific controllers?
You can put that logic in your stylesheets, in your controller or in your views (this last one, only for whole controllers).
Stylesheets
If you want to add the logic in your stylesheets, first add to your body tag the following classes:
Then, in your css, add something like this:
Controller
To add this logic to your controller, add a before filter to your application controller:
Then, if you don't want to show the navbar in CarsController, do this:
where
[list, of, actions]
are the actions you don't want to show the navbar in.Finally, change you layout to look like this:
Views
If you want to disable the header for whole controllers, first, move the header to
app/views/application/
and change your render to:Finally, in those controllers without navbar, add an empty
_header.html.erb
toapp/views/controller_name
.For this option to work, you need at least Rails 3.1
I would set a different layout for those specific actions on specific controllers.
Replace your render with this:
Then you can simply set
disable_nav
to true in any controller action you like:As a
before_filter
, which I'd encourage over the above:application_controller.rb
my_controller