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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:31:08+00:00 2026-05-25T18:31:08+00:00

In my rails 3.1 project I have a Book model that has a ID,

  • 0

In my rails 3.1 project I have a Book model that has a ID, NAME, and BOOK_ORDER. I am using the ranked-model gem, which for its sorting process creates large numbers in the sorting(:book_order) column. Im looking for some help to create a method to sort all of the Books by the :book_order column, then simplify the :book_order numbers.

So, I have this:

controller

@books = Books.all

view

<% @books.each do |book| %>
 <%= book.book_order %>
<% end %> 

# book1.book_order => 1231654
# book2.book_order => 9255654
# book3.book_order => 1654

But want this:

view

<% @books.each do |book| %>
 <%= book.clean_book_order %>
<% end %> 

# book1.clean_book_order => 2
# book2.clean_book_order => 3
# book3.clean_book_order => 1

Additionally, i don’t want to change the database entry, just use its current values to make simpler ones.

Thanks!


UPDATE:

Thanks to nash’s response I was able to find a solution:

In my Book Model I added the clean_book_order method:

class Book < ActiveRecord::Base     
  include RankedModel
  ranks :book_order 

  def clean_book_order
    self.class.where("book_order < ?", book_order).count + 1
  end
end  
  • 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-25T18:31:08+00:00Added an answer on May 25, 2026 at 6:31 pm
    <% @books.each do |book| %>
     <%= book.book_order_position %>
    <% end %> 
    

    EDIT:

    Oh, I see. https://github.com/harvesthq/ranked-model/issues/10

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

Sidebar

Related Questions

In my rails project I have a presenter method that has a helper view
I'm using DataMapper in a Rails project, and have found that calling to_json on
I have to developed a project that is using DB2 and jRuby on rails.
I have a postgresql database that has this column structure: Author id name Book
I have a old rails project that is using rails 3.0.9 and I am
I have a Rails project which has a Postgres database for the actual application
in a rails project i have to deal with lots of strings, that are
I have project on rails 3 with multiplayer using Faye. The error block in
I have a rails project that I would like to set up email notifications
In my Rails 3.1.1 project I have an ActiveModel that talks to API (ripped

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.