在我正在构建的应用程序中,用户可以将“贡献者”添加到他们的帐户中,以帮助他们为他们填写个人资料的某些方面。我cancan
用来帮助促进定义能力,但由于某种原因,为贡献者返回的查询以及他们也有权访问的用户没有正确返回。
这是我的能力文件:
module Abilities
class UserAbility < Ability
def initialize(user)
super(user)
if user.athlete_contributor?
can :update, Athlete, user: { id: user.managed_athlete_ids }
end
end
end
end
用户模型:
has_many :contributorships
has_many :managed_athletes, through: :contributorships, source: :athlete
贡献模式:
class Contributorship < ActiveRecord::Base
belongs_to :user
belongs_to :athlete
belongs_to :contributor, :class_name => "User"
belongs_to :user_type
attr_accessible :user_id, :user_type_id, :athlete_id
validates :user_type, presence: true
end
贡献者仪表板控制器:
class ContributorController < ApplicationController
before_filter :authenticate_user!
def index
authorize! :update, Athlete
@athletes = Athlete.accessible_by(current_ability)
end
end
@athletes
实例变量正在返回一个查询
SELECT "users".* FROM "users" WHERE "users"."type" IN ('Athlete') AND ('t'='f')
不知道我做错了什么,但是那个查询看起来很失败,哈哈。在此先感谢您的帮助!