Best of 2009, Ruby on Rails Edition


It was a good year for Rails. In 2009, we saw a number of exciting developments and a lot of great tools were released. Rails 2.3 was released in March 2009 and met with much fanfare. Rails has seen the introduction of templates, engines and a lot of other great features.

Thanks to the popularity of high profile websites that use Rails such as Hulu and Twitter, it is now considered a viable option for large sites. This kind of exposure means a lot of new development and movement. Rails seems to have outgrown many of the scaling woes of yesteryear. Now that it’s recognized in the mainstream as a stable and feature-rich platform for making websites, adoption has taken off, which means more tutorials, more resources, less bugs, lower barrier to entry and an overall better experience all around.

Another great development occurred quite recently in the Rails community. Two days before Christmas, on December 23, 2009, it was announced that Merb would be merged into Rails 3. This is another huge development which will end the duplication of efforts and fracturing of the developer community that occurred due to competition between Merb and Rails.

In the spirit of celebrating this current Rails renaissance, here are some of the best Rails resources we’ve come across in the past year. We hope you find these as useful as we did!

Less CSS

Less is an extension for CSS that allows you to use variables, perform operations such as mathematical calculations  and other neat features. It uses a Ruby script to read the .less file and generate a .css file to serve up to the browser.

Having variables is hugely helpful and it seems like an oversight in the CSS spec that it wasn’t included to begin with. Also, being able to add modifiers is nice. You can add, subtract, multiply, divide and even change colors. For instance, #FF0 + #00F would equal #FFF.

They also have mix-ins, which are classes that you can include in selectors, and it will include all of the properties from that class. This is the same thing functionally as adding that class to the elements matched by the selector, but without going into the HTML code. Mix-ins aren’t allowing us to do anything new that we couldn’t do already by adding the classes in HTML, but now it allows us to do this in CSS, without even touching the HTML. Some people will like this feature, others will deplore it– after all, we have a perfectly functional system where we can add multiple classes to a given element to achieve the same effect. But, I for one feel that this is a very useful feature to have. This is great for its reuse of code, and I love making modular CSS classes (for example, “rounded-corners”) that can be mixed into other CSS selectors.

Git and GitHub, Social Coding

git

These are two of the most useful tools of the year, hands down. Git caused a paradigm shift in distributed development. GitHub has become the de facto standard for Git hosting. If you’re unfamiliar with Git, read up on the Wikipedia page. To summarize, it’s a code versioning system that is well-suited for distributed development groups and open source software. It encourages users to make a fork of the repository so that any useful bug fixes, additions and changes can be easily merged back in, should the developers so desire.

github

I don’t see the advantage of using Git for personal projects or small in-house projects, but it is wonderful for open source efforts like Rails. It’s certainly a fine choice for any project, though I don’t see a big advantage over, say, Subversion, until you get into large scale distributed development situations like open source projects. Once you’re looking at open source projects, like those hosted on GitHub, we’re talking about a paradigm shift in efficiency.

Historically, most people would download zipped packages of code. Git encourages forking the repository instead. Let’s look at a quick example of how this works with Rails plugins.

Typically you could install a plugin by downloading some files somewhere and installing them, either with a script or by decompressing them directly to your vendor directory. This works fine but is unidirectional — you can only get the file from the developer, there is never an opportunity to submit code back, say, if you fix a bug.

The paradigm shift in efficiency that Git brings about is closing the loop: it allows you to easily submit code back to the trunk, thus capturing all those useful improvements to the code that would otherwise be lost on so many hard drives.

With GitHub, instead of downloading the Rails plugin, you fork the Git repositor to your vendor directory. Then, if you have to make changes to the plugin (which I almost always have to do, despite my best efforts to avoid it), you still retain the ability to update the code without losing your fixes. The old way was that if I wanted to upgrade a plugin that I had customized, I would have to download the new one and then manually go through and make whatever customizations I’d done. This way, you can automate the merging process and only have to go in if there are conflicts. That’s a big win to me. Then, if I actually do something with a plugin that others might find useful, I can offer up my own fork on GitHub, or submit it to the trunk if I think it’s useful enough to be included there.

Although Git was released in 2005 and GitHub in 2008, I included them on the 2009 list here because I think they have really broken through to the mainstream in a big way this past year. GitHub achieved meteoric rise during 2009. In January alone 17,000 new repositories were made, according to a talk given by GitHub founders at Yahoo in February of that year. In July of 2009 they had 90,000 unique repositories, double the previous year– and 45,000 forks of those repositories.

So, get on the bandwagon! Head over to GitHub and see what they have to offer. Or, if you don’t know where to start, check out this next useful resource for pointers …

The Ruby Toolbox

The Ruby Toolbox is a wonderful resource for finding out what is popular. It uses metrics such as SVN commits and GitHub forks to determine which Ruby scripts are most popular. You can find out about a lot of great tools this way. I’ve discovered plenty of useful Rails gems and plugins here. There are also some useful standalone Ruby scripts for a variety of development tasks, such as Less, which doesn’t depend on Rails to do it’s thing.

Prawn, PDF Generation Made Easy

Prawn is a gem for generating PDFs. Let me tell you, working with PDFs is never easy, but Prawn greatly reduces the pain.

Check out this tutorial at RailsTips for more info.

jRails

I think it’s pretty obvious that jQuery has hit the big time in popularity. Endorsements by Microsoft, Amazon.com and other major players have led it to become the go-to JavaScript library of 2009. While Prototype still hangs in there, and MooTools has a great offering, an article I read recently summed it up perfectly when they said ‘jQuery is the guitar.’ It had a screen grab of Google search results for guitar versus banjo, along with similar numbers for jquery versus mootools. You get the idea. If you aren’t using jQuery, you’re playing the banjo. If you want to really rock out, get on the bandwagon!

I am being facetious here but there is certainly some truth to the fact that a web developer in 2010 must be well-versed in jQuery. It’s also a viable alternative to Prototype in Ruby on Rails. In fact, I’ve heard that Rails 3 will be JavaScript framework agnostic, but don’t quote me on that.

In any case, you don’t have to wait until Rails 3 to start using jQuery in your Rails app. Simply install the jRails gem and you can go along using all those nifty Rails helpers, completely unaware that they are now implemented in jQuery instead of Prototype. Isn’t encapsulation great?

HAML

HAML (pronounced like Mark “Luke Skywalker” Hamill’s last name) is a great alternative to HTML. You write clean, concise HAML and the parser generates verbose and ugly HTML to serve up to the browser. Thus you can avoid typing those obnoxious closing tags that markup languages are so fond of. Keep your code simple, clean and pure. Or that’s the idea.

In practice, HAML can be a bit complex. Check out the HAML Wikipedia page to see what I mean — look at all those obscure symbols. But once you learn what they all mean, it is a very concise, some might say beautiful language.

Paperclip

What can I say? Paperclip rocks. It is the standard for attachments in Rails and with good reason. It has been consistently updated, bug-fixed, and best of all, it is simple with not a bit of bloat. It requires the bare minimum of information from you, the developer, and does all the heavy lifting– even light lifting like database migrations– for you.

The next time you need to allow for file uploads in your Rails app, look no further than Paperclip.

Acts_As_Taggable_On, a Gem For Tagging

Originally forked from Acts As Taggable On Steroids, the truncated form, has a number of improvements and goodies. Here is an excerpt from the Readme:

This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney. It has evolved substantially since that point, but all credit goes to him for the initial tagging functionality that so many people have used.

For instance, in a social network, a user might have tags that are called skills, interests, sports, and more. There is no real way to differentiate between tags and so an implementation of this type is not possible with acts as taggable on steroids.

Enter Acts as Taggable On. Rather than tying functionality to a specific keyword (namely “tags”), acts as taggable on allows you to specify an arbitrary number of tag “contexts” that can be used locally or in combination in the same way steroids was used.

Read more at Github.

Thinking Sphinx, Front End to Sphinx Search Engine

Thinking Sphinx is a great Ruby client to the Sphinx search engine that allows your Rails application to seamlessly integrate with Sphinx. This means you can get blazing-fast search results that are so fast because they’ve been optimized with filesystem-based indices, and even delta indices which only track changes to those indices, meaning they can avoid database calls when possible. Sounds fancy, huh? In practice, it’s a relatively painless set up that gets you professional quality search results. Sure, it can’t beat Google Mini, and feature for feature, heavy hitters like Java’s SOLR may win out, but for every project I’ve worked on, this has been sufficient. I like it a lot better than Ultrasphinx, the other Sphinx front end I’ve worked with.

All right, that’s all I have for now.  I’m sure I missed tons of great resources.

Please add your own favorite Ruby on Rails gems, plugins and resources in the comments!

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Slashdot
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Share/Bookmark

,

  1. No comments yet.
(will not be published)