Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:57:15+00:00 2026-06-14T09:57:15+00:00

These two lists are only slightly different as I need to treat the first

  • 0

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" 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:57:17+00:00Added an answer on June 14, 2026 at 9:57 am

    You can use the each_with_index method and customize each loop depending of the index value.

    %ul.list_container
      - @links.sort_by { |link| link.votes.where(:up => true).count - link.votes.where(:up => false).count }.reverse.each_with_index do |link, index|
      %li{ :style => "#{index < 3 ? '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"
        - if index < 3
          = link.url_html
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists: ask[] timeStamp[] I need to add the information in these
What is the difference between these two declarations of a list of lists? >>>
There are two unsorted lists containing Integers, need to find the common largest integer
Given two lists of different types, is it possible to make those types convertible
I have these two lists: boys = [1,2,3] girls = [1,2,3] How would you
From these two lists: list_A = [eyes, clothes, body etc] list_B = [xxxx_eyes, xxx_zzz,
I had an interview question along these lines: Given two lists of unordered customers,
There are two lists: List<string> excluded = new List<string>() { .pdf, .jpg }; List<string>
Suppose there are two lists a = {a1, a2, a3} and b = {b1,
Given two lists of equal length, is there a simpler or preferred way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.