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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:39:01+00:00 2026-06-03T09:39:01+00:00

How it is better to count for each line item it’s total cost, and

  • 0

How it is better to count for each line item it’s total cost, and then for all count total summary? I have such db: article has table existence where i have prices, but how to display price * quantity? it’s better to do in controller? or in model, but when in model, how to do this, note, in db I have only price, and quantity is given in line item:
I want something like this:

class LineItem < ActiveRecord::Base
    belongs_to :article
    belongs_to :cart
    def total_price
      existence.PRICEM * quantity
    end
end
  • 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-03T09:39:02+00:00Added an answer on June 3, 2026 at 9:39 am

    This core business functionality should reside in your models.

    Your cart could have:

    class Cart
      def total_price
        line_items.inject(0.0){|sum,line_item| sum + line_item.total_price }
      end
    end
    
    class LineItem
      def total_price
        quantity * price
      end
    end
    

    This way you can still loop over your line-items to show their price, and then your cart as well. As this transfers to an order, you’ll want to store those values rather than calculate them.

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

Sidebar

Related Questions

Suppose you have a file that contains IP addresses, one address in each line:
I have Chart1[Series1] Chart1[Series2] .... It has multiple Series and each series has Several
I have a plist. It has several dozen keys, each with NSMutableArray items: ...
I have a large array with around 20k objects in it. Each object has
I notice that StackOverflow has a views count for each question and that these
For representing a length or count variable, is it better to use signed or
Is better to use the below statement Convert.ToInt32(0 + stringValue) If not then why?
For example: I have two entities named Project and Todo where a project has
i have a quite weird question which probably has no practical use but the
A text file I what to read has a certain pattern: Name line [tag

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.