【发布时间】:2012-11-18 16:52:27
【问题描述】:
这可能是一个菜鸟问题,但我还是要问。
所以我正在构建一个人们发布帖子的应用程序。所以它是一个社交网络。
但我不希望人们能够编辑和删除其他人的帖子。
我认为基于角色的系统在这里行不通,因为人们只管理自己的帖子只。
我在考虑某种 AR 关联,但我不知道这是否可行。
我想要的就是我的app/models/ability.rb:
class Ability
def initialize(user)
if current_user.username == @post.username
can :edit, Post
can :destroy, Post
end
end
end
我该怎么做(假设模型是User 和Post)?
所以基本上我应该做一个User has Posts,还是用户拥有并且属于Posts?
【问题讨论】:
-
您实际上遇到了什么问题?你试过吗?另外,您不会将用户与帖子相关联吗?为什么不
current_user == @post.user。或@post.owner -
@IsmaelAbreu 问题是我将如何去做,例如
has_many,has_one,has_and_belongs_to_many.
标签: ruby-on-rails ruby devise authorization cancan