加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ActiveScaffold:如何为多态关联创建下拉选择

发布时间:2020-12-16 21:18:21 所属栏目:百科 来源:网络整理
导读:我正在尝试创建一个下拉选择框,用于与ActiveScaffold进行多态关联. 我有: class Award belongs_to :sponsorship,:polymorphic = :trueendclass Organization has_many :awards,:as = :sponsorshipendclass Individual has_many :awards,:as = :sponsorshipe
我正在尝试创建一个下拉选择框,用于与ActiveScaffold进行多态关联.

我有:

class Award
  belongs_to :sponsorship,:polymorphic => :true
end

class Organization
  has_many :awards,:as => :sponsorship
end

class Individual
  has_many :awards,:as => :sponsorship
end

尝试在awards_controller中创建选择下拉框时
有:

config.columns[:sponsorship].form_ui = :select

我收到以下错误:

ActionView::TemplateError
(uninitialized constant
Award::Sponsorship)

我不确定这是我做得不对或我正在尝试的事情
完成不直接支持AS.

非常感谢一些建议.

解决方法

我不熟悉ActiveScaffold ……但是,他们的文档中的快速传递揭示了一个关于has_many的部分:我熟悉ActiveRecords …所以对于它的价值,你的多态关联应该是多少像这样写的?:
class Organization
  has_many :awards,:through => :sponsorship
end

class Individual
  has_many :awards,:through => :sponsorship
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读