﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-&lt;h3 style="font-family: Comic Sans MS"&gt;&lt;font color="#FA1A0A" size="10"&gt;︻┳═一Java&lt;/font&gt;&lt;/h3&gt;-随笔分类-Ruby and Rails</title><link>http://www.blogjava.net/rain1102/category/37656.html</link><description>&lt;br/&gt;&lt;font color="green" style="font-family: 华文行楷;font-size:16px;"&gt;子曰：危邦不入，乱邦不居。天下有道则见，无道则隐。&lt;/font&gt;&lt;font color="#3C1435"&gt;&lt;/font&gt;</description><language>zh-cn</language><lastBuildDate>Sat, 21 Feb 2009 19:05:05 GMT</lastBuildDate><pubDate>Sat, 21 Feb 2009 19:05:05 GMT</pubDate><ttl>60</ttl><item><title>从 Django 看 Ruby on Rails 成功的原因</title><link>http://www.blogjava.net/rain1102/archive/2008/12/04/244362.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Thu, 04 Dec 2008 06:06:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2008/12/04/244362.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/244362.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2008/12/04/244362.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/244362.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/244362.html</trackback:ping><description><![CDATA[<p>这裡有一份对岸 cookoo 写的对Django的遗憾，真是一篇好文章，裡面描写到 Django 如何错失大鸣大放的机会。我看完之后，突然发现 cookoo 这篇文章藉由 Django 的缺点，他也顺便偷偷分析了 Ruby on Rails 成功的原因。大家可以来看看</p>
<p><br />
django的原始码改动频繁<br />
ORM API 繁琐（后来按ActiveRecord风格重写）<br />
没有整合的测试框架<br />
没出书，文件相比Rails缺之甚多<br />
python内部有人对django完全独立的一套full-stack系统有不同看法，又搞了很多别的框架（比如turbogears）<br />
django对AJAX热潮无动於衷<br />
相比起来</p>
<p><br />
Rails Team 相当稳定，很少大改<br />
ORM 太优美了<br />
出的书籍一级棒，文件也相当多<br />
Ruby 因为社群小，超级团结<br />
Full Stack 框架，Unit Test 内建<br />
RJS 赶上 AJAX 热潮，炒热不少话题<br />
虽然 Open Source 技术为本，但是撇开 Ruby on Rails 优秀的技术不谈。</p>
<p>假如大家都不写文件，Ruby on Rails 的文件不够多的话，有人敢用一个不熟悉的语言吗？<br />
没有将 Ruby 社群主力放在 Rails 身上，写得出那麼多 API 吗？<br />
没有团结的团队，人员来来去去，吵来吵去的团队作得出好作品吗？<br />
没有 DHH 肯花写程式以外的时间推销 Rails ，并且花眾多时间写出一本Agile Web Development with Rails，会更多人愿意花时间去学习一个听都没听过，也没有公司support 的 Ruby on Rails 吗？</p>
<p><br />
一向是一盘散沙的 Open Source 社群可以仔细思考一下 Ruby on Rails 带给大家的啟示。Ruby 社群向心力强，不分散力量，又懂得出书以及掌握时势用RJS炒热话题。这说明，团队管理好，向心力强，行销强，正是 Ruby on Rails 扩散那麼快速的主因。其实，这不正是一个好商业团队应该具备的特质吗？ </p><img src ="http://www.blogjava.net/rain1102/aggbug/244362.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2008-12-04 14:06 <a href="http://www.blogjava.net/rain1102/archive/2008/12/04/244362.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Why I moved from Ruby on Rails to Python/Django and back[excerpt]</title><link>http://www.blogjava.net/rain1102/archive/2008/11/21/241807.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Fri, 21 Nov 2008 02:46:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2008/11/21/241807.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/241807.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2008/11/21/241807.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/241807.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/241807.html</trackback:ping><description><![CDATA[<p>Around March of 2006, I decided to proceed with a complete rewrite of <a href="http://ajaxwhois.com/">Ajaxwhois.com</a>. I had been studying Ruby on Rails for long enough and knew it would be the ideal platform to develop with. And I was right. While <a href="http://rubyonrails.org/" target="_blank">Ruby and Rails</a> might be a little awkward at first for the <a title="Java爱好者" href="http://www.blogjava.net/rain1102" >Java</a> or .NET coder in you, it all really makes sense after a little while.</p>
<p>The behind the scene code generation (aka: magic), the lack of a decent IDE, and worse, of a good debugger made my transition to Ruby somewhat difficult and sometimes <strike>confusing</strike> frustrating. I used to live in Visual Studio .NET and breath Intellisense. In fact, I still miss that to this day.</p>
<p>Any newcomer to Rails will quickly discover why it is so talked about. First of all, even though I don&#8217;t consider myself anywhere near a decent Rails programmer, I am now at least twice as productive with Ruby on Rails than with ASP.NET and C#. Thanks to the MVC (Model, View, Controller), DRY (Don&#8217;t Repeat Yourself) and Convention Over Configuration mindset of Rails. All the data access code is automagically generated for you (without running a code generator), templating is built in and creating AJAX&#8217;ed applications is a snap.</p>
<p>Life was good with Rails and the more I used it, the more I liked it. That was until early August of 2006. I was ready to launch version 2.0 of <a href="http://ajaxwhois.com/">Ajaxwhois</a>. Knowing so many professional Rails hackers, I thought deploying my application to my production server was going to be a breeze. I was wrong. Even though the installation of Linux (Ubuntu Dapper Drake 64 bit), Lighttpd, MySql and Mongrel went well, I experienced weird problems, mainly related to Mongrel. Sometimes, my Mongrel instances would simply die and disappear from the process list for no apparent reason. I didn&#8217;t have ANY traffic at this point because I hadn&#8217;t done DNS transfers yet. On other occasions, Mongrel went crazy and started peaking the CPU at 99%. I had to manually kill and restart it.</p>
<p>After extensive research and countless &#8220;from scratch&#8221; reinstalls, I found out that Mongrel was known to not play well with 64 bit Ubuntu (I lost the links to this evidence, unfortunately). Mongrel was patched accordingly, but it didn&#8217;t solve my problem. It still crashed many times a day and I just couldn&#8217;t figure out what was wrong. I asked my good friends <a href="http://blog.richcollins.net/" target="_blank">Rich Collins</a> and <a href="http://loglibrarian.blogspot.com/" target="_blank">Adam Thorsen</a> (of <a href="http://guruza.com/" target="_blank">Guruza.com</a>) who are both experienced Rails developers and they had no idea either. I was stuck.</p>
<p>I wanted to launch. Badly. I didn&#8217;t want to waste anymore time with this so I picked up a Python book and rewrote the whole site one more time, in Python using the Django framework this time. I had never programmed in Python before and much less used Django. However, the switch was easy enough since Ruby and Python are somewhat similar.</p>
<p>My experience with <a href="http://python.org/">Python</a> and <a href="http://www.djangoproject.com/" target="_blank">Django</a> was great; it is a combination every web developer should consider. However, I soon missed <a href="http://ruby-lang.org/" target="_blank">Ruby</a> and Rails. Ruby supports &#8220;real&#8221; private/public/protected methods (Python just fakes that with its naming convention) and it&#8217;s syntax is more forgiving (the need for () at the end of each method call in Python was killing me). Django is not as straightforward as Rails, and requires more code to get things done. There are also many little things that don&#8217;t &#8220;feel right&#8221; in Django, like the need to manually pass variables to a view. Data access is confusing at best while Rails&#8217; ActiveRecord is god-sent. These little things really add up.</p>
<p>On the flip side, <a href="http://www.timestretch.com/FractalBenchmark.html" target="_blank">Python is faster than Ruby</a> and less memory hungry. I was also surprised to actually love Python&#8217;s significant indentation (<a href="http://upload.wikimedia.org/wikipedia/en/thumb/c/c3/Python_add5_syntax.png/292px-Python_add5_syntax.png" target="_blank">see example</a>). But more importantly, Python and Django just worked! I never experienced weird crashes like I did with my Rails stack.</p>
<p>So, why am I back to Rails for my next project? 3 letters: FUN. I find Ruby and Rails to be pleasant to use. The community large, active and very helpful. The number of freely available Rails plugins and the fast evolution of the core code are also welcomed additions. Rails requires less code, less self.__awkward_method_calls(), has built-in AJAX and REST support, and has much more flexible data access and templating engines.</p>
<p>But what about those crashes? What about the speed issue? Well, I don&#8217;t have the crashes anymore. Don&#8217;t ask me why, I don&#8217;t know, but it&#8217;s fine now, I swear! Something somewhere got fixed and it seems to have solved the problem. However, speed is still one of the low points of Rails. Using caching and proper code optimization should take you a long way, though. <a href="http://www.ruby-lang.org/en/about/" target="_blank">Matz</a>, the author of Ruby, is working hard on a new virtual machine that should make Ruby just as fast, if not faster than Python.</p>
<p>My recommendation is, try both for long enough to figure out what works and what doesn&#8217;t for you. If you are a long-time Python user, Django might be more compelling for you, but if you are coming from a <a title="Java爱好者" href="http://www.blogjava.net/rain1102" >Java</a>, Perl or Smalltalk background, Ruby and Rails will most likely be what you&#8217;ll end up using. Either way, I don&#8217;t think you can go wrong.</p>
<p>PS: I don&#8217;t want to blame Mongrel for my Rails problems because I am still not sure who was the guilty party. Mongrel is a wonderful piece of software and I heartily recommend it. Just make sure you watch it closely if you use Ubuntu on a 64 bit machine. </p><img src ="http://www.blogjava.net/rain1102/aggbug/241807.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2008-11-21 10:46 <a href="http://www.blogjava.net/rain1102/archive/2008/11/21/241807.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>系统编程语言和脚本语言</title><link>http://www.blogjava.net/rain1102/archive/2008/06/15/208114.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Sun, 15 Jun 2008 09:41:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2008/06/15/208114.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/208114.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2008/06/15/208114.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/208114.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/208114.html</trackback:ping><description><![CDATA[通常,脚本语言不会替代系统编程语言,他们相互补充(Ousterhout, 1998), 一般来说,<br />
系统编程语言应该用于如下目的:<br />
1.开发复杂的算法或者数据结构<br />
2.实现计算密集型应用<br />
3.操作大型数据集<br />
4.实现良好定义的, 缓慢变更的需求<br />
5.是大型项目的一部分<br />
而脚本语言应该用于如下目的:<br />
1.连接已有的组建<br />
2.处理经常变化的多种类型的实体<br />
3.具有图形化用户界面<br />
4.拥有快速变化的功能<br />
5.是小型或者中型项目的一部分<img src ="http://www.blogjava.net/rain1102/aggbug/208114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2008-06-15 17:41 <a href="http://www.blogjava.net/rain1102/archive/2008/06/15/208114.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习Ruby One</title><link>http://www.blogjava.net/rain1102/archive/2008/04/09/191679.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Wed, 09 Apr 2008 14:05:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2008/04/09/191679.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/191679.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2008/04/09/191679.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/191679.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/191679.html</trackback:ping><description><![CDATA[<p>模块定义：module<br />
类定义：class<br />
方法定义：def, undef<br />
检查类型：defined?<br />
条件语句：if, then, else, elsif, case, when, unless<br />
循环语句：for, in, while, until, next, break, do, redo, retry, yield<br />
逻辑判断：not, and, or<br />
逻辑值和空值：true, false, nil<br />
异常处理：rescue, ensure<br />
对象引用：super, self<br />
块的起始：begin/end<br />
嵌入模块：BEGIN, END (require, include)<br />
文件相关：__FILE__, __LINE__<br />
方法返回：return<br />
别名：alias</p>
<p>局部变量，方法参数和方法名称应该用一个小写字母开头或者用一个下划线开头;<br />
全局变量用美元符作为前缀$;<br />
实例变量使用@开头；<br />
类变量用@@<br />
类名，模块名和常量应该用大写字母开头</p>
<p>Ruby程序代码现在用7位的ACSII码来表示，通过语言扩展来支持EUC，SJIS或UTF-8等8位编码系统。Ruby2.0版本将支持16位的Unicode编码</p>
<p>puts print gets<br />
printf "Number: %4.3f, String:%s", 7.8, "hi!"</p>
<p>数据类型：数字，字符串，数组，哈希表，区间，正则表达式<br />
1..5&nbsp; ---&gt; 1,2,3,4,5;<br />
1...5 ---&gt; 1,2,3,4</p>
<p>a=1; b=1.0; a==b #true&nbsp;比较两个对象的值是否相等<br />
a=1; b=1.0; a.eql?(b) #false 比较两个对象的值以及类型是否相等<br />
a=1.0; b=1.0; a.equal?(b) #false 比较两个对象在内存中的地址是否相同<br />
a=1.0; b=a; a.equal?(b) #true<br />
&lt;=&gt; 比较两个对象的大小，大于，等于，小于 分别返回1，0，－1<br />
===右边的对象是否在左边区间之内，返回true和false<br />
puts (0..9) === 3.14 #true<br />
puts ('a'..'f')==='c' #true<br />
=~用来比较是否符合一个正则表达式，返回模式在字符串中被匹配到的位置，否则返回nil<br />
!~断言不符合一个正则表达式，返回true，false</p>
<p>break,跳出当层循环<br />
next,忽略本次的循环的剩下部分，开始下一次的循环<br />
redo,重新开始循环，还是从这一次开始<br />
retry，重头开始这个循环体</p>
<p>times,upto,downto,each.step<br />
3.times{print 'Hi'} #HiHiHi<br />
1.upto(9) {|i| print i if i&lt;7} #123456<br />
9.downto(1){|i| print i if i&lt;7} #654321<br />
(1..9).each{|i| print i if i&lt;7} #123456<br />
0.step(11, 3){|i| print i} #0369</p>
<p>异常处理begin/end...rescue...ensure...raise&nbsp; retry可以用在rescue中</p>
<p>attr_writer:motherland<br />
相当于<br />
def motherland=(value)<br />
&nbsp;&nbsp;&nbsp; return @motherland = value<br />
end</p>
<p>attr_reader:motherland<br />
相当于<br />
def motherland<br />
&nbsp;&nbsp;&nbsp; return @motherland<br />
end</p>
<p>attr_accessor:motherland 相当于 attr_reader:motherland; attr_writer:motherland</p><img src ="http://www.blogjava.net/rain1102/aggbug/191679.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2008-04-09 22:05 <a href="http://www.blogjava.net/rain1102/archive/2008/04/09/191679.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>活动脚手架功能列表</title><link>http://www.blogjava.net/rain1102/archive/2008/04/08/191475.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Tue, 08 Apr 2008 06:02:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2008/04/08/191475.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/191475.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2008/04/08/191475.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/191475.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/191475.html</trackback:ping><description><![CDATA[活动脚手架参考了Rails自带的脚手架（Scaffold）功能，提供了一个更丰富的通用模式，除了CRUD，还有排序、搜索、分页等等许多功能。这里是一个<a title="功能列表" href="http://activescaffold.com.cn/tutorials/features/" target="_blank">功能列表</a>。<br />
<ul>
    <li>AJAX化的表格界面，可以创建、修改、查看并删除对象。
    <li>自动处理ActiveRecord关联的编辑
    <li>排序、搜索和分页
    <li>支持RESTful <span class="caps">API</span>（包括XML/YAML/JSON）
    <li>支持换肤
    <li>支持扩展
    <li>支持多种浏览器，在Firefox 1+，<span class="caps">IE 6</span>+和Safari 2+通过验证
    <li>与Rails一样遵循<span class="caps">MIT协议</span> License，你可以在你的商业应用中自由使用它 </li>
</ul><img src ="http://www.blogjava.net/rain1102/aggbug/191475.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2008-04-08 14:02 <a href="http://www.blogjava.net/rain1102/archive/2008/04/08/191475.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ruby on Rails 安装手记</title><link>http://www.blogjava.net/rain1102/archive/2008/03/25/188591.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Tue, 25 Mar 2008 13:42:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2008/03/25/188591.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/188591.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2008/03/25/188591.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/188591.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/188591.html</trackback:ping><description><![CDATA[安装Ruby：<br />
&nbsp;&nbsp;&nbsp; 从 <a href="http://www.ruby-lang.org/en/">http://www.ruby-lang.org/en/</a>&nbsp; 下载 ruby186-26.exe，安装Ruby。<br />
&nbsp;&nbsp;&nbsp; 添加环境变量 ruby186-26\bin 到 path<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; 运行 ruby -v 显示版本号，表示安装成功。<br />
<br />
安装Rails：<br />
&nbsp;&nbsp;&nbsp; (1) 远程安装：<br />
&nbsp;&nbsp;&nbsp; 运行 gem install rails --include-dependencies，安装Rails（需要连接网络）。<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; (2) 本地安装：<br />
&nbsp;&nbsp;&nbsp; 从 <a href="http://www.rubyonrails.org/">http://www.rubyonrails.org/</a>&nbsp; 下载 rails-2.0.2.gem，安装Rails。<br />
&nbsp;&nbsp;&nbsp; 运行 gem install rails-2.0.2.gem<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;运行 rails -v 显示版本号，表示安装成功。<br />
<br />
使用：<br />
&nbsp;&nbsp;&nbsp; 运行 rails path/to/your/new/application 创建一个新的项目。<br />
&nbsp;&nbsp;&nbsp; 运行 ruby path/to/your/new/application/script/server 启动服务。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;查看<a href="http://localhost:3000">http://localhost:3000</a>成功<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp; 手工安装非常麻烦，可以从 <a href="http://instantrails.rubyforge.org/">http://instantrails.rubyforge.org/</a>&nbsp; 下载InstantRails，全部搞定。<br />
<br />
<br />
相关目录和路径如下：<br />
<a href="http://rubyforge.org/frs/?group_id=307">http://rubyforge.org/frs/?group_id=307</a> &nbsp;去下载rails <br />
<a href="http://rubyforge.org/projects/activesupport">http://rubyforge.org/projects/activesupport</a> 去下载activesupport <br />
<a href="http://rubyforge.org/projects/activerecord/">http://rubyforge.org/projects/activerecord/</a> &nbsp;去下载activerecord <br />
<a href="http://rubyforge.org/projects/actionpack">http://rubyforge.org/projects/actionpack</a> 去下载actionpack <br />
<a href="http://rubyforge.org/projects/actionmailer">http://rubyforge.org/projects/actionmailer</a> &nbsp;去下载actionmailer <br />
<a href="http://rubyforge.org/projects/aws">http://rubyforge.org/projects/aws</a> &nbsp;去下载actionwebservice <br />
<a href="http://rubyforge.org/projects/rake">http://rubyforge.org/projects/rake</a> &nbsp;去下载rake <br />
<br />
如果是升级，记得最后执行 gem cleanup把原来的老版本清除。<br /><img src ="http://www.blogjava.net/rain1102/aggbug/188591.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2008-03-25 21:42 <a href="http://www.blogjava.net/rain1102/archive/2008/03/25/188591.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RoR中的分页</title><link>http://www.blogjava.net/rain1102/archive/2007/01/15/93996.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Mon, 15 Jan 2007 09:22:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2007/01/15/93996.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/93996.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2007/01/15/93996.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/93996.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/93996.html</trackback:ping><description><![CDATA[控制层的实现：<br /><br />　　在控制层，分页必须按如下代码实现：<br /><br /><table style="WIDTH: 451px; HEIGHT: 86px" bordercolor="#cccccc" width="451" align="center" bgcolor="#e7e9e9" border="1"><tbody><tr><td>def user_list <br />@user_pages, @users = paginate(:users, :order_by =＞ 'name')<br />end </td></tr></tbody></table><br />　　以上代码通过paginate方法设置的分页器。这个方法有两个参数，第一个参数是要读取数据的表的名子，第二个参数是在取数据时要排序的字段。这个方法返回两个对象，第一个对象@user_pages是分页器对象， 第二个对象 @users 是每一页的记录数。其中@users用来向视图提供要显示的数据。 而@user_pages负责从表中得到数据，然后将这些数据保存在@users中。<br /><br />　　视图层的实现:<br /><br />　　在视图层的RHTML文件中，@users中的数据将被展现给用户。pagination_links()方法可以实现导航的功能。以下是具体的实现代码：<br /><br /><table style="WIDTH: 447px; HEIGHT: 181px" bordercolor="#cccccc" width="447" align="center" bgcolor="#e7e9e9" border="1"><tbody><tr><td>＜table＞ <br />＜tr＞＜th＞姓名＜/th＞＜/tr＞ <br />＜% for user in @users %＞ <br />＜tr＞＜td＞＜%= user.name %＞＜/td＞ <br />＜% end %＞ <br />＜/table＞ <br />＜hr＞ <br />＜%= pagination_links(@user_pages) %＞ <br />＜hr＞ </td></tr></tbody></table><img src ="http://www.blogjava.net/rain1102/aggbug/93996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2007-01-15 17:22 <a href="http://www.blogjava.net/rain1102/archive/2007/01/15/93996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ruby和Rails的一些好网站</title><link>http://www.blogjava.net/rain1102/archive/2006/12/31/91152.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Sun, 31 Dec 2006 06:22:00 GMT</pubDate><guid>http://www.blogjava.net/rain1102/archive/2006/12/31/91152.html</guid><wfw:comment>http://www.blogjava.net/rain1102/comments/91152.html</wfw:comment><comments>http://www.blogjava.net/rain1102/archive/2006/12/31/91152.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rain1102/comments/commentRss/91152.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rain1102/services/trackbacks/91152.html</trackback:ping><description><![CDATA[<p>需要用到的一些书<br />The Ruby Way <br />Programming Ruby 2nd edition <br />Agile Web Development with Rails <br />Best of Ruby Quiz <br />Rails Recipes <br />Enterprise Integration with Ruby <br />Ruby Hacking Guide <br />Ruby In A Nutshell </p>
		<p>
				<a href="http://www.itpub.net/forum61.html">http://www.itpub.net/forum61.html</a>
				<br />里大多有下，重点推荐<br />Programming Ruby 2nd edition <br />Agile Web Development with Rails </p>
		<p>
				<br />一些不错的论坛 及网站<br />国内的<br /><a href="http://railscn.crispynews.com/">http://railscn.crispynews.com/</a><br /><a href="http://www.railscn.com">http://www.railscn.com</a><br /><a href="http://chinaonrails.com">http://chinaonrails.com</a><br /><a href="http://r4rclub.schtuff.com/">http://r4rclub.schtuff.com/</a><br /><a href="http://forum.javaeye.com">http://forum.javaeye.com</a><br /><a href="http://rorwiki.hellopen.net">http://rorwiki.hellopen.net</a></p>
		<p>国外的<br /><a href="http://www.ruby-forum.com/">http://www.ruby-forum.com/</a><br /><a href="http://www.rubyonrailsforum.com/rails-code-questions/">http://www.rubyonrailsforum.com/rails-code-questions/</a><br /><a href="http://rubyforge.org/">http://rubyforge.org/</a><br /><a href="http://www.rubyonrails.org/">http://www.rubyonrails.org/</a><br /><a href="http://www.ruby-lang.org/en/">http://www.ruby-lang.org/en/</a><br /><a href="http://www.webrick.org/">http://www.webrick.org/</a><br /><a href="http://www.yaml.org/">http://www.yaml.org/</a></p>
		<p>blog</p>
		<p>&lt;博客&gt; <br />铁道播客：有诸多视频教程 <br /><a href="http://rorcast.blogger2blogger.com/">http://rorcast.blogger2blogger.com/</a></p>
		<p>my4java的文字博客：有很多教程的译稿、笔记等 <br /><a href="http://my4java.itpub.net/">http://my4java.itpub.net/</a></p>
		<p>cnruby道喜技术日记：众多实例教程 <br /><a href="http://www.hhtong.com/blog1/">http://www.hhtong.com/blog1/</a></p>
		<p>caphe的博客 <br /><a href="/cap">http://www.blogjava.net/cap</a></p>
		<p>Caiwangqin的博客 <br /><a href="http://www.uuzone.com/blog/uu_1115110/">http://www.uuzone.com/blog/uu_1115110/</a></p>
		<p>中文RubyOnRailsWiki<br /><a href="http://rorwiki.hellopen.net/index.p...%A6%96%E9%A1%B5">http://rorwiki.hellopen.net/index.p...%A6%96%E9%A1%B5</a></p>
		<p>关于rails和ajax相结合<br /><a href="http://www.rubynoob.com/">http://www.rubynoob.com/</a></p>
		<p>
				<a href="http://inquirylabs.com/blog/">http://inquirylabs.com/blog/</a>
		</p>
		<p>这个当中有一些介绍<br /><a href="http://www.railscn.com/about704.html">http://www.railscn.com/about704.html</a></p><img src ="http://www.blogjava.net/rain1102/aggbug/91152.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rain1102/" target="_blank">Eric.Zhou</a> 2006-12-31 14:22 <a href="http://www.blogjava.net/rain1102/archive/2006/12/31/91152.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>