These two lists are only slightly different as I need to treat the first 3 items a little differently than the rest. The only reason this isn’t working now is because the variable with the regex is called twice. Any idea how to get the first 3 items (as shown in the first %li) separated from the rest without having to repeat everything like this?
%ul.list_container
- @links.sort_by { |link| link.votes.where(:up => true).count - link.votes.where(:up => false).count }.reverse.first(3).each do |link|
%li
.various_containers
%p
= link_to link.title, "http://youtube.com/embed/#{link.url.to_s.match(/\/\/youtu.be\/(\S+)$/)[1]}/?rel=0", :class => "youtube title_link"
= link.url_html
- @links.sort_by { |link| link.votes.where(:up => true).count - link.votes.where(:up => false).count }.reverse.drop(3).each do |link|
%li{:style => 'margin-bottom: 50px;'}
.various_containers
%p
= link_to link.title,"http://youtube.com/embed/#{link.url.to_s.match(/\/\/youtu.be\/(\S+)$/)[1]}/?rel=0", :class => "youtube title_link"
You can use the each_with_index method and customize each loop depending of the index value.