Rails cancancan 求教

catfish23 · 2017年07月21日 · 最后由 catfish23 回复于 2017年07月21日 · 1713 次阅读

按照文档上写的,遇到个问题

Controller 内容如下:

class DepartmentsController < ApplicationController
  before_action :set_department, only: [:show, :edit, :update, :destroy]
  load_and_authorize_resource

Ability 文件如下:

class Ability
  include CanCan::Ability

  def initialize(user)
    # Define abilities for the passed in user here. For example:
    #
      user ||= User.new # guest user (not logged in)
      if user.admin?
        can :manage, :all
      elsif user.blank?
        can :read, :Department
      else
        can :manage, :Department
        cannot [:destory,:update], :Department
      end

现在问题是,用户角色都获取正确,admin 角色没问题,但是 user 角色的没有 Department 的任何权限,load_and_authorize_resource 这句话写了就如此,是有别的什么地方遗漏了么?rails 4.2.3 cancancan2.0, 查了好多文章没发现有什么明显的错漏

:Department 去掉 : 试试

:Department 前多了个冒号

哎呀,失误了。。。。低级,谢谢楼上指正

需要 登录 后方可回复, 如果你还没有账号请 注册新账号