- Use the rails command to generate a skeleton for your web application.
- Create a database and its tables using MySQL. Make sure to follow Rails conventions in naming tables and table columns.
- Use the scaffold generator to automatically create each model and its controller and views.
- Manually code relationships between tables into model files.
You can now go ahead and view your web application in the browser after starting the web server.
You can start shaping up your web application from here. Go back to the controllers and views, make needed modifications then go back and view your application in the browser. Keep modifying the application files till your web application is complete and is shaped like what you have in mind.
The above sequence is merely a proposed sequence. It is specially suitable for new comers to Ruby on Rails. Sure there are alternative paths. For instance, one can start by creating an empty database, and use Ruby on Rails migrations to create the tables. One can also go about writing controllers and views by hand without first using the scaffolding features of Rails.
If you would like to use migrations rather than creating the database tables directly with MySQL, then you can follow this alternative approach:
- Command line prompt, rails_apps folder: rails appname
- MySQL command line console: create database appname_development;
- Generate a migration after going to the appname folder: ruby script/generate migration add_tables
- Edit 001_add_tables.rb file to define database tables.
- rake migrate
- For each model (~table): ruby script/generate ModelName
- Define relationships between database tables inside model files (appname/app/models/ModelName)
- ruby script/server
- Open your browser at: http://127.0.0.1:3000/ModelName+'s'