[英]activeadmin access one resource's comments by two models rails4
我有rails4應用程序。 它(其中包括) Client
和Developer
模型。 我也有Submission
模型。 我使用cancan gems使用activeadmin 。 我試圖使Submission
的注釋對Client
和Developer
(與某些submission
)都可見,但是當我檢查時, developer
僅看到他的注釋,而client
相應地看到他的注釋。 假設,這與Ability
類定義有關。 這是我的(部分):
def developer_rules(developer)
can [:read, :create], ActiveAdmin::Comment
end
def client_rules(client)
can [:read, :create], ActiveAdmin::Comment
can :manage, Client, id: client.id
end
有沒有人遇到過類似的事情? 不勝感激任何提示。 謝謝!
UPD:已解決
最終,問題與Ability
類無關。 ActiveAdmin為每個命名空間分別顯示注釋(即使這些注釋與相同的資源相關聯),因此解決方案是重寫此方法
def self.find_for_resource_in_namespace(resource, namespace)
where resource_type: resource_type(resource),
resource_id: resource_id_cast(resource),
namespace: namespace.to_s
end
刪除最后一行namespace: namespace.to_s
以便顯示注釋獨立於命名空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.