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
Find more questions by tags Ruby gemsRuby on Rails
the new migration
in the model tasks
belongs_to :user
in the model users
has_many :tasks
MB to need something else to choose, and I doubthas_many
in the controller tasks added
authorize @task
in the methods index, new, create, destroy (in method edit also necessary?)ApplicationPolicy
TaskPolicy
but still does not work properly ...
for example, added a selection box of users when creating a new task. That would remove the need to add some method current_user? Oh and there are minor inaccuracies in what I have yet to enter - elliott.Cronin commented on June 10th 19 at 15:00
the current_user.tasks.build(task_params)
- andre commented on June 10th 19 at 15:03then it will be necessary in task_params to add parameter with user id? - elliott.Cronin commented on June 10th 19 at 15:06
Github - andre commented on June 10th 19 at 15:09