Skip to content

Instantly share code, notes, and snippets.

@hernandezalek
Last active March 10, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hernandezalek/2ebeddd23a434595dd61dc91907fc30a to your computer and use it in GitHub Desktop.
Save hernandezalek/2ebeddd23a434595dd61dc91907fc30a to your computer and use it in GitHub Desktop.
Imrpimiendo empresas por categorias
# De esto
@enterprises = Enterprise.order(enterprise_tag_id: :asc).paginate(:page => params[:page], :per_page => 6)
# A posiblemente esto
@enterprise_tags = Enterprise.all.paginate(:page => params[:page], :per_page => 6)
<!-- Refactorizando este codigo -->
<% enterprise_tag = nil %>
<% @enterprises.each do |enterprise| %>
<% unless enterprise_tag == enterprise.enterprise_tag %>
<h2><strong><%= enterprise.enterprise_tag %></strong></h2>
<% enterprise_tag = enterprise.enterprise_tag %>
<% end %>
<h4><%= enterprise.name %></h4>
<% end %>
<%= will_paginate @enterprises, :container => false %>
<!-- A mas o menos esto -->
<% @enterprise_tags.each do |category| %>
<% if category.enterprises.size > 0 %>
<h2><strong><%= category %></strong></h2>
<% category.enterprises.each do |enterprise| %>
<%= enterprise.name %>
<% end %>
<% end %>
<% end %>
<%= will_paginate @enterprise_tags, :container => false %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment