6

On my view page, I want to hide the footer partial that is defined in my application.html.erb, how can I do this?

what options do I have to do this?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

3 Answers3

20

The easiest/quickest way would probably be to define a conditional:

<%= render "layouts/footer" unless @skip_footer %>

and then set the variable as necessary in your actions:

def non_footer_action
  do_stuff
  @skip_footer = true
end
Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
1

For me, CSS solution is the closest to the conventional one:

app/controllers/resources_controller.rb

class ResourcesController < ApplicationController
  def action
    # ...
  end
end

app/views/layouts/application.html.erb

<body class="<%= "#{controller_path} #{action_name}" %>">
  <!-- ... -->
  <footer></footer>
</body>

app/assets/stylesheets/resources.css.scss

body.resources {

  // Hide footer for certain views

  &.action footer {
    display: none;
  }
}

You may also want to use separate layout for «footerless» actions, albeit one element is not good enough reason for another layout.

jibiel
  • 8,175
  • 7
  • 51
  • 74
0

If the page is 'show.html.erb' you can do the following:

<% unless action_name == "show" %>
   <%= render 'shared/footer' %>
<% end %>
Elly Ambet
  • 478
  • 4
  • 13