简体   繁体   English

Ruby on Rails:“不在所有这些页面上显示”条件

[英]Ruby on Rails: 'don't show on all these pages' condition

I am new to Ruby on Rails and am having a difficult time figuring out how to not show a div on more than one page. 我是Ruby on Rails的新手,并且很难弄清楚如何在多个页面上不显示div。 Currently, I've only been able to make the following work for a single page: 目前,我只能在单个页面上完成以下工作:

<% if signed_in? %>
  <% unless current_page?(account_setup_path) %>
   <!--job seeker options-->
        <% if current_user.job_seeker? %>

        test

        <% end %>
      <!--end job seeker options-->

      <!--employer options-->
        <% if current_user.employer? %>

        <% end %>
      <!--end employer options-->
  <% end %>
<% end %>

Any help will be much appreciated! 任何帮助都感激不尽! Thanks in advance! 提前致谢!

Since you want a div to not be shown on multiple pages you have several options. 由于您希望一个div不在多个页面上显示,因此有几种选择。 First, if the div is only meant to be shown on pages with a certain controller you'll want to move that div into a partial and reference it from all the associated views. 首先,如果仅要将div显示在具有特定控制器的页面上,则需要将该div移到部分视图中并从所有关联的视图中引用它。 If you want in only shown on one page you should put it in the view directly. 如果只想显示在一页上,则应将其直接放在视图中。 If you need it shown on several different pages accross your app. 如果需要,可以在应用程序的多个不同页面上显示它。 you can simply check if the controller in your params hash matches. 您只需检查params哈希中的控制器是否匹配即可。 For example: 例如:

#I want this div shown on any pages handled by my `Admins` and `Users` controllers.

<% if params[:controller] == 'admins' || params[:controller] == 'users' %>
    div here
<% end %>

This will add overhead to maintenance so you should think hard whether this div should be in a partial, in a specific view, or in the layout/application file etc. 这将增加维护的开销,因此您应该认真考虑此div应该位于部分视图,特定视图还是布局/应用程序文件等中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM