【问题标题】:Polymorphic associations and Formtastic in ActiveAdminActiveAdmin 中的多态关联和 Formtastic
【发布时间】:2014-11-06 12:58:31
【问题描述】:

我有一个简单的多态关联:

class Highlight < ActiveRecord::Base
  belongs_to :highlightable, polymorphic: true
end

class Property < ActiveRecord::Base
  has_many :highlights, as: :highlightable
end

class Destination < ActiveRecord::Base
  has_many :highlights, as: :highlightable
end

在 active_admin 表单中创建新的 Highlight 我如何将其分配给 Property 或 Destination?

【问题讨论】:

  • 你有想过这个吗?

标签: ruby-on-rails activeadmin formtastic


【解决方案1】:

您可以在高亮表单中添加 this:

f.input : highlightable_type, as: :select, collection: {"Property" => "property", "Destination" => "destination"}

【讨论】:

    猜你喜欢
    • 2013-05-16
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    相关资源
    最近更新 更多