https://wiki.archlinux.org/api.php?action=feedcontributions&user=Cyphus&feedformat=atomArchWiki - User contributions [en]2024-03-28T22:18:18ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Ruby_on_Rails&diff=141635Ruby on Rails2011-05-16T14:40:58Z<p>Cyphus: /* SQLite */</p>
<hr />
<div>[[Category:HOWTOs (English)]]<br />
[[Category:Web Server (English)]]<br />
{{i18n|RubyOnRails}}<br />
<br />
[http://rubyonrails.org/ 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.<br />
<br />
This document describes how to set up the Ruby on Rails Framework on an Arch Linux system.<br />
<br />
Ruby on Rails requires [[Ruby]] to be installed, so read that article first for installation instructions.<br />
<br />
== Installation via RubyGems (Recommended) ==<br />
{{Box Note | If this command is run without being root (using sudo or otherwise), the gem will be installed into the home directory of the user.}}<br />
<br />
# gem install rails<br />
<br />
Building the documentation takes a while. If you want to skip it, append the parameters --no-ri --no-rdoc to the install command.<br />
# gem install rails --no-ri --no-rdoc<br />
<br />
===Updating gems===<br />
gem is a package manager for Ruby modules, somewhat like pacman is to Arch Linux. To update your gems, simply run:<br />
# gem update<br />
<br />
== Installing via the AUR ==<br />
{{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. }}<br />
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]].<br />
<br />
== Configuration ==<br />
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 :<br />
<br />
$ rails new testapp_name<br />
<br />
This makes a new folder in your current working directory. Next start the web server. It listens on port 3000 by default :<br />
<br />
$ cd testapp_name<br />
$ rails server<br />
<br />
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/<br />
<br />
A test-page should shown greeting you "Welcome aboard".<br />
<br />
== Web servers ==<br />
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:<br />
<br />
=== Mongrel ===<br />
Mongrel is a drop-in replacement for WeBrick, that can be run in precisely the same way, but offers better performance.<br />
<br />
First install the Mongrel gem:<br />
# gem install mongrel<br />
<br />
Then start it using:<br />
# mongrel_rails start<br />
<br />
Alternatively, you can just run "ruby script/server" again, as it replaces WeBrick by default.<br />
<br />
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.<br />
<br />
=== Phusion Passenger (Recommended for production) ===<br />
[http://www.modrails.com/ Passenger] also known as {{Filename|mod_rails}} is a module available for [[NginX]] and [[Apache]], that greatly simplifies setting up a Rails server environment.<br />
<br />
Start by installing the Passenger gem:<br />
# gem install passenger<br />
<br />
If you are aiming to use [[Apache]] with Passenger, run:<br />
# passenger-install-apache2-module<br />
<br />
For [[NginX]]:<br />
# passenger-install-nginx-module<br />
<br />
The installer will provide you with any additional information regarding the installation (such as installing additional libraries).<br />
<br />
{{Note|See [[NginX#Ruby_.28Rack-based_and_Rails.29]] for more information on configuring a Rails/ Passenger/NginX web stack.}}<br />
<br />
== Databases ==<br />
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.<br />
<br />
=== SQLite ===<br />
SQLite is the default lightweight database for Ruby on Rails. To enable SQLite, simply install sqlite3<br />
# pacman -S sqlite3<br />
<br />
=== MySQL 5+ ===<br />
{{Box Note | You must first install MySQL with the appropriate headers in /usr/include (just pacman -S mysql is fine) before attempting to install the Ruby MySQL extensions }}<br />
<br />
Please refer to [[MySQL]] on how to install MySQL Server.<br />
<br />
A gem with some native extensions is required, probably best installed as root:<br />
# sudo gem install mysql<br />
<br />
You can generate a rails application configured for MySQL by using the -d parameter :<br />
$ rails new testapp_name -d mysql<br />
<br />
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:<br />
<br />
development:<br />
adapter: mysql<br />
database: my_application_database<br />
username: development<br />
password: my_secret_password<br />
<br />
Note that you don't have to actually create the database using a MySQL, as this can be done via Rails with :<br />
# rake db:create<br />
<br />
If no errors are shown, then your database has been created and Rails can talk to your MySQL database.<br />
<br />
== See also ==<br />
* [[Ruby]]<br />
* [[nginx]]<br />
* [[LAMP]]<br />
* [[MySQL]]<br />
<br />
== References ==<br />
* Ruby on Rails http://rubyonrails.org/download<br />
* Mongrel http://mongrel.rubyforge.org/</div>Cyphus