-
-
Save hernandezalek/2ebeddd23a434595dd61dc91907fc30a to your computer and use it in GitHub Desktop.
Imrpimiendo empresas por categorias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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