私はポリモーフィックモデルを持っています:
class Picture < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
class Service < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
class Product < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
activeadminモデルを両方の親(サービスと製品)で機能させるには、次のようなことを行う必要があります。
ActiveAdmin.register Picture do
def who_do_i_belong_to?
uri = how_to_get_uri?
if uri.match(/products/)
:product
else
:service
end
end
belongs_to who_do_i_belong_to?
end
回避策は機能しているようです。who_do_i_belong_to内からurl/uriを取得する方法が恋しいだけですか?方法。
controller.controller_name # "admin/services", so it is not useful.
よろしくお願いします。