Skip to Main Content
Professional Ruby on Rails™
book

Professional Ruby on Rails™

by Noel Rappin
February 2008
Intermediate to advanced content levelIntermediate to advanced
479 pages
14h
English
Wrox
Content preview from Professional Ruby on Rails™

6.1. Plugging In to Your Legacy

For the purposes of having something concrete to wrap your head around, let's assume that Soups OnLine has secured a strategic coup: the ability to deliver information from Ingredientopedia, the world's leading online source of information about the kind of ingredients that one might use in, say, a soup. Sadly, due to the sort of contrivance that involves armies of fictional lawyers, Soups OnLine has to use the existing database as-is, and is not free to migrate the schema to something useful. So you're stuck with a database schema that looks, in part, like this (a naming convention only a database admin could love):

CREATE TABLE 'ingredientopedia'.'the_ingredient_table' (
  'ingredient_id' INTEGER AUTO_INCREMENT,
  'ingredient_name' VARCHAR(255),
  'ingredient_description' VARCHAR(4000),
  'ingredient_nutritional_info' VARCHAR(4000),
  'ingredient_category_id' INTEGER,
  PRIMARY KEY ('ingredient_id')
)
CHARACTER SET utf8;

To get Rails to open this database, you need to adjust the database.yml file to add three more database environments: one for each Rails environment. You can use the YAML merge feature to make the declaration more compact, like this:

ingredient: &ingredient
  adapter: mysql
  username: root
  password:
  socket: /tmp/mysql.sock
ingredient_development:
  database: ingredientopedia_development
  <<: *ingredient

ingredient_production:
  database: ingredientopedia_production
  <<: *ingredient

ingredient_test:
  database: ingredientopedia_test
  <<: *ingredient
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails® Bible

Ruby on Rails® Bible

Timothy Fisher
Rails 4 in Action

Rails 4 in Action

Yehuda Katz, Rebecca Skinner, Stephen Klabnik, Ryan Bigg

Publisher Resources

ISBN: 9780470223888Purchase book