
I’ve seen that face before…
Today I attempted to upgrade a Rails app from 2.3.5 to 3.0.beta. I assumed this might be a monumental undertaking, and was prepared to cut things short if needed.
The bad news is that I did stop half way through, and have reverted to 2.3.5. The good news is the basic upgrade path was easier than I expected.
There’s now an official upgrade plugin which you can install into your existing Rails 2.x app that provides a number of rake tasks that help you determine what’s going to change, and provide code so you can make it happen:
http://github.com/rails/rails_upgrade
Jeremy McAnally, the creator of the plugin, also has a nice tutorial on getting Rails 3 beta installed on your system:
http://omgbloglol.com/post/371893012/the-path-to-rails-3-greenfielding-new-apps-with-the
Once Rails 3 is on your system, and you’re ready for the upgrade, it’s as simple as doing
$ cd myapp
$ rails .
After updating all my config files with proper database settings and the like, I fired up the server and found to my delight that everything seemed to work, including my Metal classes.
I then moved on to getting my RSpec testing suite working, and that’s when I ran into problems. After tinkering around for a while attempting to install the alpha of RSpec 2, I realized that rspec and rspec-rails are a bit far off from being ready for Rails 3. Since testing is intregal to my development, it was a no go for an upgrade. :(
So it seems that once the community has time to update gems and plugins for Rails 3, things will be looking good. Personally, I can’t wait to take advantage of all the Rails 3 has to offer.
A while ago I had come across the following cool tip and graphic on how to recover a combination for a Master Lock padlock you’ve forgotten.
The technique is a little algorithm that exploits a mechanical weakness in the lock to narrow down the last digit in the combination. You then use what is basically a lookup table to run through the possible combinations till you open the lock.
So last night, I found myself in need of a padlock and managed to scrounge up an old Master Lock. And of course I had no recollection of the combo. So I pulled up the instructions online and presto… 15 minutes later, I had myself a working padlock.
You gotta love it when a little algorithm like that can so easily solve what seems like an insurmountable problem.
In Ruby, you check with
nil?if an object is nil:article = nil article.nil? # => true
empty?checks if an element - like a string or an array f.e. - is empty:# Array [].empty? #=> true # String "".empty? #=> trueRails adds the method
blank?to theObjectclass:An object is blank if it‘s false, empty, or a whitespace string. For example, “”, ” “, nil, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?to
if !address.blank?
As of Rails 2.3, there’s also a handy new try() method on objects, which allows you to invoke a method on a possibly nil object without throwing a NoMethodError. This saves you the trouble of checking if your object is nil or not before accessing a method.
For example, previously you’d need to do something like
article = Article.find_by_title("My Article")
unless article.nil?
article.body
end
With try() you can skip the nil? check and do the following
Article.find_by_title("My Article").try(:body) => #body or nil
Here’s an interesting post by Google on their problems in China, alluding to the possibility that they might close down Google.cn
http://googleblog.blogspot.com/2010/01/new-approach-to-china.html
Personally I’m not surprised. I’ve been firewalling all the servers I administer from all netblocks in China for a while now. If you’re not doing business in China, my advice is to do the same. Along with blocking netblocks in Eastern Europe, you’ll see a huge decrease in the number of malicious scripts and automated exploit attempts against your server, which has the nice side effect of lowering you bandwith and slimming down your log files. Here’s a convenient list of Chinese netblocks in CIDR format which you can add to your iptables.
http://www.okean.com/chinacidr.txt
It feels to me like were are on the cusp of some serious global cyberwars. If we want to maintain an open and safe Internet, it’s going to fall on us, as responsible developers and IT people, to talk openly about what we are seeing and dealing with.
So hats off to Google for being frank and open about their security compromises.
Thought I’d post my new Ruby on Rails plugin here if it’s of interest to anyone. The plugin provides mixin conversation functionality. It’s ultra simple at the moment, and simply allows you to setup a conversation between two objects, and then send messages between those objects in the context of a conversation.
Please feel free to fork and ping me if anyone finds it of interest or has thoughts on additionally functionality.
Here it is: