在我的应用程序视图中,我有
<div class="push-in">
<div class="container">
<div id="flash_messages">
<%= flash_messages %>
</div>
<%= yield %>
</div>
</div>
但是我想这样做,如果一个特定的页面被调用,那么它将删除容器div。什么是最好的语法使用。我有大约12个页面,我只需要在整个应用程序中删除容器div。
我目前有这个......
<% if current_page?(welcome_index_path) || current_page?(tenants_path)|| current_page?(root_url) || current_page?(welcome_testimonial1_path) || current_page?(welcome_testimonial2_path) || current_page?(welcome_testimonial3_path) || current_page?(welcome_testimonial4_path) || current_page?(welcome_testimonial5_path) || current_page?(welcome_testimonial6_path) || current_page?(welcome_man_testimonial1_path) || current_page?(welcome_man_testimonial2_path) || current_page?(welcome_man_testimonial3_path) || current_page?(welcome_man_testimonial4_path) || current_page?(welcome_man_testimonial5_path) || current_page?(welcome_man_testimonial6_path)%>
<div class="push-in">
<div class="container">
<div id="flash_messages">
<%= flash_messages %>
</div>
</div>
<%= yield %>
</div>
<% else %>
<div class="push-in">
<div class="container">
<div id="flash_messages">
<%= flash_messages %>
</div>
<%= yield %>
</div>
</div>
<% end %>
但这对我来说似乎完全不好看,在页面渲染时检查每一页。我该如何清理它?
答案 0 :(得分:0)
在helper中创建一个像这样的方法
def check_page(page_url)
case page_url
when welcome_index_path || tenants_path
true
else
false
end
end
您正在隐藏并只显示一个div
<div class="push-in">
<div class="container">
<div id="flash_messages">
<%= flash_messages %>
</div>
</div>
<%= yield %>
</div>
<% unless check_page(current_url) %>
</div>
<% end %>
注意动态生成当前页面URL并在帮助程序方法中定义这些URL并匹配此方法
如果您正在使用任何cms类型的东西,那么最好添加一个标志来检查它。