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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:17:38+00:00 2026-05-13T17:17:38+00:00

I have two models of concern, Order and Kit; each order has_one :kit Each

  • 0

I have two models of concern, “Order” and “Kit”; each order has_one :kit

Each “Kit” has a ‘cost’ value. Within a controller I want to be able to sum together the costs for each ‘order’.

Logically I thought this would make sense (but it doesn’t work):

@revenue = Order.Kit.sum(:cost) 

Any help would be appreciated. Thanks.


Example:

A user creates a new order for a kit which has cost of 20. I would like the @revenue to be of hence value 20 (reflecting ‘sales’). When someone else creates a new order for the same kit, @revenue should change to 40.

  • 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-13T17:17:39+00:00Added an answer on May 13, 2026 at 5:17 pm

    I’m guessing you have it backward, and each order has a kit_id.

    . . . in which case you just need the number of orders for a given kit, multiplied by the kit cost:

    kit = Kit.find(kit_id)
    number_of_orders = Order.count(:all,:conditions=>['kit_id = ?',kit_id])
    @revenue = kit.cost*number_of_orders
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, Tweets and TweetsLocations, associated to each other with: class Tweets
I have two models: Director, and Film. I want to create a web query
I have two models Employee & Unit . Unit has many Employees . I
I have two models 'Company' and 'Vehicle' And two tables in database named same
i have two models. Batch and Subject. The relation between them are Batch HAS_MANY
I have two models class User < ActiveRecord::Base has_many :posts searchable do text :post_titles
I have two models User and Movie.. Where those are associated with UsersWatchlist.. public
I have two models, Article and Post that both inherit from a base model
I have two models. We'll call them object A and object B. Their design
I have two models indexed for searching (User and Item). I'm trying to do

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.