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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:53:48+00:00 2026-06-03T04:53:48+00:00

I am attempting to do a rails record count then do a calculation from

  • 0

I am attempting to do a rails record count then do a calculation from those records to give me a final number:

Example

100 Records = A
30 Records = B
Total Records = C

A+(-B)=C

I am not even going to show you what I tried… in retrospect I am very new to rails and it made no logical sense!

UPDATE:
To further expand:

When implementing this I realized that there might be some slight difference from what it solves above.
I have a MVC called “POST” It was some records within the table one specifically is called “VOTE” the vote integer will consist of 1 or (-1). Each post will have a VOTE column that represent a value of 1 or (-1). I am trying to create an analytic metric that consists of the following:

TOTAL = (Total posts with Value 1) + (Total posts with Value -1)
Example

1234 = 2000 + (-776)

Thank you in advance!

  • 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-03T04:53:49+00:00Added an answer on June 3, 2026 at 4:53 am

    In general,
    C = A.count + B.count

    If you want C to be the union of A and B, then do

    C = A & B
    C.count # Number of elements in C
    

    For your specific case:

    yes_votes = POST.where('VOTE = ?', 1)
    no_votes = POST.where('VOTE = ?', -1)
    total = yes_votes.count - no_votes.count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to use the data series from this example no longer passes the JSONLint
I'm attempting to get my first hello world rails example going using the rails'
I'm attempting to use Mongoid from a plain Ruby script (not via Rails or
I am running Rails 3 Beta2 and attempting to get Autotest working with rspec.
I am attempting to create a table in rails.. I need to be able
I'm attempting to use the new standard way of loading seed data in Rails
I am attempting to parse, not evaluate, rails ERB files in a Hpricot/Nokogiri type
I'm fairly new to Ruby on Rails, and I'm attempting to create some fancy
I'm very new to rails and attempting to deploy some changes to my production
Attempting to use JRuby 1.2.0 and Rails 2.3.2 with an embedded Derby database. I've

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.