Obie Fernandez: The Worst Rails Code You've Ever Seen! 1

Posted by Frank Oxener
on Sunday, June 15, 2008

Last Tuesday (10th of June) Obie Fernandez gave a presentation on the RubyenRails conference in Amsterdam about The Worst Rails Code You’ve Ever Seen.

To be honest he had some really bad examples, he showed us for example an user controller of 1131 lines (of pure FAIL)!!

But a lot of examples were more in the line of not knowing there is a better alternative in Ruby or a better alternative provided by the Rails framework.

Obie came with an example like this:


class Util
  def hash_values_as_array(hash)
    values=[]
    for key, value in hash
      values << value
    end
    return values
  end
end

(Of course, you can do the same with hash.values.)

I don’t think this is bad at all and I even think it happened to almost all of us. Most people working with Ruby On Rails were attracted by the power (and the beauty) of the Rails framework and had never worked with Ruby before (and most of the times had no or little experience with web development like myself). For a newbie it takes time to get used to and to find your way and understand the ins and outs of the language and the framework. And sometimes it is more simple or quicker to come up with your own little method like the example above. In fact, it’s a great way (or maybe the way) to learn a new language like Ruby.

The main point of Obie was that you need to learn the fundamentals, read some books and pair with senior people. All true, but it takes time and it’s more difficult for someone starting this year with Rails instead of let’s say 2005.

Rails is becoming a ‘big’ framework and if you know it really well (and keep up with all the new developments) it can make you really productive. But the learning curve is becoming steeper and steeper …....

If I look at available Rails jobs, everybody seems to look for a rails ninja, rock star, kick ass developer, killer rails developer, crazy rails hacker or even an inspiring Ruby god. I think they are difficult to find.

If you want my advise, find a place where they see your learning potential and don’t mind that you make mistakes like the ones Obie is talking about. It is all about learning by doing (and making mistakes along the way).

One more thing, Obie wrote The Rails Way, which is IMHO the best Rails book at this moment. At the end of his presentation Obie announced he is going to write a Rails Antipatterns book. I think this is not the right approach, please write a Rails patterns book, that is much more positive!

Workshop Ruby on Rails and Maglev

Posted by Frank Oxener
on Sunday, June 01, 2008

I was asked to give an introductory workshop in Ruby on Rails for an insurance company. An intranet application was build in Ruby on Rails for this company and now they want to have the knowledge to maintain the application themselves. So I organized a workshop in two sessions to touch on the basics of Ruby and Rails. And I have to say, it is not easy …. especially when this application has polymorphic and has_many :through associations… :-)

I myself started with Ruby on Rails in October 2005 (I had no experience with Ruby at all) and I remember it was straight forward, although it toke me a while to understand (for example) some of the magic of ActiveRecord (made possible by Ruby). But now 2,5 years later we have Rails 2.1 (since yesterday!) and it has a lot of new concepts and extra features and therefore I think it is a lot harder to get started. My preparation for this workshop made me realise that now it will take more time to really get acquainted with the full potential of Rails.

And to be honest, working every day with Rails, it still is a challenge to keep up-to-date with the new features in Rails (which seems to be added almost ‘every’ day) and all the new developments and innovation in the Ruby and Rails community. The day before yesterday I had never heard of Maglev or Mongrel-esi.....

Global include for Nginx with a wildcard.

Posted by Frank Oxener
on Friday, May 09, 2008

We use Nginx as our webserver and loadbalancer with several different rails applications and we’re very satisfied with it. I thought let’s share the way we set up de nginx config file, because so far I haven’t read it elsewere.

In the global config file of nginx we use includes with wildcards, for example:


    include /u/apps/*/current/config/nginx.conf;
    include /u/apps/*/config/nginx.conf;

So now we only have to take care of the individual settings of an rails application for configuring its virtual domain(s), rewrite rules and etcetera in its own ‘local’ nginx.conf file in the rails/config directory (which is of course under version control).

When you want to start a new application after deployment, first test the configuration settings of nginx as follows:


  cd /usr/local/nginx
  sudo ./sbin/nginx -t

If everything is ok, you get something like this:


2008/05/09 17:06:10 [info] 19177#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
2008/05/09 17:06:10 [info] 19177#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

Restart Nginx (all the local config files will be included as well), start your application and you’re done.


  sudo /etc/init.d/nginx restart

Very practical!

(Credits to my collegue Matthijs Kadijk.)

Please add ruby ....

Posted by Frank Oxener
on Friday, April 11, 2008

Google recently did a beta launch announcement for their application hosting service called App Engine.

Currently it only supports Python. So following Dr Nic’s advise, I starred “Add Ruby support” because its fun!

So go ahead and do the same at code.google.com !

A great day....

Posted by Frank Oxener
on Thursday, March 20, 2008

Yesterday, we had a great day on our Entrepreneurs conference here on the island of Texel.

We gave a keynote presentation about the concept Fablab, which went very well.

It was nice to have a lot of new contacts with the local community and it gave us new ideas for the next steps in establishing a FabLab on Texel.

Google Sketchup with ruby API.

Posted by Frank Oxener
on Friday, March 14, 2008

Because of our involvement in the Fablab community, we’re very interested in extending the functionality of Google Sketchup with the Ruby API. We like to use Sketchup for basic 2.5D snapfit design, for example like this or this. For the moment it is a research project to determine the possibilities of the Ruby API.

Here’s an introduction video of SketchUp developer Mark Limber talking about some of the possible ways to extend the software with the Ruby API.

An intern for this project is very much welcome…....

The ampersand in Twitter4R

Posted by Frank Oxener
on Monday, March 03, 2008

For Bemba.com we use the Twitter4R gem, which works like a charm.

sharing web pages with friends in one click on several social networks at once!

Except we had some problems when we used the & character in our messages. It turned out that URI.encode was used for encoding and the text message was chopped off at the & character.

The solution was to use CGI::escape for encoding in ../twitter/lib/twitter/ext/ stdlib.rb:


class Hash
  # Returns string formatted for HTTP URL encoded name-value pairs.
   def to_http_str
    result = ''
    return result if self.empty?
    self.each do |key, val|
      result << "#{key}=#{CGI::escape(val.to_s)}&" 
    end
    result.chop 
end

Now it is just a matter of submitting a patch for the gem, but although the specifications are all nicely written with RSpec, we’re not able to run the specs.


no such file to load -- ./../spec_helper (LoadError)

What are we doing wrong here….where is the spec helper?

Kluster: a new product in 72 hours!

Posted by Frank Oxener
on Thursday, February 28, 2008

Crowdsourcing firm Kluster officially launched yesterday at the TED conference with a big challenge: “over the next 72 hours we will harness the collective power of TED attendees, and our online community to develop a totally new, tangible product.



The idea behind Kluster is that a group of passionate people working together can come up with better solutions for any decision-making problem than a single person. Whether that is planning an event, designing a new logo, or creating a new product, Kluster believes their system can work.

I find it an interesting concept. Especially because Kluster also introduces it’s own currency: the watt. I think a sort of Local Exchange Trade system (LETS) as a catalyst for cooperation and innovation is promising. Is this principle a way forward for the International Fablab community?

Update of our website.

Posted by Frank Oxener
on Thursday, February 28, 2008

It was about time to do an update of our website.

First, we migrated from Typo to the more ligther-weight and stable Mephisto. The migration was also the moment to use a more timeless theme (Scribbish) and, from now on, to post in English.

It also reflects a slight change in our business focus. We’re still very much dedicated to our Ruby and Rails work, but our active involvement in the Fablab community has lead to a repositioning of our services.

With the expertise of Ruby, Rails and agile software development and our knowledge of digital and personal fabrication, we think that we’re better suited for multidisciplinary projects on the edge of open source connected soft- and hardware.

We closely follow the trends and developments in that sector and we of course share this on our blog.

So stay tuned …... !!