Starting a new Rails app? Here’s my skeleton…

Posted: 15th February 2010 by M. E. Patterson in Coding
Tags: , , , , ,

Not meant to be a “this is what should be done” as much as a “this is what Matt uses, based largely on community popularity, best practice, and Matt’s personal tastes.”

Take it for what it is: a point of discussion.

Of course, the skeleton of any Rails app will vary from project to project, depending on needs.  Agile approach is to only add it to your framework if you actually need it right now, though some stuff tends to be easier to use (like authentication systems and databases) if you build it in up-front.  That tends to be my approach for green-fielding Rails apps.

If you’ve got some favorites that you use, feel free to post in the comments about it! I’m always interested in hearing about new stuff that makes my life easier/more fun.

FOR MY ACTIVERECORD-BASED APPS

  • inherited_resources
    • for building clean, simple resource-oriented controllers.  the Rails 3.0 guys recommend you start using this with Rails 2.3.5 apps because Rails 3.0′s new controller syntax is basically derived from inherited_resources (and jose valim is on the rails core team now)
  • authlogic
    • the reigning champ (in my opinion) for a while in terms of a really simple, basic user authentication solution.  i’ve also tried clearance, lockdown, ye olde restful_authentication, and others.  I still like authlogic alot, but the new Devise system seems to be really solid and might be good enough to get me to switch for new apps
  • searchlogic
    • really handy extra methods for activerecord queries
  • haml / sass
  • formtastichttp://github.com/justinfrench/formtastic
    • if you intend to produce semantically-correct, standards-compliant xhtml, your biggest enemy is trying to get forms to both look right and be semantic xhtml.  formtastic takes you a long way towards that goal, while also cleaning up your views significantly. and if you need to do something weird for a form that doesn’t quite work with formtastic, it doesn’t get in your way.
  • compass + blueprint
    • blueprint is just a CSS framework for laying out 950px wide fixed layouts in a clean way; particularly great for multi-column layouts, which can be notoriously tricky to get right and cross-browser
    • compass adds a layer on top of blueprint + Sass to make html/css design really easy and slick; saves you a TON of time and makes it easier to get the cross-browser stuff working (or 99% working) on the first try, instead of spending a whole day fighting IE 7
  • hoptoad
    • exception notification to a third-party service that integrates with lighthouse, github, et al
  • acts_as_state_machine
    • self-explanatory
  • acts_as_taggable_on_steroids
  • acts_as_rateable_with_weights (mine) – http://github.com/mepatterson/acts_as_rateable_with_weights
    • forked my own version of acts_as_rateable to add weighted ratings and bayesian averages
  • will_paginate
    • makes it much easier to handle pagination on any enumerable object collection (ActiveRecord objects or not)
  • ssl_requirement
    • allows you to lock down controller methods so they won’t work unless the requestor is hitting them through SSL
  • statistics – http://github.com/acatighera/statistics
    • have used this exactly once.  liked it, but didn’t use a ton of its features.  seems pretty robust though.
  • jrails plugin (+ nuke the prototype stuff and replace with jquery)
    • self-explanatory; prototype is dead. long live jquery.
  • xapian or thinking_sphinx
    • i’ve gone through so many different search engines for so many projects.  I think I’m the only one using Xapian.  It actually works pretty well, but is lacking in a lot of ways.  Thinking sphinx is similar; easier Rails integration, but missing some stuff, though it’s highlighting and excerpting work nicely.
  • paperclip
    • super-simple file attachments on ActiveRecord models
  • carmenhttp://github.com/jim/carmen
    • “helpful collection of geographic names and abbreviations for Rails apps (includes replacements for country_select and state_select)”
  • stringexhttp://github.com/rsl/stringex
    • helpful assortment of extra string methods
  • admin-datahttp://github.com/neerajdotname/admin_data
    • every app ends up needing some sort of admin backend to rifle through the data layer, at the very least in development mode; pretty useful
  • bullethttp://github.com/flyerhzm/bullet
    • stupid-simple plugin that helps you find N+1 queries and other query performance problems
  • factory_girl, shoulda, faker
    • i liked factory_girl a lot until my company started using machinist, so now I think I like that better.  shoulda is great.  faker is indispensable, imho.
  • db-populate http://github.com/ffmike/db-populate
    • i’ve been using this in my older AR-backed apps.  probably won’t need it in 2.3.5 or 3.0 apps, though i do like how ffmike did db-populate.  i think it might still be more robust than the db:seed thing built-in to Rails

FOR MY MONGO_MAPPER APPS

  • mongo
    • [GEM] the base MongoDB ruby driver
  • mongo_ext
    • [GEM] C-extensions for the above to make it perform better
  • mongo_mapper
  • sunspot[GEM] + sunspot_rails[GEM] (with custom config for mongo support) – http://github.com/outoftime/sunspot
    • found that sunspot integrates the solr search engine more easily with mongo than anything else out there.  has a lot of nice features, and it does automatic indexing on the fly, rather than requiring some sort of nasty cron job or handrolled delta-indexing solution
  • handrolled auth system derived in part from authlogic
    • so, i probably should start using Devise, since it apparently has native mongo_mapper support.  but for the two mongo apps I’ve built thus far, i just handrolled a simple authentication system by adapting the core code from authlogic and removing all the ActiveRecord-specific bits.  works fine, easy to add on custom stuff.  but Devise is probably better for the future.
  • machinist, shoulda, faker
    • see above
  • acts_as_mongo_rateable (mine) — http://github.com/mepatterson/acts_as_mongo_rateable
    • I wrote this from scratch, inspired by the basic architecture of the acts_as_rateable plugin for ActiveRecord
  • acts_as_mongo_taggable (mine) – http://github.com/mepatterson/acts_as_mongo_taggable
    • I wrote this from scratch, inspired by the basic architecture of the acts_as_taggable_on_steroids plugin for ActiveRecord
  • will_paginate
    • works fine with any enumerable object, so works with Mongo
  • compass + blueprint
    • see above
  • haml / sass
    • see above
  • jrails plugin (+ jquery instead of prototype)
    • see above
  • inherited_resources
    • this works largely the same with Mongo, since your resource-based controller shouldn’t really have any direct dependence on your database ORM
  • hoptoad
    • see above

STUFF I’D LIKE TO USE/WANT TO INVESTIGATE FURTHER

  1. g-man says:

    aegis works very well, and chronic seems to help with the 2/3/11 date formats..

  2. Hari says:

    Hi Patterson,

    Useful info and list. Thanks. Have you used carmen with Formtastic? Appreciate if you paste a sample line.

    -Hari

  3. lakshmanan says:

    Thanks a lot. I am beginner in rails and this post will surely help me a lot. bookmarking it in my delicious ;)

  4. Thanks for sharing this list – I especially like “nuke the prototype stuff and replace with jquery long live jquery.” Yup. jQuery is so much cleaner and easy to learn. Great starter list of plug-ins.

  5. Alex says:

    Hey Patterson! I’m just starting out on Rails and Mongo and am curious as to how you learned rails/mongo? Also, when you say “skeleton” are you referring to the additional plugins that you are using?

    • M. E. Patterson says:

      Well, how I learned is a bit longish of a story, but basically: learned HTML/websites back in the old days, then scripting languages, some C, some Java, then web apps mostly with PHP and MySQL or Postgres, then migrated to using Ruby/Rails with MySQL. After learning all that stuff, picking up something new like Mongo isn’t so difficult; just takes a little bit of learning and experimenting time.

      No professional Rails developer I know starts entirely from scratch when building a new app. In fact, you could argue that using Rails pretty much means you’re NOT starting from scratch… you’re already using Active(Whatevers), Rack, and a whole host of other gems, plugins, libraries. By “skeleton” I mean the general foundational set of plugins and gems that I tend to start a new app with before I add on all the custom functionality that the customer wants… not every app needs the same stuff, but largely most apps need a common set: user authentication and login, some sort of roles/groups/security system for content, a templating engine (Erb is built-in, but I prefer HAML), a database layer, etc., and then there’s lots of gems and plugins that just help you do the same old CRUD stuff you always have to build anyway, but in a cleaner, simpler way that abstracts away all the tedium.

  6. I can’t live without rspec and cucumber.

    • M. E. Patterson says:

      Yeah, I was a big rspec/cuke fan for a while. Then I went back to test:unit/shoulda. I dunno. I’m kinda on the fence on what I like more nowadays.

  7. Scott Sims says:

    Thanks for publishing this! I am looking forward to setting up a project using this skeleton. I will post back my experience.