0

这是我的 CanCan 设置:

if user.college_coach?
  can :read, Coach, :id => user.id
  can :update, Coach, :id => user.id
  can :update_billing_information, Coach, :id => user.id
  can :update_account_type, Coach, :id => user.id
  can :edit_account, Coach, :id => user.id
  can :access_roster_builder, Coach, :id => user.id, :account_type => { :name => ["Recruiter", "Team", "Free"] }
  can :access, Coach, :college_dashboard
  can :access_saved_profiles, Coach, :id => user.id, :account_type => { :name => ["Team"] }
  can :access_draftboard, Coach, :id => user.id, :account_type => { :name => ["Team"] }
  can :update, Draftboard, :coach_id => user.id
  can :access_contributors, Coach, :id => user.id, :account_type => { :name => ["Team"] }
  can :access_deleted, Coach, :id => user.id, :account_type => { :name => ["Team"] }
  can :save_searches, Search, id: user.id, account_type: { name: ["Recruiter", "Team"] }
  can :read, Athlete
  can :update, Athlete
  can :update_account_type, Athlete
  can :keep, Athlete
  can :draft, Athlete
  can :share, Athlete
  can :notes, Athlete
  can :contact, Athlete
  can :cut, Athlete
  can :read, Stat
  can :view, :social_box
end

在我看来:

  <% if can?(:save_searches, Search) %>
    <input type="button" class="blk-button hide search-related" id="save-to-pdf" value="Save Results to a PDF" />
  <% end %>

即使我将用户的帐户类型更改为免费帐户类型,该按钮仍会显示...不确定是什么原因导致此功能不起作用..

4

1 回答 1

1

看起来你在 CanCan DSL 上有太多的阻塞条件。这条线引起了我的注意:

can :save_searches, Search, id: user.id, account_type: { name: ["Recruiter", "Team"] }

# This means... grant :save_searches when
search.id == user.id && search.account_type == { name: ["Recruiter", "Team"] }

由于这可能不是您想要的,请尝试将您的帐户验证从 CanCan DSL 中移出并放入基本条件语句中。

if user.college_coach?
  # ...
  if ["Recruiter", "Team"].include? user.account_type.name
    can :save_searches, Search
  end
end
于 2013-06-14T23:09:38.427 回答