RubyOnRails
From ArchWiki
i18n |
---|
English |
简体中文 |
Contents |
Introduction
This document describes how to set up the Ruby on Rails Framework on an Arch Linux system.
Installation via rubygems
Since rails is not currently in the repositories, using rubygems is the easiest method to install Ruby on Rails. As of ruby-1.9 rubygems is part of ruby so you only have to install the ruby package to get rubygems as well:
# pacman -S ruby
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
updating gems
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.
Configuration
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".
Mongrel
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
That's it!
Using databases
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
sqlite is the default database for Ruby on Rails. To enable sqlite, install ruby-sqlite3
# pacman -S ruby-sqlite3
mysql
mysql needs to be configured prior to using it with rails. To know how, refer to the MySQL and LAMP pages on this wiki.
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)
More Resources
- Ruby on Rails http://rubyonrails.org/download
- Mongrel http://mongrel.rubyforge.org/
- MySQL
- LAMP