Working with Rails 3

by James

So it’s Sunday, and rather than go to church I decided to take Rails 3 for a test drive. As you do. How did it go? In the main, very smoothly — a couple of bugs, which you Googlers might find it useful to know about, and some nice new stuff.

Bug: the rails command

Failed completely :) Rails my_app fails with “no value provided for required arguments ‘app_path’”. The solution to this is easy, though: first, get a local copy of Rails 3 (I cloned the Rails repo: git clone git://github.com/rails/rails.git) and then use this command instead:

The rubygems require is necessary for Rails 3 to load all the gems it needs to run.

Thoughts

The Rails command

In Rails 3, the rails command replaces script/console, script/server, etc. This is nice: commands are more meaningful (run the rails server with “rails server”), and easier to type.

ActiveRecord’s new finder syntax

ActiveRecord’s new finder syntax is lovely, and has some nice performance gains which you can read about on other blogs. Named scopes look good:

I’m going to write more about this soon.

Speed

Call me crazy but Rails 3 seems faster. Maybe this has something to do with the fact that it uses Erubis instead of ERB, or maybe I’m just easily impressed :)

Paperclip (tiny bug)

Paperclip has a branch called Rails3: I went out on a limb and guessed that was for Rails 3. It almost just worked, except for one thing: custom attachment styles weren’t being created.

If you’ve used paperclip, you’ll know you can do this:

Well, those :medium, :wide, and :small variations weren’t being created. I didn’t have time to investigate properly but this seemed to have something to do with Paperclip’s callbacks (which were returning false even when they shouldn’t be): my one line hack/fix for this:

I freely admit that this might break other parts of Paperclip, but it works for me.

Conclusions

Overall, Rails 3 feels very nice. As you’d expect from a beta it almost just works, and I’ve made a working app with it in a day. Super easy! Next up: deploying to Heroku.