Fri 20 June, 2008

As Gregg Pollack mentioned a week or so ago, I’ll be keeping a weekly-or-so column about noteworthy changes on edge Rails. This is the first time Living on the Edge (of Rails) is appearing on the official Ruby on Rails weblog, so you’ll have to bear with my short introduction.
Living on the Edge is a weekly column I used to put up on my own blog after some prodding by Gregg Pollack of Rails Envy way back in December of 2007. I used to be a rather active Rails contributor back then so it was a no-brainer. Gregg and Jason were awesome enough to feature it weekly in their podcast.
And now it’s here, so try your best to be a tough crowd so I can tune these blog posts so that they are actually useful to you – when I was blogging these on my tiny personal blog it wasn’t that vital but now the audience is significantly larger. Leave your suggestions and criticisms in the comments – they are greatly appreciated!
Anyway, there’s been a ton of new features, API changes and performance improvements in the past 2 weeks or so since Rails 2.1 was released, so rather than dumping all into one mega-post, I’ve decided to break it into 2 posts for new features/API changes and performance improvements. In this post, I’m gonna talk about some of the new features and API changes.
Minor API changes
Let’s start jump straight in with some minor API changes.
link_to now takes a block
The link_to helper now takes a block argument for those occasions when you have really long hyperlink text with variables in them:
<% link_to(@profile) do %>
<strong><%= @profile.name %></strong> -
<span>Status: <%= @profile.status %></span>
<% end %>
Some people would find it cleaner than:
<%= link_to "<strong>#{@profile.name}</strong> -- <span>Status: #{@profile.status}</span>", @profile %>
Credit goes to Sam Stephenson (of Prototype fame) and DHH for this change.
ActiveRecord::Base#merge_conditions is now part of the public API
Jeremy Kemper has made ActiveRecord::Base#merge_conditions a public method.
This is pretty useful if you have conditions from multiple sources or like to combine any conditions for any reason.
Post.merge_conditions(
{:title => 'Lucky ☆ Star'},
['rating IN (?)', 1..5]
)
=> "(`posts`.`title` = 'Lucky ☆ Star') AND (rating IN (1,2,3,4,5))"
Do note though that this merges with a SQL boolean AND only (no ORs).
Associations now take a :validate option
Association macros now accept a :validate option like so:
class Anime > ActiveRecord::Base
has_many :characters, :validate => true
end
This tells ActiveRecord to validate the characters association when saving your Anime model – just like how :validates_associated works. The default is false, which is the current behavior in Rails 2.1 and earlier, so no need to fret. This works for all the other association macros as well (has_one, belongs_to, has_and_belongs_to_many).
Thumbs up to Jan De Poorter and Pratik Naik for this, which also fixes a nasty bug.
ActiveSupport::StringInquirer and convenience Rails.env.development? methods
David Heinemeier Hansson (henceforth abbreviated as DHH – sorry!) recently added an ActiveSupport::StringInquirer String subclass that allows you to do this:
s = ActiveSupport::StringInquirer.new('awesome')
=> "awesome"
s.awesome?
=> true
s.sucks?
=> false
An immediate use of this is when you are checking the environment your app is running in: Rails.env is wrapped in a StringInquirer so you can use query methods like Rails.env.development? and Rails.env.production?.
Core extensions: Object#present? and Enumerable#many?
DHH also added some core extensions that while trivial, could make your code more readable. First up is Object#present?, which is essentially !Object#blank?
[].present?
=> false
[1, 2].present?
"".present?
=> false
"i'm here".present?
=> true
An Enumerable#many? extension was also added that is simply a boolean test for enumerable.size > 1:
[].many?
=> false
[:just_me].many?
=> false
[:just_me, 'my_friend'].many?
Object#present? changeset – Enumerable#many? changeset
Declarative block syntax for writing tests
DHH was inspired by Jay Fields when he committed this bit of syntatic sugar: you can now write your tests (Test::Unit) in declarative block style like so:
test "an anime should be invalid if any of its characters are invalid" do
# Your usual test code here.
end
I seldom use Test::Unit (except when submitting Rails patches) and prefer RSpec – this declarative style of writing tests is definitely more readable.
All Rails-generated test stubs now use this new syntax.
Performance tests
Jeremy Kemper has been hard at work optimizing and improving the performance of Rails, so it’s no surprise that he has also introduced a new type of integration test: the performance test.
You can use the performance test generator (added by Pratik in 23232a) to generate a performance test stub.
script/generate performance_test LoginStories
Running the performance test requires ruby-prof >= 0.6.1, which is still unreleased but you can get at it the development version by checking out the source and installing the gem yourself (I suggest you get Jeremy’s fork of ruby-prof for now). It’s interesting to note that with the 0.6.1 release, ruby-prof supports profiling tests cases written using Test::Unit.
Moving on… Put in some test code (request a few controller actions – whatever user story you want to test performance of) and run the test. You’ll get output like this (together with the usual ruby-prof profiling output in the test/tmp/performance directory of your Rails app):
> ruby performance/login_stories_test.rb
Loaded suite performance/login_stories_test
Started
LoginStoriesTest#test_homepage (32 ms warmup)
process_time: 11 ms
memory: unsupported
objects: unsupported
.
Finished in 0.870842 seconds.
The memory and objects results are “unsupported” because I haven’t patched my Ruby interpreter for memory profiling support. You’d need certain Ruby interpreter patches to enable memory and GC profiling. I wish I could tell you more about how to do so, but I’m treading unfamiliar ground here. There are some details here on how to patch Ruby for memory profiling. I leave it for wiser folks to explain how to do this :)
Outro
That’s it so far for new feature/API changes in Rails since Rails 2.1 – performance improvements are coming up in the next post and I’ve also intentionally left out mention of the Rack support that has been partially merged into edge.
If there were any errors or you have any suggestions on how to make this column better, please point them out in the comments. Any info on patching your Ruby interpreter for memory profiling support is also greatly welcome. If I’ve left out anything that I’d considered not noteworthy enough but you disagree, let me know in the comments too.
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 furlThu 19 June, 2008

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
There are several Ruby / Rails related conferences coming up in the next few months. Some of these are smaller regional conferences, and some of them are larger conferences which have their own Ruby tracks. If you know of any additional events, please comment and I’ll add them to this list.
July 21-25 – OSCON in Portland, Oregon
This year O’Reilly’s Open Source Convention is sporting a nice looking Ruby Track with several advanced topics. Yup, this is at the Portland Convention Center, same place as Railsconf.
Cost: $1345 (sessions only)
August 1-2 – Ruby Nation in Herndon, VA
A Washington DC Regional area Ruby conference with a great location: right next to the Washington Dulles Airport.
Cost: $175
August 8-9 – Ruby Hoedown in Huntsville, AL
A southeast regional Ruby conference located just down the street from the Space Center (aka Spacecamp).
Cost: $199
August 15-17 – erubycon in Columbus, OH
A conference dedicated to Ruby’s place in the Enterprise, organized by EdgeCase.
Cost: $199
September 4-6 – Lone Star Ruby Conference in Austin, TX
A regional Ruby conference deep in the heart of Texas. They haven’t announced their speakers or opened registration yet, but I’m told they will shortly.
Cost: $250
September 20 – Windy City Rails in Chicago, IL
A day long Rails conference in Chicago covering the freshest topics in the Rails world put together by Chicago Ruby.
Cost: $99
November 17-21 – QCon in San Francisco, CA
InfoQ and Trifork (from JAOO) put together this annual San Francisco conference with a DSLs in Practice and Ruby for the Enterprise track that any Ruby programmer would probably enjoy.
Cost: $1,695 (sessions only)
Also worth mentioning:
- Ruby Fringe is July 18-20, but tickets are no longer available.
- Railsconf Europe is September 2-4 as David announced last week.
- Rubyconf is November 6-8 in Orlando, FL, but rubyconf.org doesn’t have any information about that yet.
- Voices that Matter: Professional Ruby Conference is November 17-20 in Boston, MA. I’m told more details will be revealed next month.
- Merb Camp is hasn’t been officially announced yet, but I hear it might be October 11-12 in San Diego.
- Railscamp #3 is going on this weekend (June 20-22) near Sydney, Australia, and there’s also a Railscamp UK being planned for sometime in August.
- RuPy is this weekend (Saturday, June 21) in Omsk, Russia.
If I’ve missed any conferences, please let me know and I’ll be happy to add them.
add to del.icio.us. look up in del.icio.us.
add to furlWed 18 June, 2008

当意大利顶着世界冠军的头衔来到欧洲杯的赛场,没人会怀疑它会从小组顺利出线,尽管它所在的是所谓的死亡之组,毕竟失去齐达内的法国如同失去了灵魂的人,巴斯腾的荷兰总是给人激情有余、实力不足的感觉,而罗马尼亚,它的辉煌可能还停留在哈吉的年代。
小组赛前两轮,似乎一切一切都在朝着不利于意大利的方向发展。荷兰一下子成熟起来,3:0斩意大利于马下,4:1横扫法国,对世界杯冠亚军的一视同仁让荷兰一下子成了欧洲杯冠军的头号候选。而首轮0:0沉闷战平法国的罗马尼亚,面对意大利的时候,突然被激发出无穷的活力,与意大利打了一场激情四溢的比赛。在这场比赛里,裁判似乎对世界冠军并不友好,上半场让托尼的进球化为乌有,下半场又判给了罗马尼亚一个点球。
意大利是一支奇怪的球队,每当站到悬崖边上,它总能爆发出惊人的能量,82年的足球丑闻和06年的电话门为意大利带回了两座世界杯。这一次,意大利又一次站到悬崖边上。这一次,布冯发挥“失常”了,作为队长的他,扑出了穆图的点球,让意大利保留住出线的最后一线希望。
两轮战罢,没有人看好意大利,有人在替荷兰谋划着败给罗马尼亚,挤掉世界杯冠亚军。
当世界杯冠亚军再次站到一起,早已没有了06年的光环,多少还有一丝的苍凉。毕竟他们为之而战的不再是金杯,而仅仅是一个小组出线名额,甚至胜利者都无法掌控自己的命运。
老天在作弄意大利未果的情况下,于是,选择了作弄法国队。
开赛不久,新一代法国攻击核心——里贝里便在一次拼抢中受伤下场。如果说这只是作弄的序章的话,那么,头两场表现可以用失常形容的皮尔洛开始把这场作弄推向高潮。第25分钟,皮尔洛用他最擅长传球方式,将皮球送到禁区里面那个守门员无法出击而又在后卫身后的位置,托尼恰到好处的挺球,让客串中后卫的阿比达尔只有在背后犯规。点球、红牌!
在AC米兰已将头号点球手位置让给卡卡的皮尔洛,又一次站到了点球面前。事实证明,复活的皮尔洛是无可阻挡的,1:0。如果说还有比被红牌罚下的阿比达尔更郁闷的话,也许就是纳斯里,这个开场替换里贝里出场的法国小将,还没来得及把身体跑热,就因为这次犯规带来的人员调整,被一个中后卫换下。
在这场比赛中,复活的不仅仅是皮尔洛,还有米兰的新后卫赞布罗塔。于是,两个复活之人,开始在法国后防线面前一次次送出威胁球。如果不是德甲今年的头号射手——托尼忘记带来得分能力,也许意大利早早就会大比分领先。与之形成鲜明对比的是,赛场的另一端,法国前锋亨利和本泽马,两个人只留下孤独而无奈的身影。
下半场开始不久,换下9个主力的荷兰队打进罗马尼亚一个球,意大利人看到了出线的曙光。巴里混小子卡萨诺的盘带为意大利队赢得了一个禁区正面的任意球。这时,头号任意球手皮尔洛已经离场。站在任意球面前的是罗马新贵——德罗西,他也是意大利的新10号。当他的重炮轰出,亨利——没能将足球送入意大利球门的法国前锋,无意中用脚尖改变了足球的方向,法国门将回天无力,2:0。
当荷兰队攻入第二球的时候,意大利人开始庆祝了,他们抓住了救命稻草,成功上岸!
add to del.icio.us. look up in del.icio.us.
add to furl
“ Men have become the tools of their tools. ”
Henry David Thoreau
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
I had www.ignitephoenix.com up <strike>for maybe almost a year now</strike> since April of 2007, with nothing more than a plea for someone to step up and basically make it happen. Well, Jeff Moriarty and Roger Williams have taken steps to make Ignite Phoenix a reality.
It looks like it will be happening in August, at the offices of Jobbing.com (they host the monthly Phoenix Social Media Club meeting).
The best place to get info on all the details is www.ignite-phoenix.org
Subscribe to the RSS feed, and follow announcements on Twitter via @ignitephoenix.
What’s needed now are talk proposals. The idea is to have two sets of short talks; short, as in under 10 minutes; short, as in pecha kucha short, as in no time to be bored or boring.
Suitable topics can be almost anything. No sales pitches. But see here for details.
In between the talk sets there will be a break for discussion and socializing.
Learn more about Ignite in general, or see details on Ignite Portland, Ignite Paris, Ignite Boston, and Ignite Seattle
Spread the word, and thinking about what you would talk about if you had five minutes and an audience.
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 17 June, 2008

I received this photo in the mail today along with a puff letter allegedly from the man himself. It was basically, "I'm running for Prez because blah blah blah" and the same old promises he's been making. Though no mention of drilling for oil in our own country or of stemming the tide of the Mexican invasion.
Oh yeah, and a plea for money. He wants as much as he can get, but he's not getting a dime from me. I gave money to the RNC once, and all it seemed to be used for was to ask me for more money. Last year, I gave money to Fred Thompson's campaign, but all I got for that was a lackluster 'campaign' by Thompson until he finally just gave up and went back to the set of 'Law & Order.' I may have given Bush 43 some money back in 2004, but I can't remember.
McCain sucks as a candidate and he would suck as president. But he won't get the chance to prove or disprove that, since he's going to have his lunch eaten in the general election by Jesus Obama. As much as I hate to say it, Jesus Obama is going to win, and win big, in November.
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
This is the first edition of This Week in Rails. As announced by Gregg Pollack a few days ago, this weekly column will cover highlights from the Rails community. My aim is to provide you with a status update as if you’d gone on holidays for a week. I will try to be consistent and publish once a week on Sunday or Monday. Being my first shot, I’ll rely on your feedback to verify that I’m on the right track and that this is useful to you; so please feel free to express your opinion in the comment section below.
With Rails 2.1 out, most developers are looking forward to upgrading their skills (and projects) to the latest release. If you’re one of them, I strongly recommend that you check out the second edition of Carlos Brando’s Ruby on Rails 2.1 – What’s new free e-book, which is available in both English and Portuguese, with an Italian translation currently in the works as well. You can also read Rob Anderton’s excellent overview of Rails 2.1’s improved caching capabilities, as well as its built-in support for memcached.
Last week, Phusion announced the first release candidate of Passenger 2.0 (aka mod_rails). This release introduces support for Rack, opening the door to alternative web frameworks as well. In the same announcement, Ruby Enterprise Edition was formally released. Despite the “Enterprise” label, this is a fully Open Source version of Ruby whose main claim is a reduced memory footprint on Linux and Mac OS X.
Speaking of Enterprise, Dr Nic has released version 1.0.2 of his Composite Primary Keys gem. Starting from version 1.0.0 it finally catches up with Active Record 2.1. Erubis, the fast alternative to ERB, has rolled out support for Rails 2.1 as well, in their 2.6.1 version. A week later, version 2.6.2 was released and it includes support for Ruby 1.9 as well. You can install it by running
gem install erubis or by downloading it from RubyForge.
Last week Ryan Bates put out another two Railscasts. The first is about how to contribute to Rails using Git and is, needless to say, highly recommended. The second one is in regards to substituting pagination with the effect of endless scrolling, like DZone does. As pointed out, there are plugins that do this, but Ryan’s approach builds it from scratch and is definitely worth checking out.
Other interesting articles were: a concise guide to using the Thinking Sphinx plugin (along with the pre-requisite Sphinx primer), Easy and Flexible Breadcrumbs for Rails even though they are clearly not everyone’s cup of tea, and lastly GemPlugins: A Brief Introduction to the Future of Rails Plugins.
In conclusion, two announcements were previously reported in this blog, but they are both worth repeating. The first is the release of Capistrano 2.4 and the second is that registration has opened up for RailsConf Europe 2008. The conference will be held in Berlin, Germany from the 2nd to the 4th of September. By registering before July 15th, you can save up to 150 euros.
That’s it for this week. As you can see there is no shortage of material, given that we’re such an active community. If you’d like to read more updates from the Ruby side of things, please head over to This Week in Ruby.
add to del.icio.us. look up in del.icio.us.
add to furl
“ Benchmarks in mirror may be closer than they appear. ”
Jeremy Kemper
add to del.icio.us. look up in del.icio.us.
add to furlMon 16 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
The first Ignite Phoenix will be held August 12, 2008, at the offices of Jobbing,com, from about 6:00pm toy 9:00pm
See ignite-phoenix.org for details
add to del.icio.us. look up in del.icio.us.
add to furlSun 15 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
“ Prose is architecture, not interior decoration, and the Baroque is over. ”
Ernest Hemingway
add to del.icio.us. look up in del.icio.us.
add to furl
Tip Mammal vertebrae
All mammals have the same number of vertebrae. Humans and giraffes alike.
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
“ There is repetition everywhere, and nothing is found only once in the world. ”
Goethe
add to del.icio.us. look up in del.icio.us.
add to furlSat 14 June, 2008

Crimson and Clover
Tommy James & the Shondells
add to del.icio.us. look up in del.icio.us.
add to furl
“ … and all the while … he’s talking about parentheses, about how a sentence doesn’t really come to life until it encounters a parenthesis (something that changes the trajectory of the sentence (creating a meaning that she understands (as does he, the one who’s talking (without focusing) on and on) partly because what he’s talking about is how he’s talking) without altering its fundamental progress) which gives it a tension and a complexity that more resembles life, or if not life, music. ”
John Haskell, I am not Jackson Pollock
add to del.icio.us. look up in del.icio.us.
add to furl
Capistrano 2.4.0 is now available. Capistrano is the deployment tool of choice for many Rails programmers, but can be used for much more, allowing you to automate remote tasks using a simple task-oriented framework in Ruby.
Install it via RubyGems:
gem install capistrano
You can read the entire release announcement on Jamis Buck’s weblog.
add to del.icio.us. look up in del.icio.us.
add to furlFri 13 June, 2008

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







