How to Get a New Rails Project Started
Not sure if this will be useful to anyone else, but as my own personal memory proxy, here are the steps I like to take when starting a new rails project:
First, setup the project
- generate directory structure
#> rails [projectname]
Second, setup the database and initial tables
- create databases
mysql> create database [projectname]_development
mysql> create database [projectname]_test - create database user
mysql> grant all privileges on [projectname]_development.* to ‘[username]’@’localhost’ identified by ‘[password]’
mysql> grant all privileges on [projectname]_test.* to ‘[username]’@’localhost’ identified by ‘[password]’ - update config/database.yml with proper usernames and passwords. Don’t forget to update the path of the mysql.sock file. On debian/ubuntu, add this to the dev & test database configs:
socket: /var/run/mysqld/mysqld.sock - create migration
#> ./script/generate migration initial_tables - define the schema in the migration file (db/migrate/001_initial_tables.rb) , remembering “proper” rails naming conventions
- run the migration
#> rake db:migrate
Third, get the basic CRUD app running
- generate trestle
#> script/generate trestle [modelname] - edit config/routes.rb to add a default route
map.connect '', :controller => '[defaultcontroller]', :action => '[defaultaction]' - delete default html page
#> rm public/index.html - start the webserver in daemon mode
#> mongrel_rails start -d - connect to the app on port 3000
Now comes all the real fun…

