Ruby On Rails小记

 

Instant RailsWindows下的独立安装环境,它包括要穿件Rails应用程序的各个组建,安装起来非常简单。首先从http://rubyforge.org/frs/?group_id=904下载最新的版本

 

 

比如,这里下载InstantRails-2.0-win.zip

 

 

一旦把InstantRails解压了,目录如下

 

打开InstantRails.exe便可以去开发Rails应用了。你将看到如下界面

为了创建一个新的application,点击“Apache”右边“I”按钮,选择一个“Rails Application”,然后选择“Manage Rails Applications…

你会看到下面的Rails应用程序的对话框

 

这里你可以启动和停止应用程序,也可以创建一个新的applicatio点击Create New Rails App...

会弹出一个cmd对话框如下

 

在命令行输入rails demo,将会生成一个名为demoapplication,该application的目录位于安装目录的rails_apps目录下

C:/instantrails/InstantRails-2.0-win/rails_apps>rails demo

      create

      create  app/controllers

      create  app/helpers

      create  app/models

      .............................

      create  log/test.log

 

接下来通过脚手架生成代码

C:/instantrails/InstantRails-2.0-win/rails_apps>cd demo

C:/instantrails/InstantRails-2.0-win/rails_apps>ruby script/generate scaffold Person name:string secret:string country:string email:string description:text can_send_email:boolean graduation_year:integer body_temperature:float price:decimal birthday:date favorite_time:time

      exists  app/models/

      exists  app/controllers/

      ................................

      create  app/controllers/people_controller.rb

      create  test/functional/people_controller_test.rb

      create  app/helpers/people_helper.rb

      route  map.resources :people

 

接下来要配置mysql,将mysqlbin目录下的libmySQL.dll文件拷贝至rubybin目录下,这一步不做ruby链接mysql时候会有错误出现。

 

先在mysql下创建demo数据库

然后修改demo/config/database.yml文件如下

# SQLite version 3.x

#   gem install sqlite3-ruby (not necessary on OS X Leopard)

development:

   adapter: mysql

   encoding: utf8

   database: demo

   username: root

   password:

   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: sqlite3

  database: db/test.sqlite3

  timeout: 5000

production:

  adapter: sqlite3

  database: db/production.sqlite3

  timeout: 5000

 

然后再运行rake命令进行数据库的migrate

C:/instantrails/InstantRails-2.0-win/rails_apps/demo>rake db:migrate

(in C:/instantrails/InstantRails-2.0-win/rails_apps/demo)

==1CreatePeople: migrating =================================================

-- create_table(:people)

   -> 0.1880s

== 1 CreatePeople: migrated (0.1880s) =========================================

 

然后启动服务就ok

 

选中demo应用,点击Start with Mongrel启动服务

打开浏览器访问http://localhost:3000/people/new

CRUD和页面都自动生成好了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值