L
L
lolipo2017-12-15 18:35:43
Ruby on Rails
lolipo, 2017-12-15 18:35:43

How to share access to rails_admin records?

There is a model with tasks. Please tell me how to allow editing only your own tasks, and prohibit others. There are also two models: admin and user.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kozlov, 2017-12-15
@lolipo

I used the pundit gem for a similar task .
And here is such a Policy Object:

class CommentPolicy
  attr_reader :user, :comment

  def initialize(user, comment)
    @user = user
    @comment = comment
  end

  def update?
    owner?
  end

  def destroy?
    owner?
  end

  private

  def owner?
    comment.user == user
  end
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question