Thu 22 January, 2009

add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furlWed 21 January, 2009

“ If the world was perfect, it wouldn’t be. ”
Yogi Berra
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furlTue 20 January, 2009

add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furlMon 19 January, 2009

早在2003年,我就厌倦了出差。在客户现场工作,我也不喜欢。
但是,既来之则安之。
每个公司都有属于自己的特点,这些特点从外面看起来是一个样子,在里面看起来却是别有洞天。外面的样子一般是公司刻意打造的形像和大众的评论,这些信息很容易得到,而内部的样子,只有在公司内部的工作一段相对较长的时间才能看得到。我只在两个公司工作过,即便算上在曾经的内部跳动,我也不过在三个地方工作过,所以,只看到很少公司内部的样子。
这次的咨询工作让我在客户公司已经工作了一个半月,不算短的一段时间。每天和客户不同绝色的人打着交道,像客户的员工一样每天上班、工作和下班。这也给了我一个机会看到了客户公司内部的样子。尽管客户花钱是希望从我们这里获得一些东西,但这丝毫不妨碍我从他们身上去学习。在这里,我可以看到许多ThoughtWorks也不俱备的优点,也许,以后回了公司可以分享给大家。
虽然我们不是客户的员工,但每天的朝夕相处还是让我们有机会和客户的员工结下私交:有人为我们节假日出游提供建议,有人带着我们到处转转,有人在我们三缺一的时侯,大老远打车来凑手,还有一些从其它城市出差至此的人邀请我们到他们的地盘上。
时值年关,我们几个在外出差的同事没有机会参加公司的年会,于是,顺便参加了客户的年会。我第一次见识到这么有气势的年会,也见到了那些平时闷闷的程序员们是多么的有才。公司的年会之外,我们还顺便去蹭了一个部门的年会,其目的是为了看看平时和我们一起工作的兄弟到底有多少演艺才华。
这次出差已经打破了我一次性出差的最长纪录,而且,还在继续中,好在还有一些乐趣。
add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- 下面第一段代码使用了变量“i”。在Ruby代码中,基本上不需要使用这种变量,即使需要也可以使用“each_with_index”。而第一段代码连这种需要也没有。
- 下面第二段代码是使用方法“<<”改进后代码清单。注意使用这种方法时,一定要清楚方法“<<”之后的对象是什么。在Rails 2.2.2版本中因为使用此方法不当,产生了错误。参见: Rails2.2世界:国际化功能问与答(二) 。
add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- Rails命令script/runner可以执行Rails软件Ruby文件或者Ruby代码。
- 结合工具 crontab 可以实现Rails项目的定时任务的执行。
- 参考资料
- Automation With Rails script/runner http://tinyurl.com/99unbm
- Hidden in plain sight: script/runner http://tinyurl.com/ax4kv7
- Running one migration by hand http://tinyurl.com/a3ocsb
add to del.icio.us. look up in del.icio.us.
add to furlSat 17 January, 2009


- 说明
- 代码(一)是通过Rails命令scaffold自动生成代码,其中有一行代码“redirect_to @container”。这一行代码返回到页面,而不能够返回到该页面的某一个标签位置,如上图所示类似页面。如何办?
- 代码(二)中代码“redirect_to container_path(@container, :anchor => “tabs-3”) ”就是解决这个问题的办法。
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- adva cms 是基于Rails框架的开发平台。
- adva cms 最大的特点是所有插件和引擎都存储于目录vendor下,与用户软件彻底分离。
add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- 很多人喜欢使用函数puts,获取调试信息。这个问题类似于Java语言人们使用System.out.println(),获取输出内容。一旦使用了函数puts,无法保证网络服务器对于源代码输出信息的顺序!参见上图作了标记的两行输出记录。尽管在上面代码中,函数puts和logger.info是一前一后,但是输出信息的顺序与代码的顺序是不同的。
- 建议放弃使用函数puts,获取输出信息的方法。
- Rails框架已经集成了logger软件包!
- 什么是logger? What is logger?
add to del.icio.us. look up in del.icio.us.
add to furl
MountainWest RubyConf is on March 13-14, 2009 in Salt Lake City, UT and costs just $100.
That’s right, perhaps the most kick-ass RubyConf of the year cost only one. Hundred. Dollars.
BTW, I’ll be speaking at the conference.
See the list of speakers here
add to del.icio.us. look up in del.icio.us.
add to furl
January 10, 2009 -January 16, 2009
24 commits for edge Rails this week (with one patch ported over to the 2.2 branch as well). If you want a pre-release look at Rails 2.3, this is a fine time to install a copy of edge, if you’re not already there. It’s plenty stable enough for test sites, though there are a few rough patches yet.
Nested Transactions in Active Record
Several people contributed to a big patch that gives us nested transactions in Active Record, a much-requested feature. Now you can write code like this:
User.transaction do
User.create(:username => 'Admin')
User.transaction(:requires_new => true) do
User.create(:username => 'Regular')
raise ActiveRecord::Rollback
end
end
User.find(:all) # => Returns only Admin
Nested transactions let you rollback an inner transaction without affecting the state of the outer transaction. If you want a transaction to be nested, you must explicitly add the :requires_new option; otherwise, a nested transaction simply becomes part of the parent transaction (as it does currently on Rails 2.2). Under the covers, nested transactions are using savepoints, so they’re supported even on databases that don’t have true nested transactions. There is also a bit of magic going on to make these transactions play well with transactional fixtures during testing. commit
MemCacheStore Enhancements
Nahum Wild contributed some work that (inspired by his spandex_mem_cache_store plugin) that enhances the performance of Rails when using MemCacheStore. The basic idea is to keep a per-request local cache of requests sent to MemCacheStore, cutting down on unnecessary reads and leading to better site performance. commit
Making Active Record Callbacks behave
You may recall the spot in the Active Record documentation that says “If a before_* callback returns false, all the later callbacks and the associated action are cancelled.” What you may not know is that this is actually broken in the current version of Rails: if you cancel a before_update or before_create callback, the after_save callbacks still run. In Rails 2.3, this will behave the way that the documentation says it does. commit
Fractional seconds for TimeWithZone
The Time and TimeWithZone classes include an xmlschema method to return the time in an XML-friendly string. As of this week, TimeWithZone supports the same argument for specifying the number of digits in the fractional second part of the returned string that Time does:
>> Time.zone.now.xmlschema(6)
=> "2009-01-16T13:00:06.13653Z"
JSON Key Quoting
If you look up the spec on the “json.org” site, you’ll discover that all keys in a JSON structure must be strings, and they must be quoted with double quotes. As of this week, Rails does the right thing here, even with numeric keys. commit
Test Refactoring
Josh Peek spent some time refactoring various tests inside of Action Pack, including those for query string parsing, JSON parameter parsing, XML parameter parsing, multipart parameter parsing, and URL-encoded parameter parsing. While you won’t see any new functionality as a result of this work, it’s worth shining a spotlight on the often-thankless cleanup that keeps the Rails code in good shape.
Changes to Object#try
After some discussion, the semantics of Object#try have changed slightly: it now raises NoMethodError on private methods and always returns nil if the object is nil. commit
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furlFri 16 January, 2009


- 说明:Google Quick Search Box
- 与Mac OS X软件Spotlight类似的搜索工具
- Google Quick Search Box不仅仅搜索本地信息,而且也可以搜索网络信息。
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
With the recent revitalization of the Rails Wiki project, we’re seeing people ask how the various pieces of Rails documentation fit together. I thought it might be useful to lay out how the Rails Activists see everything fitting together as we move forward.
Rails is a large and mature framework, with a lot of functionality – and with the Merb merger, there will be even more to learn in the future. As such, it presents challenges for developers at all levels trying to understand how to use Rails effectively. There are many resources to help with the learning process, including commercial books and magazines, screencasts and podcasts, tutorials, blog entries, and training courses. But there is also a series of official written documentation projects.
There’s no such thing as one-size-fits-all documentation. Different developers bring different skill sets, backgrounds, and levels of professional maturity to learning Rails. There are at least four levels of official documentation, overlapping but serving different needs:
- Inline documentation, with comments within the code itself (that you can see by running
rake doc:railswithin any Rails project). - Rails Guides
- Rails Book (a new project for Rails 3.0)
- Rails wiki
Although at first glance there appears to be substantial overlap, our feeling is that the each of these projects occupies a distinct (and valuable) niche.
RDoc
- Provides immediate help for syntax questions
- Maintained by the actual core developers and generally up-to-date
Rails Guides:
- Provides focused “how to” help for particular problem domains
- Target the mid-level developer, possibly with Rails experience
- Have a large amount of existing high-quality material
- Are already being continuously revised to track changes in edge Rails
- Can include version-specific tutorial code samples
- Can be delivered as a part of core Rails to provide “guidance at your fingertips” for new developers
Rails Book:
- Provides high-level architectural guidance and overview of how the pieces fit together
- Digs into the philosophy of the “Rails Ways”, so readers can understand why the framework works the way it does
- Targets the developer new to Rails or those wanting to go from the “trees” to the “forest” view
- Offers help in conceptualizing Rails and choosing between alternative modules (ORMs, routing DSLs, etc.) in the Rails 3 timeframe
- Can draw on the Merb experience in simultaneous translation and pulling in contributions from many writers
- Largely version independent
- Gives a structured path through end-to-end documentation in a way that standalone Guides do not
Rails Wiki
- Community-driven documentation that can respond rapidly to new software and new questions
- A good repository to links to external information
- Potentially a showcase for Rails itself in the underlying software
- A place to put the accumulated community knowledge, even the pieces that are not often needed
It’s important to note that we don’t see these four projects as entirely separate efforts that have no interaction with one another. In particular, it seems likely that the Book will link to the Guides for those seeking additional detail, while the Guides will link to the Book for those seeking additional high-level guidance. We also anticipate that the wiki will point readers to both Guides and Book (as well as to other sources of information).
So, what can you do to get involved? If you’re a writer, translator, or editor, any of these documentation projects would love to have your help:
- To contribute to the RDoc, write a Rails patch with good comments or check out the docrails project.
- To help the Rails Guides, get in touch with Pratik Naik or Mike Gunderloy, or drop by the #docrails channel on IRC freenode.
- To get involved with the Rails Book, contact Matt Aimonetti.
- To add to the Rails Wiki, join the rubyonrails-wiki group.
add to del.icio.us. look up in del.icio.us.
add to furlThu 15 January, 2009

add to del.icio.us. look up in del.icio.us.
add to furl
