中文Ruby On Rails
百度首页 | 百度空间
 
文章列表
 
2007-06-23 21:35
TagLib
看看下面几本书吧!

ruby on rails 实践.pdf
Ruby On Rails(PDF中文版).pdf
 
2007-06-23 21:33
TagLib
经过Step by Step后,可以看到效果了。但是还是比较喜欢Apache,让我们在Apache上开始。


一、安装Ruby、rails、mongrel和Apache2.2
从rubyforge网站下载One-Click Ruby Install,运行安装程序,就安装好了ruby和rubygems。
运行命令:
gem install rails –y
gem install mongrel –y
gem install mongrel_service -y
安装好了rails和mongrel
从Apache网站下载Windows版本的Apache2.2,运行安装程序,就安装好了Apache2.2。
二、把Mongrel作为Services启动
mongrel_rails service::install -N depot -c d:\Rubyproject\depot -p 3000 –e production
-N指明服务名称,-d指明rails应用的目录,-p是mongrel监听的tcp端口,-e是启动模式为生产模式
这样打开控制面版|管理工具|服务,就可以发现增加了一项名为“depot”的服务,就可以通过控制面版来管理服务了。如果需要命令行启动和关闭该服务,那么:
mongrel_rails service::start -N depot
mongrel_rails service::stop -N depot
如果需要从服务中注销该项服务,那么:
mongrel_rails service::remove -N depot
如果需要安装多个mongrel实例,那么可以这样:
mongrel_rails service::install -N depot0 -c d:\Rubyproject\depot -p 3000 –e production
mongrel_rails service::install -N depot1 -c d:\Rubyproject\depot -p 3001 –e production
诸如此类。
三、配置Apache2.2
用编辑工具打开Apache2.2目录下面的conf/httpd.conf,需要取消如下模块的注释:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
如果你希望对页面输出使用压缩,也需要取消如下模块的注释:
LoadModule deflate_module modules/mod_deflate.so
然后按如下内容配置基于HTTP代理的负载均衡:
xml 代码
  1. ProxyRequests Off   
  2. <Proxy balancer://myCluster>  
  3.    BalancerMember http://localhost:3000   
  4.    BalancerMember http://localhost:3001   
  5. >  
  6.   
  7. <VirtualHost *:80>  
  8.    ServerName www.xxx.com   
  9.    DocumentRoot d:/rubyproject/depot/public   
  10.    ProxyPass /images !   
  11.    ProxyPass /stylesheets !   
  12.    ProxyPass /javascripts !   
  13.    ProxyPass / balancer://myCluster/   
  14.    ProxyPassReverse / balancer://myCluster/   
  15.    ProxyPreserveHost on   
  16. >  
myCluster定义了群集中的每个mongrel应用服务器节点。ProxyPass /images !指明该URL开始的请求不代理给Mongrel群集,而由Apache自己处理。重起Apache,然后打开浏览器访问www.xxx.com,检查配置是否正确。
至此,在Windows Server上面一个具备良好稳定性和性能的Ruby on rails生产环境就搭建好了。
对于页面输出,还可以使用mod_deflate进行输出内容压缩,以提高页面下载速度,这个就留给大家自己配置了。
 
2007-06-23 21:26

TagLib

跨越边界: Ruby on Rails 的秘笈是什么?
我们能从 Rails 框架学到的经验
Ruby on Rails 好像一直处于争论的风口浪尖。大多数争论的核心是其所宣称的令人惊异的生产力。 跨越边界 的作者 Bruce Tate 已经开始理解 Rails 并不是一个更好的工具,而是一个不同类型的工具。本文研究了使 Rails 在某个领域如此高效率的折衷和设计决策。然后思索了应该在 Java™ 社区获得更多关注的受 Rails 启发的思想。
http://www-128.ibm.com/developerworks/cn/java/j-cb05096.html.

跨越边界: 在集成框架中进行测试,第 1 部分
在 Ruby on Rails 中进行单元测试
Java ™ 社区在推进自动单元测试方面已经做了一项激动人心的工作。越来越多的开放源码框架支持在构建项目的同时构建自动测试套件。Spring framework、JUnit、TestNG 和其他几个框架的一些或全部灵感都来自自动测试的思想。尽管如此,一些非 Java 语言和框架具有更多的测试动机、更合适的测试工具和更统一的测试视角。通过观察其他框架的测试方式,可以改进 Java 语言中的测试方式,甚至使用更合适的语言来测试 Java 代码。这篇文章是关于在 Ruby on Rails 上进行测试的两篇文章中的第一篇,将介绍 Rails 单元测试的方式。
http://www-128.ibm.com/developerworks/cn/java/j-cb06066.html

跨越边界: 在集成框架中进行测试,第 2 部分
在 Ruby on Rails 中进行单元测试
在由两篇文章组成的这一系列的 第 1 部分 中,介绍了如何用 Ruby on Rails 进行单元测试,并展示了如何利用这种方式的某些方面改进 Java™ 的单元测试。Java 开发人员对更高级测试的选择更加有限。在这篇文章中,将继续研究 Rails,体会用于功能测试和集成测试的集成框架的优势。
http://www-128.ibm.com/developerworks/cn/java/j-cb06206/

 
2007-06-23 21:23
TagLib
有了好的语言,还要好的工具。IDE必不可少。
疯狂的Google+Baidu后,以下两种方案比较好:
1.Eclipse+RadRails(Eclipse+Aptana,应该非常不错,而且,长期java开发者,应该比较快上手)
2.Eclipse+RDT(好像rdt也并入aptana了)

好像rdt也并入aptana了,既然这样,那就选择Eclipse+RadRails吧!

找到了一篇文章,这就开始吧!

RadRails是基于eclipse平台的Ruby on Rails(ROR) IDE. 熟悉eclipse的开发人员很容易使用. 下面简单介绍一下RadRails在WindowsXP下面的安装, 配置.

1. 安装RadRails

1.1 安装JRE, 下载页面http://java.sun.com/javase/downloads/index_jdk5.jsp
1.2 安装Ruby One-Click Installer, 下载页面http://www.ruby-lang.org/en/downloads/
1.3 安装Rails, Windows CMD(开始-->运行-->cmd) 中运行"gem install rails --include-dependencies"
1.4 安装RadRails, 下载页面http://www.aptana.com, 最好下载standalone版本

2. 配置RadRails

配置RadRails应该是最容易出问题的地方,下面将分类说明Ruby,Rails,Rake的配置方法. 本指南中Ruby安装在"D:\ruby", 根据情况修改成个人的Ruby安装目录

2.1 配置Ruby

2.1.1配置Interpreters
打开"Windows-->Preferences", 选择"Ruby-->Installed Interpreters" , 点击"Add"出现的提示框中

代码
  1. //any name you like  
  2. Interpreters Name: Ruby   
  3. Location: D:\ruby\bin\ruby.exe  

2.1.2配置Ri/rdoc
打开"Windows-->Preferences", 选择"Ruby-->Ri/rdoc"

代码
  1. //bin目录下面的rdoc文件,没有扩展名,不是rdoc.bat  
  2. RDoc path: D:\ruby\bin\rdoc  
  3. //bin目录下面的ri文件,没有扩展名,不是ri.bat  
  4. Ri path: D:\ruby\bin\ri  

2.2 配置Rails和Rake
打开"Windows-->Preferences", 选择"Rails-->Configuration"

代码
  1. //bin目录下面的rails文件, 没有扩展名, 不是rails.bat  
  2. Rails Path: D:\ruby\bin\rails  
  3. //bin目录下面的rake文件, 没有扩展名, 不是rake.bat. 如果没有rake文件,运行gem update rake(安装) 或者 gem install rake(升级)   
  4. Rake Path: D:\ruby\bin\rake  
  5. //bin目录下面的mongrel_rails文件, 没有扩展名. 如果没有,运行gem install mongrel 安装  
  6. Mongrel Path: D:\ruby\bin\mongrel_rails  

3. 总结
安转RadRails很简单,但是配置还是很容易出问题, 特别是几个path, 除了ruby.exe有扩展名以外, 其他的都没有扩展名. 初学者很容易出问题, 再次强调一遍。

 
2007-06-23 21:08
新手RoR(Ruby On Rails)十分钟初体验

1、安装Ruby
Windows用户去 http://rubyforge.org/ 的 http://rubyforge.org/projects/rubyinstaller/ 下载 One-Click Installer - Windows 安装即可,最新版1.8.5-21

2、测试是否安装成功
建议一个Test.rb文件,内容如下

  1. hello = "Hello Ruby World."  
  2. puts hello  

在命令行下运行 ruby Test.rb ,注意安装时%RUBY_HOME%\bin已经设置在你的PATH中了,检查一下即可,运行正确的话就会显示
Hello Ruby World.
结果出来

也可以启动FreeRIDE,新建一个文件,保存,按F5就可以运行得到结果了。在FreeRIDE的Edit菜单==>Preferences...==>Debugger/Run的右边,选中Run process in terminal,运行时可以打开新的窗口来查看,默认在FreeRIDE下面显示结果。

3、利用gem安装其它模块
在命令行下运行 gem install rails
安装提示与结果
Install required dependency activesupport? [Yn] y
Install required dependency activerecord? [Yn] y
Install required dependency actionpack? [Yn] y
Install required dependency actionmailer? [Yn] y
Install required dependency actionwebservice? [Yn] y
Successfully installed rails-1.1.6
Successfully installed activesupport-1.3.1
Successfully installed activerecord-1.14.4
Successfully installed actionpack-1.12.5
Successfully installed actionmailer-1.2.5
Successfully installed actionwebservice-1.1.6
Installing ri documentation for activesupport-1.3.1...
Installing ri documentation for activerecord-1.14.4...
Installing ri documentation for actionpack-1.12.5...
Installing ri documentation for actionmailer-1.2.5...
Installing ri documentation for actionwebservice-1.1.6...
Installing RDoc documentation for activesupport-1.3.1...
Installing RDoc documentation for activerecord-1.14.4...
Installing RDoc documentation for actionpack-1.12.5...
Installing RDoc documentation for actionmailer-1.2.5...
Installing RDoc documentation for actionwebservice-1.1.6...

再运行gem list检查一下看是否安装上去了,会有一堆列表显示,新的也在里面,安装前后各gem list一下,就可以对比得到以下结果

4、安装后各模块介绍
actionmailer (1.2.5) 邮件分发与测试模块,类似Java里的JavaMail的东东
actionpack (1.12.5) 类似于Web的MVC中的V与C
actionwebservice (1.1.6) Web Service支持
activerecord (1.14.4) ORM工具,类似Java中的Hibernate之类的
activesupport (1.3.1) Rails框架所依赖的一些基础工具类
rails (1.1.6) Web应用框架Rails包含模板引擎,控制层及ORM

5、默认安装后的模块有
fxri (0.3.3)
    Graphical interface to the RI documentation, with search engine.
fxruby (1.6.1, 1.2.6)
    FXRuby is the Ruby binding to the FOX GUI toolkit.
log4r (1.0.5) 日志库,Java中就象Log4J或Jakarta的Commons-Logging
rake (0.7.1) 类似make的工具,Java中就象Ant或Maven
sources (0.0.1)
    This package provides download sources for remote gem installation
win32-clipboard (0.4.0)
    A package for interacting with the Windows clipboard
win32-dir (0.3.0)
    Extra constants and methods for the Dir class on Windows.
win32-eventlog (0.4.1)
    Interface for the MS Windows Event Log.
win32-file (0.5.2)
    Extra or redefined methods for the File class on Windows.
win32-file-stat (1.2.2)
    A File::Stat class tailored to MS Windows
win32-process (0.4.2)
    Adds fork, wait, wait2, waitpid, waitpid2 and a special kill method
win32-sapi (0.1.3)
    An interface to the MS SAPI (Sound API) library.
win32-sound (0.4.0)
    A package for playing with sound on Windows.
windows-pr (0.5.1)
    Windows functions and constants predefined via Win32API

6、创建Web应用
在命令行下运行 rails rorweb ,会在rorweb目录下创建相应的一堆完整的Web应用的目录结构,然后你应该做的就是写你的程序了。
      create
      create app/controllers
      create app/helpers
      create app/models
      create app/views/layouts
      create config/environments
      create components
      create db
      create doc
      create lib
      create lib/tasks
      create log
      create public/images
      create public/javascripts
      create public/stylesheets
      create script/performance
      create script/process
      create test/fixtures
      create test/functional
      create test/integration
      create test/mocks/development
      create test/mocks/test
      create test/unit
      create vendor
      create vendor/plugins
      create tmp/sessions
      create tmp/sockets
      create tmp/cache
      create Rakefile
      create README
      create app/controllers/application.rb
      create app/helpers/application_helper.rb
      create test/test_helper.rb
      create config/database.yml
      create config/routes.rb
      create public/.htaccess
      create config/boot.rb
      create config/environment.rb
      create config/environments/production.rb
      create config/environments/development.rb
      create config/environments/test.rb
      create script/about
      create script/breakpointer
      create script/console
      create script/destroy
      create script/generate
      create script/performance/benchmarker
      create script/performance/profiler
      create script/process/reaper
      create script/process/spawner
      create script/runner
      create script/server
      create script/plugin
      create public/dispatch.rb
      create public/dispatch.cgi
      create public/dispatch.fcgi
      create public/404.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

7、启动Web应用
进入rorweb目录,运行 ruby script\server 启动之,信息如下
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-11-25 08:47:44] INFO WEBrick 1.3.1
[2006-11-25 08:47:44] INFO ruby 1.8.4 (2006-04-14) [i386-mswin32]
[2006-11-25 08:47:44] INFO WEBrick::HTTPServer#start: pid=2564 port=3000

默认webrick服务器启用了3000端口,访问一下 http://localhost:3000 ,打开后可以看到如下之类的信息。
Welcome aboard
You’re riding the Rails!
About your application’s environment
点击查看:
Ruby version 1.8.4 (i386-mswin32)
RubyGems version 0.9.0
Rails version 1.1.6
Active Record version 1.14.4
Action Pack version 1.12.5
Action Web Service version 1.1.6
Action Mailer version 1.2.5
Active Support version 1.3.1
Application root X:/OpenSource/Ruby/rorweb
Environment development
Database adapter mysql

关于webrick服务器更多的信息可以访问 http://www.webrick.org/

8、写一个HelloRoR的Web程序
打开rorweb\app目录,可以看到四个子目录
controllers
helpers
models
views
一看就知道是什么作用了吧:)

仍在rorweb目录,运行 ruby script\generate controller HelloRoR 可以看到如下的创建信息
      exists app/controllers/
      exists app/helpers/
      create app/views/hello_ro_r
      exists test/functional/
      create app/controllers/hello_ro_r_controller.rb
      create test/functional/hello_ro_r_controller_test.rb
      create app/helpers/hello_ro_r_helper.rb

创建一个app/views/hello_ro_r目录及三个文件

打开 hello_ro_r_controller.rb 进行编辑,增加内容后全部如下:

ruby 代码
  1. class HelloRoRController < ApplicationController   
  2. def index   
  3.    render_text "Hello RoR World"  
  4. end  
  5. def rails   
  6.    render_text "Hello Rails"  
  7. end  
  8. end  

访问 http://localhost:3000/hello_ro_r/ 就可以看到Hello RoR World结果了
访问 http://localhost:3000/hello_ro_r/rails 就可以看到Hello Rails结果了

注意是 hello_ro_r 不是HelloRoR,默认是小写,并写大小写之间用_分隔了,要注意一下,如果要进行对应,就全部小写建立应用,如:
运行 ruby script\generate controller helloror ,这样就是生成 helloror_controller.rb 了,然后访问 http://localhost:3000/helloror/ 了

其它:1.8.4与1.8.5的区别
1.8.4
win32-clipboard (0.4.0)
win32-eventlog (0.4.1)
win32-process (0.4.2)
windows-pr (0.5.1)
1.8.5
win32-clipboard (0.4.1)
win32-eventlog (0.4.2)
win32-process (0.5.1)
windows-pr (0.5.3, 0.5.1)

1.8.5的升级:gem install rails
Bulk updating Gem source index for: http://gems.rubyforge.org
Install required dependency activesupport? [Yn] y
Install required dependency activerecord? [Yn] y
Install required dependency actionpack? [Yn] y
Install required dependency actionmailer? [Yn] y
Install required dependency actionwebservice? [Yn] y
Successfully installed rails-1.1.6
Successfully installed activesupport-1.3.1
Successfully installed activerecord-1.14.4
Successfully installed actionpack-1.12.5
Successfully installed actionmailer-1.2.5
Successfully installed actionwebservice-1.1.6
Installing ri documentation for activesupport-1.3.1...
While generating documentation for activesupport-1.3.1
... MESSAGE:   Unhandled special: Special: type=17, text="<!-- HI -->"
... RDOC args: --ri --op F:/OpenSource/RoR/Ruby/lib/ruby/gems/1.8/doc/activesupport-1.3.1/ri --quiet lib
(continuing with the rest of the installation)
Installing ri documentation for activerecord-1.14.4...
Installing ri documentation for actionpack-1.12.5...
While generating documentation for actionpack-1.12.5
... MESSAGE:   Unhandled special: Special: type=17, text="<!-- The header part of this layout -->"
... RDOC args: --ri --op F:/OpenSource/RoR/Ruby/lib/ruby/gems/1.8/doc/actionpack-1.12.5/ri --quiet lib
(continuing with the rest of the installation)
Installing ri documentation for actionmailer-1.2.5...
Installing ri documentation for actionwebservice-1.1.6...
Installing RDoc documentation for activesupport-1.3.1...
Installing RDoc documentation for activerecord-1.14.4...
Installing RDoc documentation for actionpack-1.12.5...
Installing RDoc documentation for actionmailer-1.2.5...
Installing RDoc documentation for actionwebservice-1.1.6...

9、中文截取问题测试
http://my.opera.com/sawpad/blog/show.dml/235183
从以上地址拿到程序放到 rorweb\lib\ 目录下

它的示例里有问题,我回复了它,可以在程序里调用如下,凑合着用,至少不会乱码:

ruby 代码

  1. u = USCutter.new("GBK")   
  2. u1 = USCutter.new("GBK")   
  3. u2 = USCutter.new("GBK")   
  4. s = "we love 中文截取问题"  
  5. s1 = u.cut(s,0,10)   
  6. s2 = u1.cut(s,0,11)   
  7. s3 = u2.cut(s,0,12)   
  8. puts s1   
  9. puts s2   
  10. puts s3  

记得JavaEye上线时也是乱码问题,现在解决了的,原来我给Robbin写过用JavaScript来解决乱码的问题,不知道Robbin后来如何解决的,搜了一下,没有发现解决方案?

10、接下来就是连接数据库做一个完整的开发之类的,待续。。。

http://taglib.cn
 
2007-06-23 21:01
花了2个小时,找了本Ruby的语法看了一下,习惯了Java和C#的语法,又要重新去接受C的语法,感觉还是很不习惯。而且,Ruby的方法的简写方式,是在难以接受。

疑问:解释型语言,为什么现在这么容易被接受?
 
     
 
 
日历
 
     
 
文章分类
 
 
Ror(6)
 
     
 
文章存档
 
 
     
 
最新评论
   
文章评论|照片评论


现在Netbeans6.0可以用来写ruby
 
     
 
我的搜藏
 
     
 
最近访客
 
 

tzf1943

leapder

wushuihe
     
 
其它
 
已有人次访问本空间
 
订阅RSS  什么是RSS?

您也想拥有这样的空间?请点此申请。
     


©2008 Baidu