Class: UserPolicy

Inherits:
ApplicationPolicy show all
Defined in:
lib/generators/rockstart/pundit/templates/app/policies/user_policy.rb

Overview

Policy for updating profiles, provided by rockstart

Defined Under Namespace

Classes: Scope

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#record, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#create?, #edit?, #index?, #initialize, #new?, #permitted_attributes_for_create, #permitted_attributes_for_update, #show?

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#destroy?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/generators/rockstart/pundit/templates/app/policies/user_policy.rb', line 21

def destroy?
  # Prevent admins from destroying themselves
  current_user? && !record.admin?
end

#permitted_attributesObject



26
27
28
29
30
31
32
33
# File 'lib/generators/rockstart/pundit/templates/app/policies/user_policy.rb', line 26

def permitted_attributes
  if current_user?
    # Allow a user to update their own details
    %i[name]
  else
    []
  end
end

#update?Boolean

def create?

false

end

Returns:

  • (Boolean)


17
18
19
# File 'lib/generators/rockstart/pundit/templates/app/policies/user_policy.rb', line 17

def update?
  current_user?
end