Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # the code
- has_many :line_items do
- def total
- require 'pp'
- pp to_a
- if self[0] == self[1]
- self[1..-1].map(&:total).sum
- else
- map(&:total).sum
- end
- # self[1..-1].map(&:total).sum
- end
- end
- # result from pp =>
- [#<LineItem _id: 4e4d34f7bb71f923eb000001, _type: nil, name: "Hazelfern", image: nil, item_id: "A2750", invent_size_id: "", invent_color_id: "", config_id: "", configure: {}, quantity: 1, price: 295.0, delivery_status: nil, order_id: BSON::ObjectId('4e4d3352bb71f923ae000001')>,
- #<LineItem _id: 4e4d34f7bb71f923eb000001, _type: nil, name: "Hazelfern", image: nil, item_id: "A2750", invent_size_id: "", invent_color_id: "", config_id: "", configure: {}, quantity: 1, price: 295.0, delivery_status: nil, order_id: BSON::ObjectId('4e4d3352bb71f923ae000001')>]
Add Comment
Please, Sign In to add comment