Rails L10n | 259
db/migrate/001_create_people.rb
class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people do |t|
t.string :first_name
t.string :last_name
t.string :home_phone
t.string :office_phone
t.string :mobile_phone
t.text :address
t.string :country
end
end
def self.down
drop_table :people
end
end
app/models/person.rb
class Person < ActiveRecord::Base
def full_name
"#{first_name} #{last_name}"
end
def address_with_country
"#{address}\n#{country}"
end
end
Running the migration creates thedb/globalize.sqlite3 database file:
$ rake db:migrate
== 1 CreatePeople: migrating ==================================================
-- create_table(:people)
-> 0.0020s
== 1 CreatePeople: migrated (0.0021s) =========================================
$ ls db/
globalize.sqlite3 migrate schema.rb
Here are the models, views, helpers, and controllers that we create for a very simple
first iteration of the address book. For simplicity, we only include theindex(list of all
people in the address book),new(display a form to create a new entry), andshow(dis-
play an individual entry’s details) actions.
config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :people
end