jackyrong

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

近日开始读李刚老师的好书 ruby on rails开发实战,相当好的书,笔记之。我没用RAILS 2。0,只是用
rails 1.2.6,就可以开始学习了

1)安装rails 1.2.6
   由于网上一用
gem install rails --remote就会按2。0的版本装,不喜欢之,因此到
网上下载了相关的1。2。6的包安装之
     http://rubyforge.org/frs/?group_id=307 去下载rails (我下载的是1.2.6版本);
http://rubyforge.org/projects/activesupport 去下载activesupport(我下载的是1.4.4版本);
http://rubyforge.org/projects/activerecord/ 去下载activerecord(我下载的是1.15.6版本);
http://rubyforge.org/projects/actionpack 去下载actionpack(我下载的是1.13.6版本);
http://rubyforge.org/projects/actionmailer 去下载actionmailer(我下载的是1.3.6版本);
http://rubyforge.org/projects/aws 去下载actionwebservice(我下载的是1.2.6版本);
http://rubyforge.org/projects/rake 去下载rake(我下载的是0.8.1版本);
以上所有下载文件都包括zip和gem;
 之后安装
    D:\rails>gem install activesupport-1.4.4.gem  (同等效果的D:\rails>gem install activesupport -v 1.4.4)
Successfully installed activesupport, version 1.4.4
Installing ri documentation for activesupport-1.4.4...
Installing RDoc documentation for activesupport-1.4.4...
 
D:\rails>gem install activerecord-1.15.6.gem
Successfully installed activerecord, version 1.15.6
Installing ri documentation for activerecord-1.15.6...
Installing RDoc documentation for activerecord-1.15.6...
 
D:\rails>gem install actionpack-1.13.6.gem
Successfully installed actionpack, version 1.13.6
Installing ri documentation for actionpack-1.13.6...
Installing RDoc documentation for actionpack-1.13.6..
 
D:\rails>gem install actionmailer-1.3.6.gem
Successfully installed actionmailer, version 1.3.6
Installing ri documentation for actionmailer-1.3.6...
Installing RDoc documentation for actionmailer-1.3.6...
 
D:\rails>gem install actionwebservice-1.2.6.gem
Successfully installed actionwebservice, version 1.2.6
Installing ri documentation for actionwebservice-1.2.6...
Installing RDoc documentation for actionwebservice-1.2.6...
 
D:\rails>gem install rake-0.8.1.gem
Successfully installed rake, version 0.8.1
Installing ri documentation for rake-0.8.1...
Installing RDoc documentation for rake-0.8.1...

D:\rails>gem install rails-1.2.6.gem
Successfully installed rails, version 1.2.6

到此安装过程已经结束,可以看看环境:
D:\rails>rails
Usage: D:/rails/ruby/bin/rails /path/to/your/app [options]
Options:
 
运行 rails -v 显示版本号,表示安装成功。

2) 建立应用:rails firstApp
3) 启动服务器,注意要到firstApp目录下,然后用ruby script/server,之后用localhost:3000去看了,改端口的话可以
ruby script/serve -p 3002
4) 改config目录下的database.yml文件,配置成mysql的
  development:
  adapter: mysql
  database: firstApp_development
  username: root
  password: 123456
  port:3306
  host: localhost
5) 生成控制层,模型层
  ruby script\generate scaffold 模型名  (控制器名)
6) 中文问题(我用的是phpmyadmin 2.7,mysql 5,MYSQL5的MY.INI中连接的编码用GBK)
    A 建的表中,比如要显示中文的字段或表,整理用gbk-2312
   B database.yml中,加上编码encoding: utf8
   C 页面的保存,编辑(我用DW 8的)都用UTF8编码,否则页面显示时乱码
   D html页面中,加上
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
   E 在config目录下的applicaion.rb中,加入
   def set_charset
  @headers["Content-Type"] = "text/html; charset=utf-8"
  @response.headers["Content-Type"] = "text/html; charset=utf-8"
  suppress(ActiveRecord::StatementInvalid) do
   ActiveRecord::Base.connection.execute 'SET NAMES utf-8'       
  end
 end 



 

posted on 2008-05-11 12:00  jackyrong的世界  阅读(428)  评论(0编辑  收藏  举报