Agile Web Development with Rails 翻译(四)

Agile Web Development with Rails 翻译(四)

第三章 安装 Rails

 

 

在开始写Rails应用程序之前,你需要下载Rails框架并安装它到你的计算机上。你需要在Ruby解释程序内运行RailsRails代码。但是,如果也用RubyGems包管理系统变量则事情要变得容易些,所以我们也这么安装。最后,如果你使用的数据库不是MySQL,你可能需要安装相应的Ruby库来做界面。


警告:这一章很乏味,通篇是单击这个输入那个等指令。幸运地是本章很短,我们尽可能地短一些。

让我们看看如何在WindowsOS X Linux 下安装。

 

3.1 Windows 下安装

 

1、首先,检查看你是否已经安装了Ruby。在命令提示符上输入ruby –v。如果Ruby应答,则会显示它的版本号。可进一步检查是否安装了RubyGems。输入gem –version 。如果没有提示错误,则可跳到步骤3。否则的话,我们要安装Ruby

2、如果没有安装Ruby,那么在http://rubyinstaller.rubyforge.ore上有个方便的一键安装程序可以下载,然后运行并安装它。

3、现在我们使用RubyGems来安装RailsRails需要的一些东西。

C:> gem install rails --include-dependencies

祝贺你!你现在有了Rails

 

3.2 Mac OS X 下安装

 

 

3.3 Unix/Linux 下安装

 

 

3.4 Rails 和数据库

 

如果你的Rails应用程序使用了数据库,那么在你能开始开之前,还要安装它。

Rails带有DB2MySQLOraclePostgresSQL ServerSQLite数据库。便了MySQL,其它的你还需要安装数据库驱动程序,它是Rails可以连接并使用你的数据库引擎的一个库。本章包含了连接和指令。

在开始丑陋的细节之前,让我们看看我们能跳过这些痛苦不。如果你没有创建数据库是由于你只想检查一下Rails的话,我们还是推荐你试试MySQL。它安装起来很容易,而且Rails还内建MySQL数据库驱动程序(用纯Ruby写的)。你可以使用它来将Rails应用程序与MySQL连接起来,这不需要额外的工作。这样做因为本书的例子中使用了MySQL[也就是说,如果你的应用程序要保存大量的产品,你应该使用MySQL,你可能想安装低级别的MySQL界面库,但是它的性能并不总是最好的]如果你已经使用MySQL,在你以商业用途发行你的应用程序之前,记住检查许可证。

如果你安装完了MySQL的话,那么你就做完了所有准备工作。否则,访问http://dev.mysql.com。安装它的说明将MySQL安装到你的机器上。一旦MySQL运行了,你就可以安全地跳到3.6节。

 

如果你读到这里,意味着你想连接到其它的数据库。要做到这点,你必须安装数据库驱动程序。数据库的库由C写成并以源代码形式发布的。如果你想使用源代码来构造个驱动程序,那么要仔细浏览这个驱动程序的web站点。很多时候,你会发现作者一般也发布二进制版本。

如果你没有找到二进制版本,或者你只想用源来编译,你的机器上需要有构造库的开发环境,这意味着你得有C++,你需要gcc等工具。

Under OS X, you’ll need to install the developer tools (they come with the operating system, but aren’t installed by default). Once you’ve done that, you’ll also need to fix a minor problem in the Apple version of Ruby (unless you already installed the fix from Lucas Carlson described in the sidebar on the preceding page). Run the following commands.

dave> # You only need these commands under OS X "Tiger"

dave> sudo gem install fixrbconfig

dave> sudo fixrbconfig

 

-----------------------------------------------------------------------------------------

Databases and This Book

 

All the examples in this book were developed using MySQL (version 4.1.8

or thereabouts). If you want to follow along with our code, it’s probably

simplest if you use MySQL too. If you decide to use something different, it

won’t be a major problem. You’ll just have to make minor adjustments to

the DDL we use to create tables, and you’ll need to use that database’s

syntax for some of the SQL we use in queries. (For example, later in the

book we’ll use the MySQL now( ) function to compare a database column

against the current date and time. Different databases will use a different

name for the now( ) function.)

------------------------------------------------------------------------------------------

 

The following table lists the available database adapters and gives links to their respective home pages.

DB2 http://raa.ruby-lang.org/project/ruby-db2

MySQL http://www.tmtm.org/en/mysql/ruby

Oracle http://rubyforge.org/projects/ruby-oci8

Postgres http://ruby.scripting.ca/postgres/

SQL Server (see note after table)

SQLite http://rubyforge.org/projects/sqlite-ruby

There is a pure-Ruby version of the Postgres adapter available. Download postgres-pr from the Ruby-DBI page at http://rubyforge.org/projects/ruby-dbi.

MySQL and SQLite are also available for download as RubyGems (mysql and sqlite respectively).

Interfacing to SQL Server requires a little effort. The following is based on a note written by Joey Gibson, who wrote the Rails adapter.

Assuming you used the one-click installer to load Ruby onto your system, you already have most of the libraries you need to connect to SQL Server. However, the ADO module is not installed. Follow these steps.

1. Find the directory tree holding your Ruby installation (C:Ruby by default). Below it is the folder Rubylibrubysite_ruby1.8DBD. Inside this folder, create the directory ADO.

2. Wander over to http://ruby-dbi.sourceforge.net and get the latest source distribution of Ruby-DBI.

3. Unzip the DBI distribution into a local folder. Navigate into this folder, and then to the directory srclibdbd_ado. Copy the file ADO.rb from this directory into the ADO directory in the Ruby tree that you created in step 1.

SQL Server adapter 只工作于Windows 系统,因为它依赖于Win32OLE

 

3.5 Keeping Up-to-Date

 

假如你使用RubyGems安装了Rails,保持更新也很容易,输入如下命令:

dave> gem update rails

RubyGems将自动更新你安装的Rails。下一次当你重启应用程序时它将使用最新Rails版本。

 

3.6 Rails and ISPs

 

If you’re looking to put a Rails application online in a shared hosting environment, you’ll need to find a Ruby-savvy ISP. Look for one that supports Ruby, has the Ruby database drivers you need, and offers FastCGI and/or lighttpd support. We’ll have more to say about deploying Rails applications in Chapter 22, Deployment and Scaling, on page 440.

现在们安装完了Rails,我们可使用它了。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值