`
fantaxy025025
  • 浏览: 1247844 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

ruby_on_rails_2.3.x_安装_手记

 
阅读更多

周末看书,总想试验一把,可总不能跑到公司去吧~

所以,还得在win下安装一下ruby on rails

基本上按照这个步骤参考为http://rubyonrails.org/download

 

#1 安装ruby

1.8.7

 

#2 安装gem(好像1.9之后不用此步骤了)

1.8.5(公司用的1.3.7)

结果gem的1.8.5版本和rails2.3.8不兼容,下一篇写写gem的事情

 

#3 安装rails

2.3.8

 

D:\>gem install rails -v 2.3.8
Fetching: rake-0.9.2.gem (100%)
Fetching: activesupport-2.3.8.gem (100%)
Fetching: activerecord-2.3.8.gem (100%)
Fetching: rack-1.1.2.gem (100%)
Fetching: actionpack-2.3.8.gem (100%)
Fetching: actionmailer-2.3.8.gem (100%)
Fetching: activeresource-2.3.8.gem (100%)
Fetching: rails-2.3.8.gem (100%)
Successfully installed rake-0.9.2
Successfully installed activesupport-2.3.8
Successfully installed activerecord-2.3.8
Successfully installed rack-1.1.2
Successfully installed actionpack-2.3.8
Successfully installed actionmailer-2.3.8
Successfully installed activeresource-2.3.8
Successfully installed rails-2.3.8
8 gems installed
Installing ri documentation for rake-0.9.2...
Installing ri documentation for activesupport-2.3.8...
Installing ri documentation for activerecord-2.3.8...
Installing ri documentation for rack-1.1.2...
Installing ri documentation for actionpack-2.3.8...
Installing ri documentation for actionmailer-2.3.8...
Installing ri documentation for activeresource-2.3.8...
Installing ri documentation for rails-2.3.8...
Installing RDoc documentation for rake-0.9.2...
Installing RDoc documentation for activesupport-2.3.8...
Installing RDoc documentation for activerecord-2.3.8...
Installing RDoc documentation for rack-1.1.2...
Installing RDoc documentation for actionpack-2.3.8...
Installing RDoc documentation for actionmailer-2.3.8...
Installing RDoc documentation for activeresource-2.3.8...
Installing RDoc documentation for rails-2.3.8...

 

测试安装成功否:

D:\>rails -v
Rails 2.3.8

 

其他的包也大致安装吧。

 

#4 创建一个helloapp

1)装mysql数据库

 

2)生成一个database

mysql> create database hello;

 

3)安装mysql的gem包

D:\>gem install mysql

 

4)生成一个rails app

D:\workruby>rails helloapp
      create
      create  app/controllers
      create  app/helpers
      create  app/models
      create  app/views/layouts
      create  config/environments
      create  config/initializers
      create  config/locales
      create  db
      create  doc
      create  lib
      create  lib/tasks
      create  log
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  script/performance
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/performance
      create  test/unit
      create  vendor
      create  vendor/plugins
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  Rakefile
      create  README
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  config/database.yml
      create  config/routes.rb
      create  config/locales/en.yml
      create  db/seeds.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_rails_defaults.rb
      create  config/initializers/session_store.rb
      create  config/initializers/cookie_verification_secret.rb
      create  config/environment.rb
      create  config/boot.rb
      create  config/environments/production.rb
      create  config/environments/development.rb
      create  config/environments/test.rb
      create  script/about
      create  script/console
      create  script/dbconsole
      create  script/destroy
      create  script/generate
      create  script/runner
      create  script/server
      create  script/plugin
      create  script/performance/benchmarker
      create  script/performance/profiler
      create  test/test_helper.rb
      create  test/performance/browsing_test.rb
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/index.html
      create  public/favicon.ico
      create  public/robots.txt
      create  public/images/rails.png
      create  public/javascripts/prototype.js
      create  public/javascripts/effects.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  doc/README_FOR_APP
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log

 

5)配置rails连接数据库

config/database.yml文件

此处为了简单测试,把test和production都配置成了一个,实际的项目应该分开~

 

development:
  adapter: mysql
  database: hello
  pool: 5
  timeout: 5000
  username: root
  password: fantaxy
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  database: hello
  pool: 5
  timeout: 5000
  username: root
  password:
fantaxy
  host: localhost

production:
  adapter: mysql
  database: hello
  pool: 5
  timeout: 5000
  username: root
  password:
fantaxy
  host: localhost

 

6)写ActionPack

#I 在app/controllers目录下新建一个文件hello_controller.rb

class HelloController < ApplicationController
  def index
    @name = "fantaxy"
    @now = Time.new
  end
end

 

#II 在app/views目录下新建文件夹hello

#III 在app/views/hello下新建一个view文件index.html.erb

<html>
<head>
  <title>hello</title>
</head>

<body>
<p>Hello <%= @name %></p>
<p>It's now <%= @now.to_s(:db) %></p>
</body>
</html>

 

7)启动server

D:\workruby\helloapp>ruby script\server

=> Booting WEBrick
=> Rails 2.3.8 application starting on http://0.0.0.0:3000

 

8)观察结果

浏览器输入:http://localhost:3000

看见rails的欢迎界面。

可以点击 About your application’s environment 连接看下自己主机的环境

如果有错误,看下后台,比如没有安装mysql的gem包等,会有提示

 

浏览器输入:http://localhost:3000/hello

看见结果:

Hello fantaxy

It's now 2011-07-02 22:35:24

 

 

先到此吧。记得找个自己喜欢的ide比较方便。

 

X

X

X

-

X

X

X

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics