Recently in Ruby on Rails Category

One fine evening I was sitting in a Taiwanese café sipping some slightly too sweet tea. While I waited for my bite sized morsels of fried chicken to emerge from their sizzling oil bath, I decided to hack a bit in Ruby.

I could not start immediately, though. I needed some gems to start on my intended task. I attempted to install a gem only to see it fail. I tried a different one. It failed with the same error. Something was amiss.

$ gem install mysql2
ERROR:  While executing gem ... (Zlib::GzipFile::Error)
    not in gzip format
$

I immediately started to troubleshoot my ruby installation. Had I screwed it up somehow? I had just upgraded XCode.

After a few minutes of troubleshooting I figured out the problem. Ruby and gem were fine. My Internet connection was not. It had timed out and was again redirecting me to the terms of use page. Gem was trying to install the wifi terms of use for the cafe. This was why the gunzip failed ;) The solution involved pretty standard Internet connectivity troubleshooting:

  1. Open a web browser and navigate to http://www.google.com to trigger the terms of use page
  2. Once I accepted the terms I cleared my DNS cache with this command on OS X Lion: dscacheutil -flushcache
  3. I ran gem again and it worked!
$  gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysql2-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...

Rails 3 Validator List

Ruby on Rails 3.0 expanded the set of available validators that can be passed to validates. Here they are in list form:

:acceptance => Boolean.
:confirmation => Boolean.
:exclusion => { :in => Enumerable }.
:inclusion => { :in => Enumerable }.
:format => { :with => Regexp, :on => :create }.
:length => { :maximum => Fixnum }.
:numericality => Boolean.
:presence => Boolean.
:uniqueness => Boolean.

Source: the Rails 3.0 release notes

A suitable alternative to Net::HTTP in Ruby

A few weeks back I posted a vent blog entry about some shortcomings of Ruby. Well, it looks like one of my concerns has been at least partially resolved. Hiroshi Nakamura created, and continues to maintain, a wrapper around Net::Http called httpclient which adds enough functionality to save lots of time. Sure the performance still sucks compared to curl, but with this great library you can do multipart form posts and basic cookie functionality. Now my rails app can finally make use of some more complex HTTP based APIs out there (not everything is simple REST). Hiroshi, you rock, but back to my other complaint about Ruby stuff being scattered about the wind, please submit your gems to one of the big repositories so we can find them :)

About this Archive

This page is an archive of recent entries in the Ruby on Rails category.

Operating systems is the previous category.

SVN is the next category.

Find recent content on the main index or look in the archives to find all content.