Prev | Current Page 392 | Next

Brad Ediger

"Advanced Rails"

sqlite3
encoding: utf8
First, we create the model and migration for the Person model and its corresponding
people table:
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 the db/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 the index (list of all
people in the address book), new (display a form to create a new entry), and show (display
an individual entry??™s details) actions.
config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :people
end
260 | Chapter 8: i18n and L10n
app/controllers/people_controller.


Pages:
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404