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 101 | Next

Ola Bini

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

I??™ve decided to name the models Product,
ProductType, and ProductCategory. These names are important to remember, because Rails
has some guidelines regarding how to translate a model name into a database table.
Product Type
First of all, you??™ll create the model called ProductType, because it doesn??™t have any dependencies
on other models. Each Product will have one type, and each ProductCategory will also
have one type, so these depend on the type being there.
To create a new model, you use the model generator, like this (in the root directory of the
Shoplet application):
jruby script/generate model ProductType
This creates several files and also prints some output. It should look like this:
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/product_type.rb
create test/unit/product_type_test.rb
create test/fixtures/product_types.yml
create db/migrate
create db/migrate/001_create_product_types.rb
Now, as mentioned before, all model code resides in the directory app/models. A file called
product_type.rb now exists in that directory. However, because the ProductType is a simple
CHAPTER 4 ?–  STORE ADMINISTRATION 41
model object, you won??™t add anything to it right now. It??™s fine as it is. You do need to define the
migration for ProductType, and decide which fields it should contain. The way to do that is to
open the file called db/migrate/001_create_product_types.rb in a text editor. Right now that
file is quite sparse, because you haven??™t added any content to it.


Pages:
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113