簡體   English   中英

在active_admin中刪除用戶時出錯

[英]Error when deleting user in active_admin

嘗試刪除用戶時出現以下錯誤:

undefined method `handle_dependency' for #<ActiveRecord::Associations::HasAndBelongsToManyAssociation:0x007fa889b27328>)

我的用戶模型是:

class User < ActiveRecord::Base
  rolify
  attr_accessible :user_attributes
  attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :role_ids
  has_one :role, :dependent => :destroy

  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

  validates_presence_of :username, :email, :password, :case_sensitive => true
  validates_uniqueness_of :email, :case_sensitive => false
  validates_uniqueness_of :username, :case_sensitive => false

  before_create :assign_role

  def assign_role
    self.add_role :user if self.roles.first.nil?
  end

  after_create { |admin| admin.send_reset_password_instructions }

end

我的榜樣是:

class Role < ActiveRecord::Base
  has_many :users, :through => :users_roles, :dependent => :destroy
  belongs_to :resource, :polymorphic => true
  attr_accessible :role_attributes
  resourcify
  scopify
end

難道我做錯了什么? handle_dependency方法似乎不存在。 將不勝感激任何幫助。

謝謝。

我無法解釋該特定錯誤,但是看起來好像對rolify的宏方法確實有些困惑。 這里是一些背景:

rolify在用戶和角色模型之間建立一個has_and_belongs_to_many 因此,用戶模型中的has_one調用是不必要的,可能會引起問題。

resourcify用於指示用戶對於給定的類或該類的實例可以具有一個或多個角色。 用戶沒有與角色有關的角色,而與帖子或文章或其他有關角色。 因此,角色模型中的resourcify調用很可能會引起問題。 您需要在類中為要限制訪問的模型調用resourcify

我正在嘗試使除UserRole以外的模型重新rolify和重新resourcify對此進行了調查。 我沒有明確的答案,但我可以提供所發現的內容。 如果沒有其他要求,請確保您具有最新版本的rolify(“捆綁更新rolify”)。

我已經回答了類似的問題。

https://stackoverflow.com/a/23003808/1011746

不幸的是,我一直無法弄清您的代碼中:roles關聯是如何被覆蓋的。 可能是:roles以外的其他東西被覆蓋了,但我還沒有找到它。

這並不是一個很好的答案,但我希望它指向正確的方向。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM