Born: Ruby-on-Rails - People

47 downloads 114 Views 244KB Size Report
Efficiently Creating Database Applications with Ruby On Rails. By: Kenton Born. Abstract. This tutorial was created as a simplified, shorter version of the tutorial ...
Efficiently Creating Database Applications with Ruby On Rails By: Kenton Born Abstract This tutorial was created as a simplified, shorter version of the tutorial provided by InstantRails (“http://instantrails.rubyforge.org/wiki/wiki.pl”). The tutorial shows how a user can efficiently set up an application that allows for the adding, editing, reading, and deleting of database items. Procedure •

If you have not done so, install InstantRails at http://instantrails.rubyforge.org/wiki/wiki.pl. Follow their instructions for installing and configuring MySQL to work with InstantRails.



Open the command prompt and navigate to ../ruby/InstantRails/rails_apps



Type “rails mycookbook” o This created the MVC file architecture for the application



By default, it wants to use a database called “mycookbook_development”, so we want to create this database. o The default database be changed by editing the mycookbook\config\database.yml file o Enter the following commands into the command prompt  mysql -u root -p  create database cookbook2_development;  exit



Create a script at ..\cookbook2\db\create.sql to create tables for the database It should contain the following sql:

--------------------------------------------------drop table if exists recipes; drop table if exists categories; create table categories ( id int not null auto_increment, name varchar(100) not null default '', primary key(id) ) engine=InnoDB; create table recipes ( id int not null auto_increment, category_id int not null, title varchar(100) not null default '', description varchar(255) null, date date null, instructions text null, constraint fk_recipes_categories foreign key (category_id) references categories(id), primary key(id) ) engine=InnoDB;

-----------------------------------------------------



Run the script o Navigate back to the mycookbook directy o Type: “mysql –u root –p mycookbook_development