Ruby on Rails project creation

From Smith family

Jump to: navigation, search

Some steps to go through when creating a new Ruby on Rails project.

Contents

Subversion control setup

Assume you're using NetBeans IDE for development.

  • Some files should be excluded from version control. Add the svn:ignore to the following directories, with the given value.
Directory Value
log *.log
config database.yml
tmp *
doc *doc
then copy config/database.yml to config/database.sample.yml, which will be included in the repository.
If you're doing this on Netbeans, you may need to remove these files from Netbeans's first commit queue.

The idea is that each developer (if you're collaborating) will use their own database.yml file. It also means that the database password for your production server isn't exposed in the Subversion repository.

  • Mark some files as being executable. NetBeans should do this for you on the first commit. If not, add the svn:executable property (with value '*') to every file in the scripts directory and to all the public/dispatch.* files.

Database creation

  • Log into the MySQL server
user@desktop:~# mysql -u root -p

Development and test databases

For the development project, where the user is restricted to the localhost only

  • Create the database
mysql> create database project_development;
mysql> create user 'project'@'localhost';
mysql> grant all on project_development.* to 'project'@'localhost';
  • In database.yaml, create the relevant details:
development:
  host: localhost
  adapter: mysql
  database: project_development
  port: 3306
  username: project
  password:
  socket: /var/run/mysqld/mysqld.sock
Rails assumes the user is on the localhost anyway.
On Red Hat/Fedora boxes, the MySQL socket may be at /var/lib/mysql/mysql.sock instead.
  • If you want to use Sqlite3, use this stanza instead:
test:
  adapter: sqlite3
  encoding: utf8
  reconnect: false
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

Production database

For the production project, where the user can log in from any host but access is protected by a password

  • Create the database
mysql> create database project_production;
mysql> create user 'project'@'localhost' identified by 'password';
mysql> grant all on project_production.* to 'project'@'localhost';
  • In database.yaml, create the relevant details:
development:
     host: localhost
     adapter: mysql
     database: project_production
     port: 3306
     username: project
     password: password

Enable log rotation for production servers

Modify config/environments/production.rb to include these lines:

# Rotate logs when the file grows to 10Mb, keep 10 old log files
config.logger = Logger.new(config.log_path, 10, 10.megabytes)

Change the welcome page

  • Pick the controller you want to handle requests at the root of your website. For instance, for the demo Depot application, you'll want the store controller to handle HTTP requests of http://www.depot.tld/, as well as the more usual http://www.depot.tld/store/.
  • Uncomment the map.root line in config/routes.rb and insert the name of the controller:
map.root :controller => "store"
  • Remove or welcome page, public/index.html
  • If you now point a browser at http://localhost:3000/, you should see the page served by the controller you chose!

See also

There are a couple of frameworks with most of the obvious plugin-installation already done.

  • Bort is a standard Rails app with authentication, pagination, and the like already included.
  • Insoshi is a basic social networking application.
Personal tools