0

Consider the following block of ruby on rails code:

      <% unless current_user %>
        <%= card title: 'Things you can do', bodyless: true do %>
          <ul class="list-group list-group-flush">
            <li class="list-group-item" style="background: transparent"><a href="/todo"><i class="fa fa-key"></i> MEET OTHERS LIKE YOU</a></li>
            <li class="list-group-item" style="background: transparent"><a href="/todo"><i class="fa fa-question-circle-o"></i> ASK A QUESTION</a></li>
            <li class="list-group-item" style="background: transparent"><a href="/todo"><i class="fa fa-users"></i> SHARE YOUR JOURNEY</a></li>
          </u>
        <% end %>
      <% end %>

The "card" is shown, but only to logged in users. Can Pundit Authorization policies be used determine which divs/partials/cards are shown to the visitor on a website?

american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80

1 Answers1

0

Yes you can, if you defined a policy and then want to show some div/partial just if that policy, then you can do it like this for example

<% if policy(@post).update? %>
  <%= link_to "Edit post", edit_post_path(@post) %>
<% end %>
xploshioOn
  • 4,035
  • 2
  • 28
  • 37