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
This core business functionality should reside in your models.
Your cart could have:
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.