order.rb

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

RB
41
字号
#---# 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.#---# An Order contains details of the purchaser, and# has a set of child LineItem rows.class Order < ActiveRecord::Base  has_many :line_items  # A list of the types of payments we accept. The key is  # the text displayed in the selection list, and the  # value is the string that goes into the database.  PAYMENT_TYPES = [    [ "Check",          "check" ],     [ "Credit Card",    "cc"    ],    [ "Purchase Order", "po"    ]  ].freeze  validates_presence_of :name, :email, :address, :pay_type    # Return a count of all orders pending shipping.  def self.count_pending    count("shipped_at is null")  end  # Return all orders pending shipping.  def self.pending_shipping    find(:all, :conditions => "shipped_at is null")  end  # The shipped_at column is +NULL+ for  # unshipped orders, the dtm of shipment otherwise.  def mark_as_shipped    self.shipped_at = Time.now  endend

⌨️ 快捷键说明

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