60 lines
1,4 KiB
Ruby
60 lines
1,4 KiB
Ruby
#---
|
|
# Excerpted from "Agile Web Development with Rails",
|
|
# published by The Pragmatic Bookshelf.
|
|
# Copyrights apply to this code. It may not be used to create training material,
|
|
# courses, books, articles, and the like. Contact us if you are in doubt.
|
|
# We make no guarantees that this code is fit for any purpose.
|
|
# Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
|
|
#---
|
|
$: << File.dirname(__FILE__)
|
|
require "connect"
|
|
|
|
require "rubygems"
|
|
require "active_record"
|
|
|
|
class Order < ActiveRecord::Base
|
|
end
|
|
|
|
an_order = Order.new
|
|
an_order.name = "Dave Thomas"
|
|
an_order.email = "dave@example.com"
|
|
an_order.address = "123 Main St"
|
|
an_order.pay_type = "check"
|
|
an_order.save
|
|
|
|
Order.new do |o|
|
|
o.name = "Dave Thomas"
|
|
# . . .
|
|
o.save
|
|
end
|
|
|
|
an_order = Order.new(
|
|
name: "Dave Thomas",
|
|
email: "dave@example.com",
|
|
address: "123 Main St",
|
|
pay_type: "check")
|
|
an_order.save
|
|
|
|
an_order = Order.new
|
|
an_order.name = "Dave Thomas"
|
|
# ...
|
|
an_order.save
|
|
puts "The ID of this order is #{an_order.id}"
|
|
|
|
an_order = Order.create(
|
|
name: "Dave Thomas",
|
|
email: "dave@example.com",
|
|
address: "123 Main St",
|
|
pay_type: "check")
|
|
|
|
orders = Order.create(
|
|
[ { name: "Dave Thomas",
|
|
email: "dave@example.com",
|
|
address: "123 Main St",
|
|
pay_type: "check"
|
|
},
|
|
{ name: "Andy Hunt",
|
|
email: "andy@example.com",
|
|
address: "456 Gentle Drive",
|
|
pay_type: "po"
|
|
} ] )
|