简体   繁体   中英

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. 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. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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