Speeding Up Rails Development

November 15th, 2008

Over the last few months I’ve realised that the speed at which I develop new projects is a lot quicker than it used to be. So I thought I’d share some of the things I’ve learned and also some quite obvious things (to me at least).

Use a Base Application

I’m obviously going to be horrifically biased due to the fact that I helped to develop Bort, but I think that base apps are the way to roll. They save you about half a days worth of development and let you get straight into developing your application rather than fucking around doing the same monotonous stuff every time.

So here’s a run down of base apps floating around:

I haven’t used any of these apart from Bort, so I can’t really give you any opinion but everything I’ve seen by Thoughtbot and James Golick have always been awesome. Just look through them and find which one suits your needs.

I would like to end this section with a nice graph taken from Rails Rumble Observations, part II :)

Bort

Write Your Own Scaffold Generator

The default Rails scaffold generator is alright for prototyping an app but let’s face it, you wouldn’t use it for everything. So why don’t you made your own that you can use for everything. At the start of the last project we worked on, we spent 2-3 days working on a scaffold generator that would help to generate parts of the admin.

We made the generator generate all the search stuff, add sortable tables, generate basic specs and a whole bunch of other awesome stuff. Now we can get an awesome admin section set up for a model by running line from terminal.

This must have saved us at least a weeks worth of time. Time that we can now spend making sure that the rest of the site is as brilliant as possible. With the extra time, you take it easy, or you could add extra features, improve the UI, whatever. Keep it RESTful, kids.

Use a Form Builder

I hate forms. No secret there. But alas, nearly every application you’ll develop need to have forms. I wrote a custom form builder for the chaps at Fudge and it saves us a hell of a lot of time.

Now instead of writing something like the following:

<% form_for @story do |f| %>
  <%= f.error_messages %>
  <fieldset>
    <legend>Story Details</legend>
    <ol>
      <li>
        <%= f.label :title %>
        <%= f.text_field :title %>
      </li>
      <li>
        <%= f.label :body, 'Content' %>
        <%= f.text_area :body %>
      </li>
    </ol>
    <div class="buttons">
      <%= f.submit 'Create' %>
    </div>
  </fieldset>
<% end %>

Using our form builder we write:

<% form_for @story do |f| %>
  <%= f.error_messages %>
  <% f.field_set "Story Details" do %>
    <%= f.text_field :title %>
    <%= f.text_area :body, :label => 'Content' %>
  <% end %>
  <%= f.submit 'Create' %>
<% end %>

Now imagine you’re got to write close to 50 forms for an application. Can you guess which ones saves you time? Which one is more enjoyable to use? You got it.

Now while I wouldn’t say our form builder is ready for the general coding public (it isn’t), there are still a few out there.

I have used Semantic Form Builder by RubyPond before and it also happens to be the one we based out form builder on.

Build a Populate Rake Task

We started using Populator/Faker a couple of months a go and this is probably one of our biggest time savers. It’s a pain in the ass adding test data into your applications.

Ryan Bates has made a great railscast on how to use Populator along with Faker to generate fake data using a rake task so I’ll leave it to his awesome video to tell you all about it.

There are also a couple other options out there for generating fake data, the random-data gem and the Forgery plugin.

Peter Cooper has a more thorough run down of all three options over at Rails Inside.

Use Plugins/Gems

This should really go without saying, but I’ve seen a few people trying to write (poor) code for tasks that have already been solved, tested and improved on.

Gems and plugins are probably your biggest time saver. One of the things I love about the ruby community is that a lot of people give back to it.

If you have a problem, have a look on the awesome GitHub and see if there’s a plugin/gem floating around that looks like it could solve your problem. Try it out. If it works brilliant, if not see if you can fix it and improve the original code. Then if someone else has the same problem, they can use the plugin. If everyone helps out, we all have an easier job, we can do less work and enjoy life more.

Seriously, Just Buy a Fucking Mac

Just do it. Stop making excuses. I was a Windows user for about ten years but mainly because I didn’t know any better. I now work full time on a mac, both at home and at work, and there’s not a thing you could do to make me go back to Windows.

Windows simply won’t do a lot of things that you’ll want to do. Background jobs? Not a chance. Git? oh yeah, you can use msysgit but who the fuck wants to open up a separate program just to use git? Fuck off Windows. You’re slow and you suck.

Why get a mac? Rails runs faster. You can use the best text editor around, TextMate. You can install all those gems and plugins that all say: “This won’t work on Windows”.

Think getting a mac is too expensive? Get a low spec mac mini for $599. That’s what I started using and even though it’s low spec I never had a problem with it. You can use your USB keyboard, mouse and your monitor from your Windows machine. Still think it’s too much? Have a look on Amazon… Preowned Mac Mini for $350

So do you, my lovely readers, have any more suggestions/tips to speed up your development?

(Possibly) Related Posts

Recommend Me

If you found this post or anything else on this site of any use, then please take the time to recommend me on Working with Rails.

You can follow any responses to this entry through the RSS 2.0 feed. Trackback from your own site.

26 Responses to “Speeding Up Rails Development”

  1. November 15th, 2008 at 12:21 pm - malkomalko Says:

    Lovely insight! Code that writes code (generators), can not be ignored!


  2. November 15th, 2008 at 3:20 pm - Dwayne Says:

    Great post!

    Some help on … “write your own Scaffold generator”?


  3. November 15th, 2008 at 3:24 pm - Lenary Says:

    How about “grow a brain”. that’s something fairly high up my list for faster develompent.

    In all seriousness, passenger is very fast for development and deployment, esp with the prefpane thingy. If that doesn’t float your boat (i had an issue with memory usage on a very low spec server) then thin is an alternative. IIRC, it used as much memory as passenger alone, not apache too.


  4. November 15th, 2008 at 3:28 pm - Jim Neath Says:

    @Dwayne - I learned how to write generators by basically reading through the rspec generators along with the restful auth generators

    @Lenary - I’ve tried running passenger along with the pref pane a couple of times but for some reason the pref pane never seems to work properly for me. I’ll look into it again soon.


  5. November 15th, 2008 at 4:29 pm - JL Smith Says:

    Buy a Mac? Nah, save a pile of cash and install Ubuntu on your current hardware. There’s nothing Rails related that a Mac will do _significantly_ better than a good Ubuntu setup.


  6. November 15th, 2008 at 4:38 pm - Jim Neath Says:

    Or you could do that.

    I should probably reword it to “Don’t use windows” ha.


  7. November 15th, 2008 at 4:56 pm - Benjamin Curtis Says:

    That RailsRumble chart on Bort isn’t quite right… I got a very nice email from a RR participant who used the OpenID Rails Kit starter application (http://railskits.com/openid/) as the starting point for his application. He said he loved it. :)


  8. November 15th, 2008 at 4:58 pm - Jim Neath Says:

    @Benjamin - I know the chart isn’t right. It just made me laugh. One team used Suspenders and another team used Blank as far as I know.


  9. November 15th, 2008 at 5:41 pm - Peter Says:

    “That RailsRumble chart on Bort isn’t quite right”

    As I said about 9876*E10 matziliion times already, I worked with data the users supplied, and I suck at mind reading you know. I am really sorry for not including RR participants who used OpenID Rails Kit and pissed off Thoughbot guys who used suspenders etc.

    Anyway, the point is, statistically it doesn’t matter. Statistically everyone is using Bort. And the chart not being quite right doesn’t alter that. This of course doesn’t mean either that suspenders and/or OpenID Rails Kit doesn’t rock.

    And yeah, seriously, just buy a fucking mac - Ubuntu won’t do either. I have spent a few years on Ubuntu from warty to gutsy, and though it was improving from release to release, when I bought an MBP a year ago, the difference was shocking. C’mon, installing Ruby and the whole Rails stack is still a considerable pain (nothing like emerge rails on gentoo e.g.), whereas OS X ships with ruby/rails. How about a proper SQL GUI? (No, local phpmyadmin doesn’t count, and neither does mysql-query-browser). CocoaMysql?TextMate? skitch? DropBox? (ok, not directly Rails related, but I couldn’t live without it).
    Seriously, what’s the advantage of an ubuntu pc?


  10. November 15th, 2008 at 6:38 pm - gene t Says:

    Cheap macs: agreed, but at least 2G RAM, for VMware and all the other stuff you’re running simultaneously. I like to check powermax.com and smalldog.com, and there’s a small “Refurb” link on store.apple.com.

    Check out

    http://stackoverflow.com/questions/190662/whats-the-cheapest-mac-development-box-possible


  11. November 15th, 2008 at 8:56 pm - Amaretto Says:

    JL Smith is right. there is no need to buy a mac when you have Ubuntu… for FREE. Not to mention all apps (that i use at least) are 100% free.

    Finally… chances are you are going to deploy to a linux server… why not develop on the platform your app will be running on?


  12. November 15th, 2008 at 9:30 pm - Leon Bogaert Says:

    Come on guys. Let’s not make this thread a crappy Ubuntu vs. Mac flameware. Let’s all just agree on that Windows sucks and the commandline rocks \m/


  13. November 15th, 2008 at 9:41 pm - Peter Says:

    I neither want hijack Jim’s post nor start a mac/pc linux/os x holy war here, so this is my last comment on this topic:

    1) a mac is a piece of hardware and Ubuntu is an OS. My last DELL was about the same price as my current (almost high-end) MBP. Of course you can buy an Acer for third of the price, but well, the drop in the quality will be proportional.
    2) All the apps I mentioned and using are free too - except TextMate, which I would buy for even $500.
    3) linux server… what do you think, what is OS X built on? Windows?
    4) Finally… no one said it’s going to be cheaper - but the time OS X tools saved me is worth way more than the difference in a one-time purchase of a mac+TextMate vs PC (in case there is a difference at all).


  14. November 15th, 2008 at 9:54 pm - Alistair Holt Says:

    Great stuff man. I really should devote some time to developing some scaffold generators and form builders that I can use in my apps.


  15. November 15th, 2008 at 11:21 pm - Alistair Holt Says:

    BTW would it be possible to see your form builder code? I don’t mind if its messy. :)


  16. November 16th, 2008 at 10:49 am - Ibrahim Ahmed Says:

    You can add css_dryer, and resource_controller plugins. Both plugins are indispensable. and save a lot of time. Both plugins worth being imported into core rails. yes, they are that good.


  17. November 16th, 2008 at 11:26 am - Ingemar Says:

    OS X, Ubuntu, Gentoo… whatever. Just as long as you drop Windows. I had a monster PC with Windows XP, but my development environment was so slow. Everyday was a pain. Once you’ve made the switch you’ll never go back!


  18. November 16th, 2008 at 3:59 pm - Randy Parker Says:

    Watch oculardisaster’s Ruby Dev Tip & Tricks video at
    http://atlrug.org/oculardisaster/posts/65-Ruby-Development-Tips-Tricks

    (recorded at the Atlanta Ruby users group, 11.13.2008. There are a few slow spots when folks in the audience ask questions, but the audience makes it more comprehensive)


  19. November 17th, 2008 at 3:19 pm - Terence Namusonge Says:

    Good post Jim. I second your point on using a mac instead of windows but just to add using linux , ubuntu in particular is just as snazzy and netbeans as your IDE is such a gem :)


  20. November 17th, 2008 at 11:31 pm - JL Smith Says:

    @Peter: You’re dismissing Ubuntu linux as a viable Rails development platform because you had a hard time installing Rails? You justify a $2500 Macbook Pro purchase because the thing ships with Ruby/Rails installed? Please…I think you just bought a Mac because the “cool kids” did.

    Bottom line: OS X does nothing _significantly_ better than Ubuntu linux in the realm of Rails development.


  21. November 18th, 2008 at 12:10 pm - Migol Says:

    @Peter: Oh please…
    To first comment:
    Ubuntu is slow as hell. You want to get performance, get Gentoo. And for the Rauils installation - DON’T USE DISTRO PACKAGE MANAGER. It sucks. Really. Just install ruby, gem and use gem for management of your ruby packages. Why? Because no distro have ever utilized gem ability to have concurrent versions of same package.
    And for the SQL GUI, there are some for X Window that are nice and smooth.

    To your second comment:
    1) Yepp, but I could get a nice Core Quad Extreme 4*3GHz + 8 GB DDR3 RAM + HUGE HDD for less than you would pay for a Mac. And it would be fast as hell.
    2) And where TextMate is better than a good IDE? You don’t use IDE? Lol…
    3) True, Apple just added a lot of crap to it
    4) If you like it, use it.


  22. November 29th, 2008 at 12:12 am - Phill Kenoyer Says:

    The only reason why I prefer my Mac over my Linux/FreeBSD boxes is that when I’m using X I find myself constantly tweaking the UI. All the bells and whistles that X has are just too irresistible to me. I just have to play with it. On the Mac, I get my work done and then I can go outside and enjoy life.

    But yeah, I don’t think I could live without my Textmate. The IDE’s just don’t do it for me. GVIM is good too, but textmate is just great…. and WHERE IS MY TEXTMATE V2.0! It’s been years….


  23. December 1st, 2008 at 10:28 am - Migol Says:

    @Phill Kenoyer: “The IDE’s just don’t do it for me.”

    And may I ask you why? For months I’ve been using text editor for programming, but when I finally learnt how to use IDE there was no going back.


  24. December 9th, 2008 at 7:47 am - roger Says:

    Active scaffold is pretty nice, too, and uber-builder as a form builder has some good recommendations [1].
    I also like http://code.google.com/p/ruby-roger-useful-functions/wiki/EnglishLikeQueries

    -=R
    [1] http://tim.theenchanter.com/2008/11/most-rockin-carpool-site-on-web.html


  25. December 30th, 2008 at 11:25 am - 嚐一口基因改造蘋果 « 窗外的紅寶石 Says:

    [...] 早陣子看網上的Rails資訊,讀到Bort的作者Jim Neath一篇題目為Speeding Up Rails Development的文章,其中最後部份很煞有介事的說”Seriously, Just Buy a Fucking [...]


  26. January 3rd, 2009 at 5:58 pm - Akhil Bansal Says:

    Good collection. Thanks for your posts


Leave a Reply

Jim Neath is a 24 year old Ruby on Rails developer from Manchester, UK. Contact Jim Neath

Recommend Me

Categories

Stalk Me