Ruby on rails Rails:in_groups_of-error

Ruby on rails Rails:in_groups_of-error,ruby-on-rails,Ruby On Rails,我正试图找出如何在我的观点中链接到我的文章,我被“in_groups_of”这个电话困住了 我的观点如下: <div class="row"> <div class="col-md-10 col-md-offset-1"> <% Article.in_groups_of(2) do |group| %> <div class="row"> <% group.compact.each do |articl

我正试图找出如何在我的观点中链接到我的文章,我被“in_groups_of”这个电话困住了

我的观点如下:

<div class="row">
  <div class="col-md-10 col-md-offset-1">
    <% Article.in_groups_of(2) do |group| %>
      <div class="row">
        <% group.compact.each do |article| %>
            <div class="col-md-5 col-md-offset-1">
              <div class="indexdisplay">
              <%= image_tag article.image_url, width: '100%', height: '200px' if article.image.present? %>
                  <div class="indexheading"> <%= link_to article.title, article %> </div>
                <div class="indexsubtext">    <%= truncate(article.body, :ommission => "...", :length => 250) %></div>
                 </div>
            </div>
              <% end %>
              </div>

    <% end %>

  </div>
</div>

“…”,:长度=>250)%>

试试这个。

谢谢。我必须再等5分钟才能接受这一点
NoMethodError at /
undefined method `in_groups_of' for #<Class:0x007fa70300cda8>
NameError at /
uninitialized constant ActionView::CompiledTemplates::Articles
<div class="row">
  <div class="col-md-10 col-md-offset-1">
    <% Article.all.in_groups_of(2) do |group| %>
      <div class="row">
        <% group.compact.each do |article| %>
            <div class="col-md-5 col-md-offset-1">
              <div class="indexdisplay">
              <%= image_tag article.image_url, width: '100%', height: '200px' if article.image.present? %>
                  <div class="indexheading"> <%= link_to article.title, article %> </div>
                <div class="indexsubtext">    <%= truncate(article.body, :ommission => "...", :length => 250) %></div>
                 </div>
            </div>
              <% end %>
              </div>

    <% end %>

  </div>
</div>