Acts as Conference - Rails conference

New Edge Rails Feature: Default Scoping

By Peter Cooper on November 20th, 2008 in Miscellaneous, Tips

In his "What's New in Edge Rails" series, Ryan Daigle has just written about "default scoping." You're probably familiar with regular named scopes on Rails models, but now there's a default_scope method that defines a scope that exists by default on find methods.

Example:

class Article < ActiveRecord::Base
  default_scope :order => 'created_at DESC'
end

The default scope also carries across, by default, to any regular named scopes that you might have, so if you want to override the default scope, you have to force it.

Do note, however, that this feature is currently only in edge rails.

November 14

DHH announces the release of Rails 2.2 Release Candidate 2. It's the last stop before Rails 2.2 final!

3 Ways To Build Fake Demo Data For Your Rails App

By Mike Gunderloy on November 14th, 2008 in Compilation Posts, Plugins, Tools

numbers-1.pngYou've finished the first sprint of your new Rails application and you're ready to show it to the client - or are you? Most user interfaces look better when they're actually filled with data. You could sit down and start entering records by hand, wracking your brain to think of new names and addresses. Or you could take the easier way out by turning to a random data generation library.

We previously looked at the Faker library from Ben Curtis. Now at version 0.3.1, Faker is a port of Data::Faker from perl. Faker includes modules to generate random names, addresses, phone numbers, and more. Faker's data is hard-wired as lookup arrays in its source code, though, and it's installed as a gem, making it somewhat difficult to extend. Two other data generators are easier to work with in this regard.

The first of these is the random-data gem, currently at version 1.5.0. The brainchild of Mike Subelsky, random-data has a somewhat wider range than faker, covering names, dates, text, addresses, phone numbers, and more. As with Faker, the basic building blocks of the data are hardwired in the source code, but random-data also implements method_missing in a useful way: if you have a file named "spam.dat" in your load path, then calling Random.spam will return random lines from the file.

Rails developers will also want to check out Nate Sutton's forgery plugin. Forgery uses a Rails generator to move its data into your application, and it also separates data dictionaries from the actual generation code, making it extremely simple to change things like the list of names or cities that it includes. Forgery also has more data to choose from than the other two libraries, leading to an increased appearance of randomness in the end product.

Is this the end of the test data generation story? Probably not. At least random-data and forgery are still under active development, and I can think of some useful ways to extend them. For example, it would be great to see some sort of correlated generator that would ensure that a state, zip code, and area code all matched up roughly with one another. But even in their current state, any of these libraries will do better to fill out your test user interface than laboriously putting in everything by hand.

Tip: There's a more basic guide on generating fake names, addresses and more in Ruby over at Ruby And How!

November 13

Webbynode is a new scalable, Xen VPS hosting company whose service is currently in beta. They are looking for further beta testers particularly from the Rails field.

PaperClip: An Alternative Attachment / File Upload Plugin for Rails

By Peter Cooper on November 10th, 2008 in Plugins

redpaperclip.png In Goodbye attachment_fu, hello Paperclip, The Web Fellas present a walkthrough of Paperclip, a new(ish) Rails plugin that makes file (and particularly image) uploads easy. It's well worth a read, especially if you're just starting to develop a new app and are looking at which file upload technique to go with.

Paperclip is compelling firstly because it's developed by thoughbot, a team of ridiculously talented Rails developers who've released a lot of awesome Rails-related projects (such as Shoulda, Factory Girl, and Jester). Secondly, it offers some awesome features: no extra database tables needed to refer to files/attachments, only one library required for image processing (ImageMagick), and a very easy way to refer to files (as attributes on the main model, basically).

The official documentation is here, but Jim Neath has also written a full Paperclip tutorial that will take you from start to finish.

Supported by Media72 Hosting: Looking for reliable UK Ruby on Rails hosting? Packages start from just £7/month on our mod_rails/apache stack hosted on fast UK servers and include free 24/7 support.

November 10

Antonio Cangiano writes A major milestone for DB2 on Rails.

authlogic: Another Take on Rails Authentication

By Mike Gunderloy on November 5th, 2008 in Plugins

Locked keyboardThere are certainly plenty of plugins available to handle authentication in Rails, with perhaps the most commonly-used being Restful Authentication. But there's always room for one more, and the latest I've run across is Ben Johnson's authlogic. It takes a fresh approach to the problem space, with one big advantage over many existing solutions: because it's a pure plugin rather than a generator, it doesn't litter your application with a ton of code.

The key to making this approach work is that you need to define a special user session model that inherits from authlogic's internals, rather than from ActiveRecord::Base:

class UserSession < Authlogic::Session::Base
end

With that in place, you can use the regular Rails generator to spin up a controller for user sessions, and write "natural" code. For instance, logging a user in is just a matter of running @user_session = UserSession.new(params[:user_session]). Similarly, destroying a UserSession instance logs the current user out.

In addition to the source code, you can explore an Authlogic Setup Tutorial or play with an implemented example online. I haven't used authlogic in a client project yet, but after experimenting with it in some test code, it's definitely on my list for the next time I need to roll out authentication as a feature.

RailsRumble 2008 Winners Announced

By Peter Cooper on November 4th, 2008 in News

rr2008.png

Take approximately 500 Rails coders with a weekend to spare, an awesome collection of prizes, and a stackload of Linode virtual servers and you end up with Rails Rumble - a significant annual contest to develop the best Rails application possible in just two days. 245,000 lines of code were written and, as TechCrunch reported, 131 Rails apps were launched!

Josh Catone of SitePoint has put together an awesome summary of Rails Rumble. If you're just interested in the raw data, however, the three main winners this year were:

mibu.png

MeetInBetween.us - a Web app developed by the "Great Lakes Geeks" for finding the middle ground between two locations. It's basically the same sort of thing as a.placebetween.us.

qflip.png

QFlip - Get strangers to influence your Netflix queue. Sounds scary, but you might end up with some interesting picks! Developed by the wonderfully named "Scatapult" team.

riverdex.png

Riverdex - Get up to the minute news regarding the flow of your local river (in the US). Very useful if you're into rafting or kayaking.

There were also winners in Appearance, Completeness, Innovation, Usefulness, and Solo Team categories - all rounded up in the official Rails Rumble winners' post. I'd like to give a special mention to What Does This Error Mean, the winner in the Usefulness category. You paste in an error message you get in whatever you're doing and you look for answers. I could see it becoming a real-world hit if pushed properly.

Supported by Media72 Hosting: Looking for reliable UK Ruby on Rails hosting? Packages start from just £7/month on our mod_rails/apache stack hosted on fast UK servers and include free 24/7 support.

suprails and rg: Two Rails Application Generators

By Mike Gunderloy on November 3rd, 2008 in Tools

generator.png Most Rails developers are familiar with the repetitive grunt work between running the rails command and starting in on custom code: adding plugins, setting up git, initializing Capistrano, bringing in your usual custom rakefile, and so on. There are projects that provide a "Rails-plus" starter application with common stuff baked in (like Bort), but if you use one of those you're limited to what the developer thought you should add, unless you start fixing up the source code yourself.

Two new projects, suprails and rg, take a different approach to Rails application generating. They're both template-driven application generators that take a configuration file describing what you want to build and then go build it. Either one can make a new Rails application, bring in plugins, set up a git repository, run generators, and so on. The idea is that you set up your configuration once, and then just generate applications from it.

Suprails uses plain text files with a list of commands for its templates. The syntax for rg templates is more ruby-ish, with a template class containing nested tasks. Both projects are in the early days yet, but either one will already help you get rid of the repetitive work if you create many Rails applications.

Envy Casts Releases Rails 2.2 Screencast and PDF

By Peter Cooper on October 31st, 2008 in Screencasts

envycastsrails22.jpg

Just two months ago, Gregg Pollack and Jason Seifer of the Rails Envy podcast launched Envy Casts, a micro-publisher in the Rails scene. In anticipation of the release of Rails 2.2, they've released both a Ruby on Rails 2.2 Screencast and a Ruby on Rails 2.2 PDF (written by Carlos Brando; translated by Carl Youngblood). They're $9 each, or $16 as a package deal for the two. Reviews follow:

The Screencast

rails22videosample1.png

The screencast is a 44 minute audiovisual extravaganza that demonstrates most of the significant new features in Rails 2.2. I discovered a lot of stuff I didn't know about, and while Gregg and Jason were still as entertaining as in their first screencast, they've toned it down a little and focus more on the content this time around.

The diagrams and code examples are great and I found the format to be well suited for learning the material. If you really want it all to sink in, you can watch the screencast at the same time as using their supplied code samples (supplied in a separate file), as otherwise you get blinded by all of the cool new features and then need to rewatch it anyway!

In conclusion, this screencast is an awesome resource for getting up to speed with many of Rails 2.2's improvements (though, significantly, internationalization is barely covered). Unless you're a die-hard follower of the commits on edge Rails, however, you're going to pick up a whole ton of tricks and ideas from this video.

The PDF

rails22icon_product.png

The Ruby on Rails 2.2 PDF is a DRM-free PDF e-book that walks through all of the new Rails 2.2 features, along with a code example or two for each.

Clocking in at 118 pages (landscape), the main bulk of the PDF spans 80 pages of step by step feature summaries of the changes to ActiveRecord, ActiveSupport, ActiveResource, ActionPack, ActionMailer, and Railties. There's also a chapter on the Internationalization (i18n) features and one covering a few new performance features. Added to this are two laundry-list like chapters covering the "Bugs and Fixes" in Rails 2.2 and the obligatory "CHANGELOG."

The main chapters of the book, summarizing the new features along with code examples, are good, and possibly worth the price of entry, although I find the PDF format (for this sort of content) and the landscape orientation cumbersome. I'd prefer a more accessible format. The writing is solid and succinct though, and the code examples are as good as you'd expect.