4

I am working in rails project. I created a header and footer and added to all pages in layouts/application.html.erb file. Now I want to remove it from some pages. how can I do that?

Om3ga
  • 30,465
  • 43
  • 141
  • 221

4 Answers4

7

Controllers support :only and :except options for layouts, see the Conditional layouts section in this guide.

So you can do the following in your controller:

class SomeController < ApplicationController
  layout 'application', :except => [:some_action, :some_other_action]
  ...
HargrimmTheBleak
  • 2,147
  • 1
  • 19
  • 19
4

Create a different layout, and apply that in the pages where you don't want to render the header and the footer.

Matzi
  • 13,770
  • 4
  • 33
  • 50
1
class SomeController < ApplicationController
  def method_without_layout
    render layout: false
  end
end
jrich
  • 75
  • 6
0

You can go to application.html.erb, and do the following:

<% unless action_name == "show" %>
   <%= render 'shared/header' %>
<% end %>

<%= yield %>

<% unless action_name == "show" %>
   <%= render 'shared/footer' %>
<% end %>

'show.html.erb' will be the page that will not have the header and the footer. Be careful as you implement this solution coz any page that you name 'show.html.erb' will not have the header and the footer.

Elly Ambet
  • 478
  • 4
  • 13