line_item.rb

来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 25 行

RB
25
字号
#---# Excerpted from "Agile Web Development with Rails, 2nd Ed."# We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.#---# Line items tie products to orders (and before that, to carts).# Because the price of a product may change after an order is placed, # the line item contains a copy of the product price at the time# it was created.class LineItem < ActiveRecord::Base  belongs_to :product  belongs_to :order  # Return a new LineItem given a Product.  def self.for_product(product)    item = self.new    item.quantity   = 1    item.product    = product    item.unit_price = product.price    item  endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?