Rails cancan gem不会给出对象名称

时间:2015-10-29 01:36:46

标签: ruby-on-rails

在我的cancan能力档案中,

:manage, Topic(不起作用)

:manage, :topic(确实有用)

任何人都知道为什么?非常感谢

3 个答案:

答案 0 :(得分:1)

cancan需要一个字符串或符号,而不是整个类。如果你想要,你也可以尝试:

#ex03.py
#-------
from composes.utils import io_utils
from composes.transformation.scaling.ppmi_weighting import PpmiWeighting

#create a space from co-occurrence counts in sparse format
my_space = io_utils.load("./data/out/ex01.pkl")

#print the co-occurrence matrix of the space
print my_space.cooccurrence_matrix

#apply ppmi weighting
my_space = my_space.apply(PpmiWeighting())

#print the co-occurrence matrix of the transformed space
print my_space.cooccurrence_matrix

答案 1 :(得分:0)

  

仍然给我未经授权的消息。

如果您指的是未经授权的内容,则必须了解CanCan(现在CanCanCan的工作方式):

https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities

CanCanCan wiki看,您可以将Constant名称分配给can方法:

#app/models/ability.rb
class Ability
   include CanCan::Ability

   def initialize(user)
      user ||= User.new
      can :manage, Topic, user_id: user.id
   end
end

如果您升级Gemfile以包含latest version of CanCanCan,则应使用Constant名称定义:

#Gemfile
gem 'cancancan', '~> 1.13', '>= 1.13.1'

答案 2 :(得分:0)

我发现如果设置:manage, Topic不起作用的原因。我不小心把authorize_resource :class => false放在我的模型类主题中。