开发者

How to hide footer layout on a particular page?

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?


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


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜