ActiveRecord and DB Migration Ate My Model Attributes!

So a few days ago we started seeing the following errors on our Jenkins builds (swapped with fictional model and attribute names):

NoMethodError:
  undefined method `attack_power=' for #<Ironman:0x00000008525d20>

attack_power is a new attribute we recently added to the Ironman ActiveRecord model.

I was baffled, as the table column is clearly there but ActiveRecord couldn’t see it.

Read more ...

An Interview with Yukihiro “Matz” Matsumoto

A week ago I went to Shanghai, China to attend and to give a talk at RubyConf China. The day before the conference’s first day a bunch of us were invited to a VIP dinner where we met with Matz and got to play with a device running MRuby. And I heard that earlier on that day Matz was ‘adopted’ by a book publisher to do an interview.

I have found the interview (in Chinese), and found it to be really useful. So I translated it to English. Hope more people will like it. :)

On November 16th, 2012 - a day before RubyConf China, a Chinese book publisher Turing Book has done an interview with Matz on his new book The Future of Computing as well as about a few topics interested to Chinese readers. The interview was conducted by The Future of Computing’s Chinese translator Zi Heng Zhou.

Read more ...

“Become A Better Developer You Can” - Slides of My RubyConf China 2012 Talk

Contrary to what the title of the talk suggests, I am by no means a superstar developer myself. Though I would like to think that I am extremely passionate about what I do, therefore I love to share my thoughts and tips on web development and software engineering.

Below is the version I used for my actual talk:

https://speakerdeck.com/fredwu/2012-become-a-better-developer-you-can

Since I had been preparing for my talk for over a month, I’ve done many revisions to my slides. Here’s an uncut version that contains every single slide since day one:

https://speakerdeck.com/fredwu/2012-uncut-become-a-better-developer-you-can

Hope you will enjoy them! :)

Update: The video of my talk is up! :)

SimpleCov: Test Coverage for Changed Files Only

The other day a colleague asked whether or not it’s possible to have SimpleCov return a group that only contains uncommitted changes.

The answer is yes! After some digging around, we found the following way:

# in spec_helper.rb
SimpleCov.start 'rails' do
  add_group 'Changed' do |source_file|
    `git ls-files --exclude-standard --others \
      && git diff --name-only \
      && git diff --name-only --cached`.split("\n").detect do |filename|
      source_file.filename.ends_with?(filename)
    end
  end
end

Basically use git ls-files --exclude-standard --others for untracked files, git diff --name-only for unstaged files and git diff --name-only --cached for staged files.

Brewing Node.js on OS X without Xcode

If you are like me who has no need for a full Xcode installation just to get the command line tools, chances are you are using one of these: Apple’s Command Line Tools or the osx-gcc-installer.

Recently Node.js has made some changes so that it no longer installs on OS X via homebrew if you don’t have Xcode installed.

If you run brew install nodejs, you will get the following error:

> Error: Failed executing: make install (node.rb:28)

And if you run brew install -v nodejs, you will discover this line:

> xcode-select: Error: No Xcode is selected. Use xcode-select -switch , or see the xcode-select manpage (man xcode-select) for further information.

The fix? It’s actually quite easy, simply do:

sudo xcode-select --switch /usr/bin

And voila! You can now install Node.js just fine. :)

Fix OpenSSL Error on Mountain Lion (and RVM)

Don’t you just hate it when you have a fresh intall of Mountain Lion, RVM and some rubies - then all of a sudden you hit this OpenSSL::SSL::SSLError error message:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

The fix is quite simple actually, all you need to do is to download a CA root certificate:

curl http://curl.haxx.se/ca/cacert.pem -o ~/.rvm/usr/ssl/cert.pem

And that’s it! Enjoy!