2011-02-27 81 views

回答

18

最簡單的/最快的方式很可能是爲其定義條件:

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

,然後設置你的行爲需要變量:

def non_footer_action 
    do_stuff 
    @skip_footer = true 
end 
1

對於我來說,CSS解決方案是最接近到傳統的:

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; 
    } 
} 

您可能還需要使用不同的佈局«footerless»動作,儘管一個元素不夠好理由另一佈局。