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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:45:09+00:00 2026-05-31T00:45:09+00:00

I am following this tutorial http://railscasts.com/episodes/29-group-by-month and have built a system to allow a

  • 0

I am following this tutorial http://railscasts.com/episodes/29-group-by-month

and have built a system to allow a user to assign a contact to a specific label. However I need pagination such that it only returns the first 3 labels, second 3 labels, etc.

How do I go about doing this in ActiveRecord

def index
    @connections = @current_user.user_contacts.where('label_id > 0').order("updated_at")
    @connections_label = @connections.group_by { |t| t.label_id }
end

Contact Table
ID | Name | Label_ID
01 | Mike | 1

Label Table
ID | Name
1  | PSU

UPDATED

  • 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-31T00:45:11+00:00Added an answer on May 31, 2026 at 12:45 am

    You could try take

    What are you using for pagination? If you wanted to print this out in erb, it would be something like this.

    <%= @connections.group_by { |t| t.label_id }.take(3).each do |label, connections| %>
      <%= label.name %>
      <% connections.each do |connection|
        <%= connection.name %>
      <% end %>
    <% end %>
    

    This would give you the first 3 labels:

    Label 1
     Mike
     ...
    
    Label 2
     Bob
     ...
    
    Label 3
     Jim
     ...
    

    In your controller you should be able to something like @VVN suggested:

    .take(3).offset((params[page] || 0) * 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following this tutorial: http://railscasts.com/episodes/253-carrierwave-file-uploads or atleast I want to but would like to
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I am following this tutorial http://www.codeproject.com/KB/cpp/authforwebservices.aspx They have this in the tutorial [SoapHeader(Authentication, Required
I'm following this tutorial: http://developer.android.com/resources/tutorials/views/hello-datepicker.html . I have two EditText, and which one calls
I have created a dataset with the C# designer following this tutorial http://www.devx.com/dotnet/Article/28678/1954 ;
I have created bg3.9.png image following this tutorial http://developer.android.com/guide/developing/tools/draw9patch.html but when i put it
I am following Ryan Bate's tutorial: http://railscasts.com/episodes/163-self-referential-association But my setup is slightly different. I
I've been following this tutorial: http://emumair.wordpress.com/2011/03/17/social-network-authentication-with-omniauth-and-authlogic/ . I've walked through it all and I'm
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
http://www.codinghorror.com/blog/2008/04/setting-up-subversion-on-windows.html I am following this as a guide to install subversion. The tutorial at

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.