This might be a bit of a noob question, but I'm asking anyway.
So I'm building an app where people make posts. So it's a social network.
But I don't want people to be able to edit and delete other's posts.
I don't think a role-based system would work here, because people only administrate their own posts only.
I was thinking some sort of AR association, but I don't know if that would work.
What I want is something like this for my app/models/ability.rb
:
class Ability
def initialize(user)
if current_user.username == @post.username
can :edit, Post
can :destroy, Post
end
end
end
How would I go about doing this (assuming the models are User
and Post
)?
So basically should I do a User has Posts, or User has and belongs to Posts?