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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:12:11+00:00 2026-05-25T19:12:11+00:00

I call this method (with helper method detailed below as well), defined in User.rb

  • 0

I call this method (with helper method detailed below as well), defined in User.rb model

def get_random_items
return nil unless groups_as_member
if groups_as_member == 1
  assignments = groups_as_member.assignments.limit(5)
  random_items = Post.rand_by_post(assignments)
end
random_groups = groups_as_member.sort_by{rand}.slice(0,5)
random_items = Array.new
i=0
return unless random_groups
until i == 10 do
  random_groups.each do |group|
    assignments = group.assignments.limit(5)
    if y = Post.rand_by_post(assignments)
      random_items << y
      i+=1
      if random_items == 5
        return random_items
      end
    else
      return random_items
    end
  end
end

return random_items
end

helper method rand_by_post in Post.rb

def self.rand_by_post(assignments)
  find_by_id(assignments.rand.post_id)
end

in the user controller show action:

def show
@public_groups = Group.public
@groups_member = @user.groups_as_member
@groups_as_owner = @user.groups_as_owner

@random_items = @user.get_random_items
end

when I comment out the call in the user show action, the user show works fine on my development and production server. But when I try to user the method the servers will just hang there, not doing anything. I can’t find any errors in the server logs or the heroku logs. My test writing skills are pretty limited, and I am having trouble writing one for the entire method.
Can anyone spot a problem?

  • 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-25T19:12:11+00:00Added an answer on May 25, 2026 at 7:12 pm

    if your random_groups is empty, your helper method get_random_items will go into an endless loop until i == 10 do ... end. That could be the reason.

    You might want to change return unless random_groups to return if random_groups.empty?

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

Sidebar

Related Questions

So I've got this helper method, right? def table_form_field(name_or_options = nil, *args, &block) #
I have a method in a rails helper file like this def table_for(collection, *args)
Every time I call this method my NSMutableData is leaking and I cannot figure
I'm getting a java outOfMemoryError when I call this method - i'm using it
I have this method call I have to use... financial_document.assets.length But financial_document.assets could be
I'd like to accomplish something like this: Call a method, say turn, and then
I'm trying to find the jQuery equivalent of this JavaScript method call: document.addEventListener('click', select_element,
I'm generating buttons dynamically that I want it to call a method like this:
This is my first time attempting to call an ASP.NET page method from jQuery.
This code involves a recursive Stored Procedure call and a not so great method

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.