这是我的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 %>
即使我将用户的帐户类型更改为免费帐户类型,该按钮仍会显示...不确定是什么导致此操作无效..
答案 0 :(得分: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