: 调节器 </跨度> :
def show @user = authorize User.find(params [:id])结束
的Gemfile:
宝石’轨道’,‘〜&gt; 5.1.1’宝石’设计’,‘〜&gt; 4.3’宝石’专家’,‘〜&gt; 1.1’
我的 调节器 </跨度> :
class PostsController锟“”帖子是#{@post.class.name}!“除非@ post.is_a?岗位 结束
def set_post #这应该返回一个post的实例 @post = authorize Post.find(params [:id]) 结束结束
政策 </跨度> :
阶级
返回记录显然是主人的变化,没有反映在 1.1 发布。
# Retrieves the policy for the given record, initializing it with the # record and user and finally throwing an error if the user is not # authorized to perform the given action. # # @param user [Object] the user that initiated the action # @param record [Object] the object we're checking permissions of # @param record [Symbol] the query method to check on the policy (e.g. `:show?`) # @raise [NotAuthorizedError] if the given query method returned false # @return [true] Always returns true def authorize(user, record, query) policy = policy!(user, record) unless policy.public_send(query) raise NotAuthorizedError, query: query, record: record, policy: policy end true end
解决方法是:
def authorize(record, query = nil) super record end