我有这两个模型:
class Photo < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :photos
end
而这个declarative_authorization
角色的设置:
role :reg_ser do
has_permission_on :photos, :to => [:show] do
if_attribute :user_id => is { user.id }
end
end
我想允许向用户显示他上传的图像 - 只有他的图像。我的意思是,例如:
user_id | photo
1 | 1
1 | 2
1 | 3
2 | 4
而当用户设置了 url/photos/1
时,这个图像只会显示为user_id
数字1
,当user_id=2
显示这个地址时,他看不到图像......
有可能这样做吗?