It happens that I use a group_by to divide the posts according to their year by means of a scope, and it works great I print the posts in groups per year, the problem is that when migrating to Rails5, always I divided them but I printed the other post but not correspond to that year, if I have a post of 2014, I printed all, then the next group a post of 2015, I printed below all others, I do not know exactly what will be happening, I leave my code, for suggestions and help, greetings!
Index.html.erb
<% @enterprises.group_by { |a| a.created_at.year }.each do |year, enterprises| %>
<h5><b><%= year %></b></h5>
<% @enterprises.each do |enterprise| %>
<div class="main-section">
<h5><b><%= enterprise.name %></b></h5>
<p><%= enterprise.enterprise_tag.name %></p>
<p><%= truncate(enterprise.about, length: 140) %></p>
</div>
<% end %>
<% end %>
enterprise.rb
class Enterprise < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def self.year
where(created_at: Time.zone.now.beginning_of_year..Time.zone.now.end_of_year)
end
end