- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
Many Varied Components, or… Multi Variable Complexity, or… Mainly Vanilla Coding
(Image comes from the Rails Envy MVC public service announcements -- and I hope they don't mind)
Here's the question:
Describe the MVC design pattern as it is implemented in Ruby on Rails.
And the followup:
In an MVC design, where would you place complex business logic?
This is part of the standard phone screen we give to potential Rails developers. The expected answer goes something like this:
MVC stands for Model, View, Controller, each of which represents a section of the application. The model manages data and often persistence, the view manages presentation, and the controller mediates between user actions and associated models and views. Each of these three subsystems should have as little interaction with the others as possible. Complex business logic should go in the model, since that is the section that deals with business objects.
If your doing a phone screen with us after this, at least have the decency to phrase that in your own words...
I don't think of that as particularly controversial, although I suppose you could pick at the wording and details to taste. Interestingly, or oddly, or something, the recent stretch of phone interviews has had a nearly unanimous answer to the followup question: Controller (sometimes, to be fair, the answer would be controller and model, but with controller as the primary answer).
After a brief time-out to check my sanity and calibrate with some other people (like the video with guys from the picture), I came out of the process with the following few thoughts:
Topics: Ruby on Rails
Mass Assigning Inheritance Column Values for ActiveRecord STI with Rails
One of the security features in Rails is to prevent mass assigning values for certain columns (when passing a hash to #new, #attributes=, and #update_attributes). This is to ensure that a malicious user can't exploit the system by passing in values for certain attributes you really don't want them to change.
In Rails 2.1, one of the attributes that will always be protected from mass assignment is the inheritance_column. In most cases, protecting inheritance_column; is desired because we don't want (for example) someone to change their user type by specifying type = 'Admin' when posting a form. Despite this, there are some cases where we do want to allow the user to specify the type.
However, even if we specify #attr_accessible on the inheritance_column, we will not be able to mass assign a value to it. Rails will not allow it unless we put in a little hack to work around this feature.
Topics: activerecord, Ruby on Rails, STI
Project Website Part 5: Morph in 11 steps or so

Eventually in the course of developing the Project Website application, it was time to put the project on a staging server for client viewing.
Often we'll host that ourselves, but in this case I decided to try out Morph, which provides a relatively inexpensive virtual hosting environment for Rails applications, using the Amazon Web Services cloud. Even better, Morph allows you to set up a development environment for free. (The free version is limited in size and bandwidth, and they also apparently will shut down the server if you don't deploy for 30 days -- a limitation obviously not shared by the paid environments).
I was able to go from total Morph ignoramus to running deployed app in under two hours. After reading this you should be able to do it even faster. (Full disclosure: Morph and Pathfinder are co-sponsers of the WindyCityRails conference September 20, 2008. That doesn't really have anything to do with anything, I just wanted to mention the convference)
Here are the steps:
Topics: Project Website, Ruby on Rails
What’s In Your Dock?
![]()
One of the things I like most about pair programming, or going to conferences, or sneaking a glance over somebody's shoulder at their screen is getting a chance to see the applications and tools that other people use to make it through the day. I often find myself walking past somebody and wanting to stop and ask them exactly what that interesting looking icon is for.
With that in mind, here are six things that you'd find on my dock, menubar, or command line history that help me get through the day. (I consider Quicksilver and TextMate to be in the Hall of Fame, and beyond this list.)
Autotest: Part of the excellent, if underdocumented ZenTest gem, autotest runs all your unit tests, then sits and reruns the appropriate tests when you save a file in your project. It also tries to run failed tests until they pass, which is very helpful if you have only one or two failing tests and you want to put some debug print statements in the code. Generally, if I'm coding in Rails, autotest is running.
Caffiene. Super-simple little utility that sits in the menu bar. When you click it, your Mac won't go to sleep. You can even set it to revert back to normal after a set time interval. This is always turned on whenever I give a presentation or client demo -- I always hate if my computer decides to sleep in the middle of my droning on...
Evernote. Note taking application. Boring, right? Not exactly. It syncs with a web account and also with an iPhone app. I've taken to putting clippings from Rails blogs there, to prevent the "I know I saw that somewhere" syndrome. Notes can also include pictures, and the web service attempts to do character recognition and allow you to search on, say, the notes you wrote on the whiteboard during that meeting.
TextExpander. Text macro utility, which comes with a set of HTML snippets that I prefer to the TextMate ones. I also define my command line aliases here because I hate messing around in Unix config files.
Twitteriffic. Okay, it's not exactly a productivity tool as such. But it's an extremely well designed piece of software. And with all the Mac and Rails developers I follow, it's nice to get a sense of what's going on. And, well, there are a lot of funny people who hang out there.
VoodooPad. Essentially, this is a personal desktop wiki, but rather than being an ugly web app, it's a pretty nice looking Mac app. I confess that I admire VoodooPad more than I use it, but I've recently started to put project-specific data there that is either too sensitive or too pointless to expose on our public wiki.
Hope this helps. What's in your dock?
Topics: Ruby on Rails
Why Chicago is Rails-town, USA
It's rare that dowdy old Chicago can pull rank on Silicon Valley, but with the red hot Ruby on Rails technology, Chicago leads the pack. How can I make such a claim? After all, everyone knows that SF and San Jose and points in between attract the best developers. There are 7 (and counting) reasons why I can say this:
- 37Signals - yes, the company where it all started is headquartered in Chicago. They're out of the professional services business and selling software built in RoR, but we used to see them as a competitor and have tried to emulate some of their business plans.
- Pathfinder Development - yes, the small but growing RoR powerhouse is also headquartered in downtown Chicago. They combine Agile development, User Experience Design (UXD) and RoR to develop "extraordinary applications," as it says in the tag line to the right.
Watch for our Rails-based competitor to Mingle, Tasker, in the next few months. Of course we also have Noel Rappin, author of Professional Ruby on Rails. - ThoughtWorks - global IT consultancy, but an OO and Agile Rails development shop at heart. Their Agile project management product, Mingle, is implemented in Rails.
- Centro - they're all Rails, all the time. Their core business is "providing the most comprehensive platform and services to help agencies easily and effectively buy local online media," but they have an impressive team of Rails developers powering their development. Heck, they're just a handful of blocks from us. We may have more Rails developers per square mile than any other neighborhood in America!
- WindyCityRails - our own local Rails conference (yes, we sponsor it).
- Two, count'em, two active Ruby groups, ChicagoRuby.org and the Chicago Area Ruby Group.
- Obtiva - another Agile and Rails shop, this one in the suburbs.
Think your town deserves the title of Rails-town USA? Bring it on!
Topics: Chicago, Ruby on Rails
Integrating Design Drafts Into Your Rails App
This one might be a little half-baked, I'd expect the implementation and features to change a bit over time. (Image from ArtCulture)
Nearly every project we work on at Pathfinder involves coordination between the developers and the designers. Over time, we've found that the more the design and development work can be integrated, the better everybody's work is. To that end, we like to have our designers work in CSS and HTML where possible, and to keep their designs in the same Subversion repository as the rest of the code. Being able to run a development environment helps the designers see their changes, and gives both sides immediate feedback on changes.
Here's a Rails hack that takes this one step further, allowing developers and designers to go back and forth between the current developer version and the design.
Topics: Ruby on Rails
Getting Started with Facebooker
Developing for the Facebook platform can be a big headache, and on Rails your headaches are unfortunately compounded from the get-go. While the otherwise-inferior PHP users get an API library from the Facebook development team (I'm kidding, I love you PHP guys), on Rails we have to deal with gems that aren't even at version 1.0 yet. While Facebooker is quite good at this point, its documentation covers a rather sparse selection of its impressive feature set, and RFacebook, which is better documented, hasn't been updated in aeons and is way more difficult to use besides. And unfortunately the standard Facebooker tutorial doesn't include the newest features from the recent Facebook profile overhaul or even all the necessary steps to get a new Rails application running on Facebook. So, enter Josh.
In this blog post I'll tell you the best way to integrate Facebooker into a new Rails project so you can start developing social networking applications quickly and easily, and how to hook them in to Facebook's new profile plan. The goal is that by the end of this post you'll have a totally working Facebooker Rails application and you'll understand how to develop in it at least a little bit.
Topics: Facebook, Ruby on Rails
Project Website Part 4: Drag and Drop in jQuery

Drag and drop is like those Nutty Bars snack things.
Allow me to explain.
I like Nutty Bars. But I never expect to like them. They are kind of funny looking, for one thing, what with that weird criss-cross pattern on the top, and the chocolate never quite covering the wafers. But when I get past that and actually eat one, it's actually kind of tasty.
Which brings me to drag and drop. Which I always expect is going to be an overwhelming pain in the neck (probably based on bad experiences using Java Swing). But whenever I manage to get over it and actually implement a web drag and drop, I'm always surprised at how easy it is using an Ajax framework.
jQuery is no exception.
Topics: Javascript, jQuery, Project Website, Ruby on Rails
Multiple Column Sorting with Drag and Drop using Scriptaculous
The other day I wanted to do drag and drop between multiple columns using scriptaculous. Allowing this behavior is extremely simple, but out of the box the interaction feels clunky. Here, we'll be going through an example of how to do multi-column drag and drop with scriptaculous.
Enabling multi-column drag and drop just involves setting a single option, but without setting a few other options the dragging will feel jittery and won't allow us to drop on empty areas. Also, interaction with the server will require a small bit of consideration to support persistence of any changes.
Topics: Javascript, Ruby on Rails, Scriptaculous
Visualizing Your Database Schema Entirely in Rails
I was recently looking into a tool to visualize the schema in a rails app, and found mostly windows only solutions. Some of these included two steps: one to convert your schema into another format (usually XML) and another step which included using a windows only executable to convert that into a diagram.
However, among these I found an interesting plugin which would allow you to not only view your schema live in your application, but also to make changes to it.
Topics: Ruby on Rails
Resolved: Should schema.rb be included in your source control?

This issue provoked a comment in two separate recent posts, and hey, when the people talk in vast numbers like... well, two, we respond.
As you know, Bob, there are two ways a standard Rails application tracks your database schema. The first is the collected set of your migrations, which can all be run with rake db:migrate. In theory, the set of migrations run sequentially results in your database schema. Rails also maintains an automatically generated file schema.rb, which is updated when migrations are run. This file is a Ruby script representing the current snapshot of the database and can be loaded into a blank database using the command rake db:schema:load.
The question that arises is which of these two methods -- migrations or schema.rb -- should be considered the ultimate source of truth about the application's expected database schema? The answer has implications for your group practices. If you consider schema.rb to be the final source, then you will want that file in source control, and you are less likely to place effort into ensuring your migrations are always runnable from scratch. If you consider the migrations to be the final source, then you probably don't want schema.rb in source control but you do always want to know that the migrations run.
Topics: Ruby on Rails
“Developing iPhone applications using Ruby on Rails and Eclipse, Part 3: Developing advanced views for iPhone” now available on IBM Developerworks
Part 3 of my series on developing web applications for the iPhone is now available.
This final series article looks at what you should do when the user reaches the end of the list structure and your application actually needs to display some content. iUI provides some useful features for content and form layout. It also covers some features that will give your application some extra polish, such as capturing the user's rotation of the phone and adding an icon to display on the iPhone's home screen.
Topics: iPhone, Ruby on Rails
Project Website, Part Two: Simple jQuery With Rails

This is something of a mix between what I've been doing on the http://www.pathf.com/blog/tag/project-website/ posts with my more typical "here's how you do something in Rails" post. I'm going to describe how to use jQuery to manage JavaScript and Ajax in a Rails application rather than Prototype and Scriptaculous.
Conclusions, Up Front
The benefits of using jQuery on a Rails project seem to be:
- A lot of basic behavior can be specified with much less JavaScript then in Prototype/Scriptaculous, making it feasible for even somebody with my JavaScript skills to write complex behavior directly in JavaScript. I found myself doing things client-side in jQuery that I would have done with a separate Ajax call before.
- In particular, certain kinds of behavior are almost ridiculously easy -- especially the case where you want every element of a certain kind to have similar behavior. So for instance, if you were, say, maintaining an iPhone plugin and wanted all links of a certain kind to trigger Ajax calls and slide left like a native iPhone app would, jQuery would be a pretty easy way to get there.
- Creating a Web site that is functional without JavaScript is a much easier and cleaner process using jQuery.
There are a couple of costs, especially from a Rails application
- You lose some or all of the Rails helper methods for writing JavaScript. You can keep some of the helpers by using the jRails plugin, but using that plugin minimizes some of the gains of using jQuery.
- The biggest loss for me was
assert_select_rjsand the lack of unit testing of jQuery behavior. As much as JavaScript development tools have improved, there are still gaps in testing browser-centric behavior.
Topics: Javascript, jQuery, Project Website, Ruby on Rails
Combine Multiple CSS/JS Files Into a Single File in Rails
One of the nice features in rails that many people overlook is the ability to combine multiple CSS or javascript files into a single file. Why would you want to do this? Well, it results in fewer HTTP requests being made by a client. The end result is that the page will load faster in most browsers, and your YSlow score will be bumped up a bit.
How do you turn this feature on? It is simple really; it just involves setting a single option in two rails helper calls which you're most likely already using.
Topics: Ruby on Rails
Screencast available
I've got a new screencast up, thanks to Jim Minatel at Wiley for helping put this together. Mac users might want to try this direct link to a QuickTime version, the main version is a WMV file.
The subject of this one is getting a Rails project started on Subversion, which is largely taken from Chapter 2 of my book.
I'm planning to update this screencast with another one on getting a Rails project started with Git. But I'd also like to open the floor to requests, if there's some piece of Rails functionality that you'd like to see visually.
Topics: Ruby on Rails
About Pathfinder
Recent
- Implementing linked multiselects with jQuery, LiveQuery, and Low Pro: Part 1: Requirements and interaction design
- Many Varied Components, or… Multi Variable Complexity, or… Mainly Vanilla Coding
- Custom Flex 3 Lightweight Preloader with source code
- Mass Assigning Inheritance Column Values for ActiveRecord STI with Rails
- Working effectively as a team of one: Five tips for front-end developers on Agile teams
- Ruby on Rails with Windows - How I made it work
- Project Website Part 5: Morph in 11 steps or so
- Papervision3D 2.0 (Great White) in Flex 3 (Part II & III combined) with source code
- What’s In Your Dock?
- Why Chicago is Rails-town, USA
Archives
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006




