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

  • Home
  • SEARCH
  • 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 6188965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:19:38+00:00 2026-05-24T02:19:38+00:00

Absolute RoR newbie here, I’m trying to render out multiple leagues in a loop,

  • 0

Absolute RoR newbie here, I’m trying to render out multiple leagues in a loop, incrementing the div_# each time, here’s a cut down version, without the html. It works when I hard code div_1 or div_2 to be sorted, but div_name doesn’t work, even though it has the right contents I need it to be seen as the array.

<%  div_1 = Array.new
    div_1 << { :Name => 'Rob', :Played => '2', :Won => '1', :Lost => 1, :Points => 4}

    div_2 = Array.new
    div_2 << { :Name => 'Gavin', :Played => '2', :Won => '1', :Lost => 1, :Points => 4}

    for i in (1..2) 

    i = i.to_s
    div_name = "div_" + i 

    div_name.sort_by { |position| position[:Points] }.reverse!.each do |position| %>

<%= position[:Name] %>
  • 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-24T02:19:40+00:00Added an answer on May 24, 2026 at 2:19 am

    There are lots of problems here:

    div_1 = Array.new
    div_1 << { :Name => 'Rob', :Played => '2', :Won => '1', :Lost => 1, :Points => 4}
    

    div_1 is now an array with a single element, which is a hash. You don’t need an array if you’ll just have one element in it.

    for i in (1..2) 
    

    Where’s the block for this loop? After that statement, i is still undefined, so when you call

    i = i.to_s
    

    you’ll get a NameError.

    div_name = "div_" + i 
    

    Even if i == 1, div_name will be a string with value ‘div_1’, and not a copy or instance of the div_1 variable you define above.

    div_name.sort_by { |position| position[:Points] }.reverse!.each do |position| %>
    

    Now you’re trying to call sort_by on a string, which doesn’t respond to that, because it doesn’t make sense.

    <%= position[:Name] %>
    

    You don’t have a variable named position defined at this scope.

    Also, when you find yourself putting lots of logic inside of a view within <% %> tags, that’s a sign that you need to move that code elsewhere, like to the controller. You could define and calculate @positions as an array of hashes in the controller, and then in the view do something like:

    <% @positions.each do |position| %>
      <%= position[:name] %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

absolute newbie here: I have table with columns: resource, resource_type_field, value. I have this
Absolute newbie question, any help is highly appreciated :) I am using curvycorners (
I am an absolute objective-c, c, and openGL newbie. Hence, when I found coco2d
Is absolute absolute or not? I am trying to make an input form with
I am trying to absolute a 'hero' image at the top of the page
An absolute time is given in stored in this format: time = 000:03:07.447 How
I'm an absolute newbie to Varnish & caching in general, so this question might
I'm an absolute newbie to Moose and so far I have read Moose and
absolute newbie in this space so please adjust :-) this has to work on
I'm an absolute newbie when it comes down to subversion and SVN (don't even

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.