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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:31:43+00:00 2026-05-22T21:31:43+00:00

Im working on creating a game in rails and I ran into a problem

  • 0

Im working on creating a game in rails and I ran into a problem for creating the scoring logic.

I have a model called Score which belongs to a user and has total_points as an attribute.

So every time a user creates a post(or whatever) I would like to automatically adjust the users total_score attribute.

I have a feeling that I could create a method somewhere in the score model but haven’t done this before so I’m a bit confused.

  • 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-22T21:31:44+00:00Added an answer on May 22, 2026 at 9:31 pm

    This is good use case for a ActiveRecord callback.

    #post.rb
    
      belongs_to :score
    
      after_create :update_total_score
    
      protected
    
      def update_total_score
        score.update_attribute :total_score, score.total_score + new_score_value
      end
    

    Note: if the post is updatable, then you would want to use after_save, but my guess is after_create is what you are looking for

    Good luck!

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

Sidebar

Related Questions

I am creating a bank simulation game and have the cron job working to
I am creating some C# tools for the game I am working on, and
I am working on creating an immutable class. I have marked all the properties
I'm working on creating a self updating application and one issue I'm running into
I'm creating a game, and am currently working on the Inventory system for it.
I am currently working on creating an import-based pipeline for my indie game using
I'm creating a DSL for an extensible card game engine I'm working on, with
I am working on a game that will have a two dimensional board of
I have little quiz game I've working on and am tracking correct answers. I
I'm working on creating an HTML5 game designed for six players and I would

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.