File: app/models/line_item.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  class: LineItem#10
inherits from
  Base ( ActiveRecord )
has properties
class method: from_cart_item / 1 #15

Class Hierarchy

Object ( Builtin-Module )
Base ( ActiveRecord )
  LineItem    #10

Code

   1  #---
   2  # Excerpted from "Agile Web Development with Rails, 3rd Ed.",
   3  # published by The Pragmatic Bookshelf.
   4  # Copyrights apply to this code. It may not be used to create training material, 
   5  # courses, books, articles, and the like. Contact us if you are in doubt.
   6  # We make no guarantees that this code is fit for any purpose. 
   7  # Visit http://www.pragmaticprogrammer.com/titles/rails3 for more book information.
   8  #---
   9 
  10  class LineItem < ActiveRecord::Base
  11    belongs_to :order
  12    belongs_to :product
  13 
  14 
  15    def self.from_cart_item(cart_item)
  16      li = self.new
  17      li.product     = cart_item.product
  18      li.quantity    = cart_item.quantity
  19      li.total_price = cart_item.price
  20      li
  21    end
  22 
  23 
  24  end
  25