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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:51:25+00:00 2026-05-20T17:51:25+00:00

So I have a method in my video model: def rank_sum(score, video) … …

  • 0

So I have a method in my video model:

def rank_sum(score, video)
 ...
 ...
end

that returns a value that I want to store in my database for the specific video in the rank_sum column.

I also order my videos like so:

default_scope order('videos.rank_sum')

Now my question is how should I update the rank_sum column? With a callback? How often should I be updating this?

  • 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-20T17:51:25+00:00Added an answer on May 20, 2026 at 5:51 pm

    I’d recommend that you don’t create methods that clash with any of the automatically created attributes of your model, as this will interfere with built-in Rails functionality such as form generation.

    You could simply rewrite your method as follows:

    def update_rank_sum(score)
      new_rank = self.rank_sum + score # Or substitute whatever logic is necessary here.
      update_attribute :rank_sum, new_rank
    end
    

    This will update the value in the database (if necessary) each time the update_rank_sum method is called.

    If you want to postpone the update of the rank_sum value until some later point, you can change the implementation as follows:

    def update_rank_sum(score)
      new_rank = self.rank_sum + score # Or substitute whatever logic is necessary here.
      self.rank_sum = new_rank
    end
    

    But remember that you will need to call save on the Video instance to persist the change to the database.

    Updating one field of a single row is likely to take your database in the order of milliseconds, so I wouldn’t worry too much about performance unless you know you will need to handle 10s or 100s of changes per second.

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

Sidebar

Related Questions

I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to
I have a method in my Python code that returns a tuple - a
I have a method that can return either a single object or a collection
I have a method in .NET (C#) which returns string[][] . When using RegAsm
I have a method that takes an IQueryable. Is there a LINQ query that
I have a method that periodically (e.g. once in every 10 secs) try to
Can someone please clarify the following; if a have the following model; presentation-->slide-->video where
We have decided that it is time to ditch the ad-hoc method of deploying
I have a Video entity that has multiple Genres, public class Video { public

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.