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 7569243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:07:09+00:00 2026-05-30T15:07:09+00:00

I need to wrap 3 results in separate divs. I am returning the results

  • 0

I need to wrap 3 results in separate divs.
I am returning the results with a basic query:

@items = Item.all

but in the view, I need to list the results in blocks of 3 :

<% @items.each do |item| %>    
<div>
  <p>Result 1</p>
  <p>Result 2</p>
  <p>Result 3</p>
</div>
<div>
  <p>Result 4</p>
  <p>Result 5</p>
  <p>Result 6</p>
</div>

etc…

Any help appreciated from a ROR noob

  • 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-05-30T15:07:10+00:00Added an answer on May 30, 2026 at 3:07 pm
    <% @items.each_slice(3) do |chunk| %>
    <div>
        <% chunk.each do |item| %>
            <p><%= item %></p>
        <% end %>
    </div>
    <% end %>
    

    (Related to: How to split (chunk) a Ruby array into parts of X elements?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to wrap a List<T> with some class that allows calls to set/get
I need to wrap a dynamically allocated array(from a = new double[100] for example)
I need to wrap zend form error messages in custom html. <div class=cerror id=ID-error>
In my R development I need to wrap function primitives in proto objects so
I'm using Moose and I need to wrap method calls in my project. It's
Most of the time when I need to wrap some code onto the next
Situation is simple. I need to wrap text around two inline objects (buttons with
I have an XSLT file generating plain HTML. I need to wrap some elements
I would like to create this layout in Silverlight. The text need to wrap
I need to simply wrap long text to display it in a few lines.

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.