[英]Rails CanCanCan & Defining Abilities
我正在嘗試在Rails 4中制作一個應用程序。
我正在使用CanCanCan獲得權限,並使用Role_Model進行角色管理。
在我的Capacity.rb中,我將學生的能力定義為:
elsif user.try(:profile).present? && user.profile.has_role?(:student)
student_abilities
接着:
def student_abilities
can :read, Project.visible.current.available
在我的project.rb中,我將范圍定義為:
scope :visible, lambda { joins(:sweep => :disclosure).where('disclosures.allusers' => 'true')
.joins(:sweep => :finalise).where('finalises.draft' => 'false') }
scope :current, lambda { where('project.start_date >= ?', Date.today)}
scope :available, lambda { where('closed =', 'false')}
當我嘗試啟動服務器並生成視圖時,出現以下錯誤:
NoMethodError at /project_invitations
undefined method `available' for #<Project::ActiveRecord_Relation:0x007fdde41f2ee8>
當我嘗試從該功能的末尾刪除可用內容時,使其恰好:
can :read, Project.visible.current
我收到此錯誤:
entry for table "project"
LINE 1: ..." = 'true' AND "finalises"."draft" = 'false' AND (project.st...
^
我不知道為什么它不會讓我閱讀錯誤消息的結尾。
誰能看到我做錯了什么?
檢查表名。 它真的叫做“項目”,而不是“項目”嗎?
您描述范圍的方式有點奇怪。 例如,而不是where('closed =', 'false')
我將其描述為where(closed: false)
,從而最大程度地減少了SQL感知片段的數量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.