1

我有一个在 Ruby 1.9.3、Rails 3.2 和 Bootstrap 2 中使用 simple_form 启动的 RoR 应用程序。在继续之前,我决定迁移到 Ruby 2.0、Rails 4.0 和 Bootstrap 3。这是一个让我难过的迁移问题。

在 Rails 3.2 版本中,这可以正常工作:

<%= f.association :services, collection: @account.company.services, as: :check_boxes, label_method: :description %>

在 Rails 4.0 世界中,它没有给我任何收集数据。在 Rails 4.0 中,这些都有效:

<%= f.association :services, as: :check_boxes %>
<%= f.association :services, collection: Service.all, as: :check_boxes, label_method: :description %>
<%= f.association :services, collection: Service.where(id: 1), as: :check_boxes, label_method: :description %>

在 Rails 控制台上,@account.company.services返回ActiveRecord::Associations::CollectionProxy [#< ... >]>Service.all返回ActiveRecord::Relation [#< ... >]>

有谁知道将我的选择放入f.association收藏夹的正确格式?

编辑:

它现在正在工作。我的部分问题原来是使用没有加入“服务”的“公司”记录(我的错)。我确实将它与其他问题联系起来,所有这些都源于 CollectionProxy 替换了旧的数组(或关系)返回对象。我能够通过在集合上使用 .to_a 来修复其中的大部分。

4

0 回答 0