Ruby on Rails (简体中文)
如何在Archlinux下建立Ruby on Rails开发环境.
Since rails is not currently in the repositories, using rubygems is the easiest method to install Ruby on Rails. First, install the rubygems package :
# pacman -S ruby rubygems
Next install rails via gem . All the dependencies for Ruby on Rails will be downloaded.
# gem install rails
Building the ri documentation takes a little while. If you want to skip it, append the --no-ri parameter to the install command.
# gem install rails --no-ri
gem is a package manager for ruby modules, similar in concept to pacman. To update your modules, simply ask gem:
# gem update
Installation via AUR
There is also a rails package in AUR. Since it isn't at the moment in the community repository, you will need to build it by yourself, either by using makepkg or by using an helper tool like yaourt.
If installing rails via AUR allows you to manage it via pacman, keep in mind that not all ruby modules (gems) are packaged and you might need to install some modules via gems anyways.
Rails is bundled with a basic HTTP server called WeBrick. You can create a test application to test it. First, create an application with the rails command :
# rails testapp_name
Next start the web server. It listens on port 3000 by default :
# cd testapp_name # ruby script/server
Finally open your server address on port 3000 in your web browser. For example, if the server is on the local host :
open http://127.0.0.1:3000/ in web browser
You should see a test page titled "Welcome aboard".
The default Ruby On Rails HTTP server (WeBrick) while being convenient for tests is not recommend for production use. A better alternative is Mongrel.
Install mongrel via gem:
# gem install mongrel
Next start mongrel:
# mongrel_rails start
Most web applications need some sort of database to stock the data. Ruby on Rails is very versatile because it supports a lot of databases.
sqlite is the default database for Ruby on Rails. To enable sqlite, install ruby-sqlite3
# pacman -S ruby-sqlite3
First install the gem module for mysql:
# gem install mysql
You can generate a rails application configured for mysql by using the -d parameter :
# rails -d mysql testapp_name
You then need to edit config/database.yml. Rails uses 3 databases for production/tests/development. For testing purposes, only the development database is needed. Fill out the database, username & password fields.
To test the database, issue the following command :
# rake db:migrate
If no error are shown, then your setup is correct. To be sure, you can take a peak at the mysql database. For example :
# mysql -u root -p testapp_development mysql> show tables; +-------------------+ | Tables_in_testapp | +-------------------+ | schema_migrations | +-------------------+ 1 row in set (0.00 sec)