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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:03:30+00:00 2026-05-24T17:03:30+00:00

I have an @array and a view where each array element is listed. Right

  • 0

I have an @array and a view where each array element is listed. Right next to that list I want a link which says “Sort by rank”.

I know how to sort an array by a certain attibute

array.sort {| a, b | a[:rank] <=> b[:rank] }

But I don’t know what I have to put in the view and controller, so it displays me the sorted array as soon as I click the 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-05-24T17:03:31+00:00Added an answer on May 24, 2026 at 5:03 pm

    Generally you create a parameter that re-loads the page with the appropriate filter engaged:

    <%= link_to('Sort', :order => 'rank') %>
    

    Then in your controller you have something that re-sorts the list if required:

    if (params[:order] == 'rank')
      @array.sort_by!(&:rank)
    end
    

    There are plug-ins that will make this easier, plus you should probably be doing the sorting in the database if you have pagination.

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

Sidebar

Related Questions

I have an array of folders. Each folder is listed as a table view
I have a list view full of items that contain multiple widgets each such
I have a float array in java and want to convert each element to
I have an activity that has two tabs and a list view in each.
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have an array of buttons. Now, when each button is clicked, I want
I have code in which I have array of view in scroll view. In
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I have an array of numbers that potentially have up to 8 decimal places
I have Groups that has_many projects. I also created an order view that is

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.