SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 125 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"


CHAPTER 4 ?–  STORE ADMINISTRATION 60
More Models
Because you have more or less finished the administration side of Products, it??™s time to think
about the other parts the user interface should sport. If you remember the links we added to
the layout in the end of the last section, the two parts needed will be one for order handling,
and one for user administration. I??™ve modeled the order system like this: An Order has zero or
more OrderLines, and each Order is associated with a Customer. Regarding users, there will be
a User model object. You??™ll begin by generating these models:
jruby script/generate model Customer
jruby script/generate model Order
jruby script/generate model OrderLine
jruby script/generate model User
After you??™ve generated these models, you should open up the file db/migrate/004_create_
customers.rb and change it to look like this:
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :customers do |t|
t.column :given_name, :string
t.column :sur_name, :string
t.column :shipping_address_street, :string
t.column :shipping_address_postal, :string
t.column :shipping_address_zip, :string
t.column :shipping_address_country, :string
t.column :billing_address_street, :string
t.column :billing_address_postal, :string
t.column :billing_address_zip, :string
t.column :billing_address_country, :string
end
end
def self.down
drop_table :customers
end
end
This is arguably not such a good database design, but extending it more would take too
much focus from the core you need for the current project.


Pages:
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137