📄 order.rb
字号:
# Copyright (c) 2006 The Pragmatic Programmers, LLC.# Reproduced from the book "Agile Web Development with Rails, 2nd Ed.",# published by The Pragmatic Bookshelf.# Available from www.pragmaticprogrammer.com/titles/rails2# # Permission is hereby granted, free of charge, to any person obtaining a copy# of this source code (the "Software"), to deal in the Software without# restriction, including without limitation the rights to use, copy, modify,# merge, publish, distribute, sublicense, and/or sell copies of the Software,# and to permit persons to whom the Software is furnished to do so, subject to# the following conditions:# # 1) This Software cannot be used in any training course or seminar, whether# presented live, via video, audio, screencast, or any other media, without# explicit prior permission from the publisher.# # 2) The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN# THE SOFTWARE. # Schema as of June 12, 2006 15:45 (schema version 7)## Table name: orders## id :integer(11) not null, primary key# name :string(255) # address :text # email :string(255) # pay_type :string(10) ##START:validate#START:select#START:has_manyclass Order < ActiveRecord::Base#END:select#END:validate has_many :line_items#END:has_many #START:select PAYMENT_TYPES = [ # Displayed stored in db [ "Check", "check" ], [ "Credit card", "cc" ], [ "Purchase order", "po" ] ] # ... #END:select #START:validate validates_presence_of :name, :address, :email, :pay_type validates_inclusion_of :pay_type, :in => PAYMENT_TYPES.map {|disp, value| value} # ... #END:validate #START:add_line_items_from_cart def add_line_items_from_cart(cart) cart.items.each do |item| li = LineItem.from_cart_item(item) line_items << li end end #END:add_line_items_from_cart#START:has_many end#END:has_many
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -