Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 rails 4 cancancan多态性_Ruby On Rails 4_Cancancan - Fatal编程技术网

Ruby on rails 4 rails 4 cancancan多态性

Ruby on rails 4 rails 4 cancancan多态性,ruby-on-rails-4,cancancan,Ruby On Rails 4,Cancancan,无论出于何种原因,用于跟踪/跟随者的代码不再有效,我怀疑我需要一个cancancan规则,但我不确定。希望有人能看到我的错误 剖面模型 class Profile < ActiveRecord::Base ... has_many :follower_relationships, foreign_key: :following_id, class_name: 'Follow', dependent: :destroy has_many :followers, through:

无论出于何种原因,用于跟踪/跟随者的代码不再有效,我怀疑我需要一个cancancan规则,但我不确定。希望有人能看到我的错误

剖面模型

class Profile < ActiveRecord::Base
  ...
  has_many :follower_relationships, foreign_key: :following_id, class_name: 'Follow', dependent: :destroy
  has_many :followers, through: :follower_relationships, source: :follower
  has_many :following_relationships, foreign_key: :follower_id, class_name: 'Follow', dependent: :destroy
  has_many :following, through: :following_relationships, source: :following
  ...
end
我尝试过各种can能力,但我觉得我只是随便乱闯。如果上面的行没有错误,有人能指出我应该执行的can规则吗


谢谢

我明白了,它实际上并没有因为模型组织而被阻止,这些动作在能力类中是不允许的

添加:

can :follow, Profile
can :unfollow, Profile

解决了问题。很抱歉浪费了大家的时间。

嗨,很难理解,以前在坎坎坎工作过吗?或者您刚刚添加了新功能?Cancancan与用户合作,您可以发布配置文件并跟踪控制器吗?。查看@Gaston我按照您的要求添加了额外的代码点,这里没有控制器,只有一个用于持久化更改状态的模型。什么不起作用?从你的问题看不清楚。是否不允许您调用
follow
方法?
class ProfilesController < ApplicationController
  ...
  load_and_authorize_resource
  ...
  def follow
    if current_user.profile.follow(@profile.id)
      SystemMailer.following_email(@profile.user, current_user).deliver_later
      redirect_to request.referrer
    end
  end

  def unfollow
    redirect_to request.referrer if current_user.profile.unfollow(@profile.id)
  end 
class Ability
  include CanCan::Ability
  ...
  can :edit, Profile, user_id: user.id
  can :read, Profile
  can :update, Profile, user_id: user.id
  can :show, Profile
  can :manage, Profile, id: user.profile.id
can :follow, Profile
can :unfollow, Profile