Ruby on rails 嵌套多态关系

Ruby on rails 嵌套多态关系,ruby-on-rails,ruby-on-rails-3.2,cancan,polymorphic-associations,Ruby On Rails,Ruby On Rails 3.2,Cancan,Polymorphic Associations,我的回复与帖子、电话和会议之间存在多态关系: class Response < ActiveRecord::Base belongs_to :responseable, polymorphic: true ... end class Post < ActiveRecord::Base has_many :responses, as: :responseable, dependent: :destroy ... end class Call <

我的回复与帖子、电话和会议之间存在多态关系:

 class Response < ActiveRecord::Base
    belongs_to :responseable, polymorphic: true
    ...
 end

class Post < ActiveRecord::Base
   has_many :responses, as: :responseable, dependent: :destroy
   ...
end

class Call < ActiveRecord::Base
   has_many :responses, as: :responseable, dependent: :destroy
   ...
end

class Meeting < ActiveRecord::Base
   has_many :responses, as: :responseable, dependent: :destroy
   ...
end
根据,在您的轮询方法结束时,您应该能够将其放置在轮询方法结束时:

authorize! :read, @responses
我相信原因是您只有在父对象的支持下才授权使用响应对象

根据能力进行编辑:

也许像

can :polling, Response, :user_id => user.id

我正在另一个项目中做一些工作,并且。如果/当这个答案被证明是正确的,我会更新它。

谢谢你的答案,尽管我认为不是这样。我试过了,没有改变。我已经用我的ability.rb文件更新了这个问题。也许这能帮助你告诉我我做错了什么。BetjaminRichards我也经历了同样的事情@斯科特姆,这是个好建议,但对我来说也不管用。我的情况稍有不同,我正在四处寻找,如果必要的话,可能会发布一个单独的问题。但是cancan和polymorphic在尝试访问我的照片>索引操作时无法满足我的需要,因为我的照片klass是多态的。你知道我仍然不确定我做了什么才能使它工作吗?我使用的方法与您使用“过滤器:授权”之前的
函数的方法相同,除了在我的函数中,而不是仅在
authorize!:阅读,(@post | | call | | meeting)
,我使用
授权!:管理,(@post | | call | | | meeting)
——我不知道为什么我已经很久没有查看此代码了。不过,在开发环境中删除链上的所有权限限制(使用:manage而不是:read)可能会更好,以查看是否可以跟踪错误的来源。。。
if user.role == "client"
  can :index, Post, :user_expert_private => false
  can :index, Post, :user_expert_private => true, :user_id => user.id
  can :show, Post, :user_expert_private => false, :countries => { :id => user.country_ids}
  can :show, Post, :user_expert_private => true, :user_id => user.id
  can :create, Post
  can :edit, Post, :user_id => user.id
  can :update, Post, :user_id => user.id
  can :read, Response
  can :create, Response
  can :polling, Response
  can :read, Call, :user_id => user.id
  can :create, Call, :user_id => user.id
  can :edit, Call, :user_id => user.id
  can :update, Call, :user_id => user.id
  can :read, Meeting, :user_id => user.id
  can :create, Meeting, :user_id => user.id
  can :edit, Meeting, :user_id => user.id
  can :update, Meeting, :user_id => user.id
  can :responses, :polling          
  can :posts, :autocomplete
end
authorize! :read, @responses
can :polling, Response, :user_id => user.id