"destination"} 关于ruby-on-rails - ActiveAd-6ren">
gpt4 book ai didi

ruby-on-rails - ActiveAdmin 中的多态关联和 Formtastic

转载 作者:行者123 更新时间:2023-12-04 06:36:24 27 4
gpt4 key购买 nike

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

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 表单中创建一个新的突出显示,我如何将它分配给属性或目标?

最佳答案

您可以将此添加到突出显示表单:

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

关于ruby-on-rails - ActiveAdmin 中的多态关联和 Formtastic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26780100/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com