RubyOnRails (简体中文)
From ArchWiki
i18n |
---|
English |
简体中文 |
Contents |
简介
如何在Archlinux下建立Ruby on Rails开发环境.
通过rubygems来安装
rails当前没有安装在仓库中, 我们要使用rubygems来安装Ruby on Rails.首先安装rubygems软件包:
# pacman -S ruby rubygems
下面通过gem来安装rails . 所有依赖Ruby on Rails的包将自动下载.
# gem install rails
创建ri 文档需要一会时间. 如果不想要它,加上 --no-ri 参数到安装命令中.
# gem install rails --no-ri
更新gems
gem 是一个ruby模块包管理器, 类似pacman. 去更新gem, 简单的使用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 自带了一个基本的HTTP服务器 WeBrick. 你可以创建一个测试应用来测试它. 首先, 创建一个应用使用rails 命令:
# rails testapp_name
然后开始Web服务器. 它默认监听3000端口 :
# cd testapp_name # ruby script/server
完成后打开浏览器输入你服务器地址和3000端口. 例如, 如果服务器在本机 :
在浏览器地址栏输入http://127.0.0.1:3000/
你将看到Rails默认欢迎界面 "Welcome aboard".
Mongrel
Ruby On Rails 默认HTTP 服务器(WeBrick) 可以方便去测试,但是不推荐在产品中使用. 一个更好的选择是 Mongrel.
通过gem来安装mongrel:
# gem install mongrel
然后开始mongrel:
# mongrel_rails start
That's it!
使用数据库
多数Web应用都需要数据库去保存数据. Ruby on Rails 是非常万能的因为它支持许多数据库.
sqlite
sqlite是Ruby on Rails默认的数据库. 要去激活sqlite, 安装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.
首先安装通过gem安装mysql模块:
# gem install mysql
你可以创建使用mysql的Rails应用使用 -d 参数:
# rails -d mysql testapp_name
然后你需要编辑 config/database.yml. Rails 为production/tests/development使用3种数据库.为达到测试目的, 仅仅使用development数据库. 填写数据库,用户名,密码字段.
去测试数据, 使用下面命令 :
# rake db:migrate
如果没有错误显示, 那么表示建立正确. 你可以在命令行中连接mysql. 例如 :
# 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