Difference between revisions of "Ruby on Rails"

From ArchWiki
Jump to: navigation, search
m (remove contractions)
Line 22: Line 22:
 
== Installing via the AUR ==
 
== Installing via the AUR ==
 
{{Warning | This is not recommended, as this might not include the latest Rails version, and additional dependencies may be introduced that may require you to run "gem install" anyway. }}
 
{{Warning | This is not recommended, as this might not include the latest Rails version, and additional dependencies may be introduced that may require you to run "gem install" anyway. }}
There is a [http://aur.archlinux.org/packages.php?ID=14624 Rails package] available in the [[AUR]]. Note that this is not in an official repository, so you'll need to build it manually with makepkg or using an [[AUR Helpers|AUR helper]].
+
There is a [http://aur.archlinux.org/packages.php?ID=14624 Rails package] available in the [[AUR]]. Note that this is not in an official repository, so you will need to build it manually with makepkg or using an [[AUR Helpers|AUR helper]].
  
 
== Configuration ==
 
== Configuration ==
Line 34: Line 34:
 
  $ rails server
 
  $ rails server
  
Finally open your server address on port 3000 in your web browser. For example, if you're working on your local machine, visit http://localhost:3000/
+
Finally open your server address on port 3000 in your web browser. For example, if you are working on your local machine, visit http://localhost:3000/
  
 
A test-page should shown greeting you "Welcome aboard".
 
A test-page should shown greeting you "Welcome aboard".
Line 88: Line 88:
 
  $ rails new testapp_name -d mysql
 
  $ rails new testapp_name -d mysql
  
You then need to edit config/database.yml. Rails uses different databases for development, testing, production and other environments. Here's an example development configuration for MySQL running on localhost:
+
You then need to edit config/database.yml. Rails uses different databases for development, testing, production and other environments. Here is an example development configuration for MySQL running on localhost:
  
 
   development:
 
   development:
Line 96: Line 96:
 
     password: my_secret_password
 
     password: my_secret_password
  
Note that you don't have to actually create the database using a MySQL, as this can be done via Rails with:
+
Note that you do not have to actually create the database using a MySQL, as this can be done via Rails with:
 
  # rake db:create
 
  # rake db:create
  

Revision as of 03:37, 20 September 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language. It is intended to be used with an Agile development methodology that is used by web developers for rapid development.

This document describes how to set up the Ruby on Rails Framework on an Arch Linux system.

Ruby on Rails requires Ruby to be installed, so read that article first for installation instructions.

Installation via RubyGems (Recommended)

Template:Box Note

# gem install rails

Building the documentation takes a while. If you want to skip it, append the parameters --no-ri --no-rdoc to the install command.

# gem install rails --no-ri --no-rdoc

Updating gems

gem is a package manager for Ruby modules, somewhat like pacman is to Arch Linux. To update your gems, simply run:

# gem update

Installing via the AUR

Warning: This is not recommended, as this might not include the latest Rails version, and additional dependencies may be introduced that may require you to run "gem install" anyway.

There is a Rails package available in the AUR. Note that this is not in an official repository, so you will need to build it manually with makepkg or using an AUR helper.

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 new testapp_name

This makes a new folder in your current working directory. Next start the web server. It listens on port 3000 by default:

$ cd testapp_name
$ rails server

Finally open your server address on port 3000 in your web browser. For example, if you are working on your local machine, visit http://localhost:3000/

A test-page should shown greeting you "Welcome aboard".

Web servers

While the default Ruby On Rails HTTP server (WeBrick) is convenient for basic development it is not recommended for production use. Here are some suitable alternatives:

Mongrel

Mongrel is a drop-in replacement for WeBrick, that can be run in precisely the same way, but offers better performance.

First install the Mongrel gem:

# gem install mongrel

Then start it using:

# mongrel_rails start

Alternatively, you can just run "ruby script/server" again, as it replaces WeBrick by default.

Generally, Mongrel is used in a production environment by running multiple instances of mongrel_rails, which are load-balanced behind an nginx or Apache reverse proxy. However, you might find Phusion Passenger (see below) a much simpler solution for running a production environment.

Phusion Passenger (Recommended for production)

Passenger also known as Template:Filename is a module available for NginX and Apache, that greatly simplifies setting up a Rails server environment.

Start by installing the Passenger gem:

# gem install passenger

If you are aiming to use Apache with Passenger, run:

 # passenger-install-apache2-module

For NginX:

 # passenger-install-nginx-module

The installer will provide you with any additional information regarding the installation (such as installing additional libraries).

Note: See NginX#Ruby_.28Rack-based_and_Rails.29 for more information on configuring a Rails/ Passenger/NginX web stack.

Databases

Most web applications will need to interact with some sort of database. ActiveRecord (the ORM used by Rails to provide database abstraction) supports several database vendors, the most popular of which are MySQL, SQLite, and PostgreSQL.

SQLite

SQLite is the default lightweight database for Ruby on Rails. To enable SQLite, simply install sqlite3

# pacman -S sqlite3

MySQL 5+

Template:Box Note

Please refer to MySQL on how to install MySQL Server.

A gem with some native extensions is required, probably best installed as root:

# sudo gem install mysql

You can generate a rails application configured for MySQL by using the -d parameter:

$ rails new testapp_name -d mysql

You then need to edit config/database.yml. Rails uses different databases for development, testing, production and other environments. Here is an example development configuration for MySQL running on localhost:

 development:
   adapter: mysql
   database: my_application_database
   username: development
   password: my_secret_password

Note that you do not have to actually create the database using a MySQL, as this can be done via Rails with:

# rake db:create

If no errors are shown, then your database has been created and Rails can talk to your MySQL database.

See also

References