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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:13:27+00:00 2026-06-05T02:13:27+00:00

Unfortunately I’m probably still too much a Rails beginner, so, even though I thought

  • 0

Unfortunately I’m probably still too much a Rails beginner, so, even though I thought about and tried different approaches, I didn’t get to work what I want and now have to ask for help again.

I have a REST comment vote mechanism with thumbs up and down for each comment. That works fine, each handled with counter_cache to count. Now, based on these thumbs up and down votes, I want to calculate a plusminus value for each comment, thumbs_up-votes – thumbs_down-votes. Although I’m not sure if it’s the most efficient way to deal with that, I am planning to have the plus-minus value as an extra integer attribute of the comment model (whereas the thumbs up and down are own models). So, what I basically want is, that when a thumbs_up is saved, the comment’s plusminus attr automatically should be += 1, and respectively for the thumbs_down.save a -= 1.

How can I issue such an action from within the thumbs_up controller? Do I need to modify my form_for or is my approach completely wrong?

Is there an after_save callback to deal with an attribute of a different model?

  • 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-06-05T02:13:28+00:00Added an answer on June 5, 2026 at 2:13 am

    From what you’ve given, it’s hard to tell. But I’d say that if you need to show a comment’s “thumbs up” and “thumbs down” independently, store them as fields for your Comment model. Then, just making a helper method in your Comment model to get a comment’s rating:

       def rating
          thumbs_up - thumbs_down
       end
    

    Edit:
    With your new comment, I’d still say make a helper method rather than a field.

       #models/comment.rb
       def rating
          thumbs_up.all.length - thumbs_down.all.length #or whatever way you want to do this
       end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unfortunately, my C app for PIC32 needs OO too much and I can't continue
Unfortunately ThinkingSphinx is not an option for DataMapper (though they say support is planned).
Unfortunately I haven't coded Java for about five years and I absolutely can not
Unfortunately the specification does not tell anything about precision. The xml scheme definition states
Unfortunately, Google didn't help me much: I'm looking for some information regarding the execution
Unfortunately, the term schema has come to take on different definitions for different databases.
unfortunately a not too easy to answer question, as I cannot really provide you
Unfortunately I'm very new to different control properties and was wondering why the following
Unfortunately official guide for creating Rails plugins is outdated: http://guides.rubyonrails.org/plugins.html and I didn't find
Unfortunately I still have to support ie6. I currently don't have a machine with

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.