Skip to content

Instantly share code, notes, and snippets.

@taketo1113
Last active December 21, 2018 08:46
Show Gist options
  • Save taketo1113/2e1e43d191ae670e283921bb50340b78 to your computer and use it in GitHub Desktop.
Save taketo1113/2e1e43d191ae670e283921bb50340b78 to your computer and use it in GitHub Desktop.
Pundit Nested Headless policies

Pundit Nested Headless policies

# app/policies/hoge/dashboard_policy.rb
class Hoge::DashboardPolicy < Struct.new(:user, :dashboard)
  # ...
end
# In controllers
authorize [:hoge, :dashboard], :show?
# In views
<% if policy([:hoge, :dashboard]).show? %>
  <%= link_to 'Dashboard', dashboard_path %>
<% end %>

ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment