ruby on rails - Pundit Gem Index Page Prevent Access -


i'm using pundit gem , trying figure out how use prevent access index page belongs user other current_user.

the examples talk how scope results current_user no how prevent access page if current_user not owner of record.

any appreciated

thanks

maybe want this? (for class modelname)

# /policies/model_name_policy.rb  class modelnamepolicy   attr_reader :current_user, :resource    def initialize(current_user, resource)     @current_user = current_user     @resource = resource   end    def index?     current_user.authorized_to_edit?(resource)   end  end  # /models/user.rb  class user < activerecord::base    def authorized_to_edit?(resource)     admin? | (id == resource.created_by) # or whatever method want call on model determine ownership   end  end 

edit: note need call authorize controller invoke policy.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -