我正在尝试添加一个按钮以在 Rails 中将回复标记为已读。我目前有这样的东西。
# /app/models/ability.rb
...
can :manage, Reply, :user_id => user.id
...
load_and_authorize_resource
我的 RepliesController中也有
# /app/controllers/replies_controller.rb
class RepliesController < ApplicationController
load_and_authorize_resource
def update
@reply = Reply.find(params[:id])
@reply.isRead = true
if @reply.save
flash[:notice] = "Marked as ready."
flash[:alert] = params[:id]
redirect_to root_path
else
render :action => 'new'
end
end
我有一个按钮,用户可以在其中将回复标记为已读。
= button_to "Mark as read", idea_reply_path(reply.idea,reply), :method => "put"
问题是,由于我试图从ability.rb(顶部)中定义的其他 user.id 所有者更新对象,因此我没有编辑它的权限。
如果我添加这样的东西它会起作用,但我也将管理整个回复对象的权利授予其他人。
can :manage, Reply, :to_user_id => user.id
我需要一种方法,只允许用户管理isRead?
他的 user.id 匹配的对象的属性to_user_id
。