TypeError - 错误的参数类型符号(预期的模块) - Eager Loading Association - Rails 4

时间:2016-06-29 13:38:27

标签: ruby-on-rails-4

有人可以告诉我哪里出错了吗

在我的视图文件中,我有以下代码

<div>
  <ul>
    <% CategoryOutsourceadvert.include(:advert).all do |categoryoutsourceadvert| %>
      <li>
        <%= check_box_tag('q[category_outsourceadverts_id_eq_any][]', categoryoutsourceadvert.id ) %>
        <%= categoryoutsourceadvert.name %> (<%= categoryoutsourceadvert.adverts.uniq.count %>)
      </li>
    <% end %>
  </ul>
</div>

模型

Advert belongs_to category_outsourceadvert
CategoryOutsourceadvert has_many adverts

在我的终端我收到错误我不明白:

TypeError - wrong argument type Symbol (expected Module):
  app/views/adverts/_index.html.erb:134:in `block in _app_views_adverts__index_html_erb___100043438257983213_70223712632760'
  

有人可以向我解释这个错误意味着什么吗?

2 个答案:

答案 0 :(得分:5)

你忘记了&#39;:

CategoryOutsourceadvert.includes(:advert).all

答案 1 :(得分:1)

您必须使用联接替换包含,因此它看起来像CategoryOutsourceadvert.joins(:advert).all