Rails Tips for Designers, Part 1

After working with Ruby on Rails for a few years and spending the past 2 months knee deep in it for 8-10 hours a day, I’ve learned a few things about working in Ruby on Rails. I owe my basic understanding to Jonathan and Sean from when I was working with them on Voomaxer.

The Tips

1. Work with smart programmers who are also good teachers

The lead developer at Bleacher Report is both a great developer and a great teacher. This is the single most important thing for making working with Rails (or any language) easy. Whenever I have a problem (which is regularly) I say “Hey Tung, how do I ________?” The other engineers are equally helpful and very smart.

If you don’t have access to smart coworkers, try talking with developers regularly on IRC or in forums. Many of them are very willing to help out if you are genuinely curious and don’t ask basic questions that you’d find quickly using Google.

If people can’t explain something so that you can understand it, chances are they don’t really know what they’re talking about. Experts are good at explaining things to non-experts.

2. Stay organized

A brand new Rails project is setup to keep the developers organized. The MVC pattern is great for keeping programmers from putting too much logic in a view or writing a bunch of SQL alongside a bunch of logic. It is not so good at keeping designers organized.

Namespace your images using folders. If I have a button that goes on the sign up form, I put it in a directory that looks like this:

/public/images/forms/signup/signup.jpg

But more often than not I use sprites, which I would keep in /sprites/buttons.jpg.

I do the same thing for stylesheets. As an example there is certain CSS that is loaded on every single page of the site (i.e. the header). I would keep that in it’s own file:

/public/stylesheets/common/header.css

Under the /common/ you would include all of the CSS files that are loaded on every page of the site, my stylesheets directory looks like this:

/public/stylesheets/common/reset.css
/public/stylesheets/common/base.css
/public/stylesheets/common/grid.css
/public/stylesheets/common/header.css
/public/stylesheets/common/sidebar.css

/public/stylesheets/articles/article.css
/public/stylesheets/articles/comments.css

/public/stylesheets/widgets/widget_1.css
/public/stylesheets/widgets/widget_2.css
...

Wait! Don’t you have to write 20 different links to external CSS stylesheets in the header if you do this? No. You use asset packaging, which takes all these stylesheets, removes the white space, and turns them into one stylesheet that loads nice and fast.

<%= stylesheets_link_merged :base %>

If your development team is not using asset packager, suggest it to them - there are many benefits beyond organizing your CSS. Also, I know that you are probably thinking this organization is a bit anal retentive and causes more pain in the long run, but if you’re working on a site of moderate size it’s just as annoying to scroll through 7,000 lines of CSS.

3. <%= and <% are different.

This is insanely obvious to every engineer. To me, this was not obvious. It turns out code that looks like this:

<%= %>

Actually spits something out onto the page. You wrap your Rails link helpers with <%= because it will actually spit out the results into the HTML. If the code begins with:

<% %>

Then it does not actually output anything that the user or browser can see but is parsed by Rails - if/else statements, loops, etc. will go in these tags.

4. Break things regularly

A lot of what I’ve learned comes from when I try to do something on my own without asking a developer. It usually breaks. I usually then have to reverse engineer what I broke and figure out how to fix it. Guess what? After I do this I understand why it broke and why the code was written a certain way.

This is a great way to learn any programming language. Actually, since starting work, this is how I’ve learned most of what I know about our Prototype. I will probably use the same method to learn more about Ruby and Rails. Just remember not to check in broken code - version control will identify you as the culprit.

The Hype

There was (and is) a lot of hype around Ruby on Rails. (Did you know 37signals uses it for Basecamp?!) You can read millions of blog posts about it and buy all sorts of books with advanced Rails recipes. People argue until they’re blue in the face about whether Ruby is faster than this or Rails is faster than that.

Guess what? When you’re working on a team that just wants to push a kickass product out the door, no one thinks about these things. People code in whatever language makes them happy and seems like the best tool to get the job done. The people building real, useful products in Ruby often don’t have the time to hang out on message boards arguing about millisecond differences in response time.

The truth is, Ruby on Rails is good enough for most web apps. Tung (our lead developer) answered the question “Does Ruby on Rails scale?” with another question: “How good is your code?” I think he heard that somewhere else, but I don’t know (or care) where.

{ 12 comments… read them below or add one }

1 Nick November 20, 2008 at 10:20 am

I’m not a designer, but I like what you said here. Being organized is the most important part of any software development project, be it as a designer or developer. If you start organized and stay organized, then you’ll be ok. If you start off wrong, then all hell can break lose down the line.

I think the only place you may be off is with the statement that “Experts are good at explaining things to non-experts.” There are some things that are just too obtuse to be explained quickly and easily to people who don’t have intermediate to advanced knowledge of a subject. To be fair, these aren’t things that a designer would usually be involved with so maybe you weren’t addressing them ;)

2 Kyle November 20, 2008 at 2:42 pm

I’d venture to say that not just “good enough”, but rather great for most web apps. For the vast majority of people out there, their apps will never require intricate scaling, and all frameworks have issues scaling anyway. It’s the instant gratification of Rails that is so great, and it really speeds up development time, so that, even if you do end up running into scaling issues, the time you saved upfront is well worth it.

3 Ben November 20, 2008 at 2:59 pm

There are some things that are just too obtuse to be explained quickly and easily to people who don’t have intermediate to advanced knowledge of a subject.

I tend to disagree - even advanced theoretical physics can be explained in terms that most people understand. Do you need to understand some basic physics principles? Sure. But nothing you didn’t learn in high school physics classes.

Good explanations are not necessarily succinct - it may take a day to explain something very advanced, but that doesn’t make it a bad explanation.

4 Nick November 20, 2008 at 3:37 pm

I tend to disagree - even advanced theoretical physics can be explained in terms that most people understand.

I guess the only concern is if you lose something in the translation to simpler terms. I surmise that string theory can be abstracted to the point where you don’t have to be actively studying high-level physics, but I would guess that some of the more nuanced concepts would be missing after the translation.

Then there are the things that are pure mathematical constructs that humans have come up with to better understand the world. How do you explain these to a non-expert with no direct knowledge of the subject? I guess the two things I can think of from my domain are continuations and closures. You almost have to learn a little bit of lambda calculus to know what is going on. Once you start doing that, you’re becoming a domain expert via the explanation, so you’re actually learning the subject yourself and becoming a pseudo expert (even if it is just a particular niche of a topic). You make a good point that good explanations aren’t necessarily succinct, but where do you draw the line between an explanation and a lesson?

Of course what it really boils down to is this: In day to day life, you don’t really need to know the things that can’t be abstracted and explained in simpler terms.

5 Ben November 28, 2008 at 12:56 pm

Agreed, Kyle.

6 Loy53 October 22, 2009 at 4:21 pm

That leads us to the second point I want to elucidate. ,

7 Heel October 29, 2009 at 12:50 pm
8 Aron October 29, 2009 at 1:19 pm
9 Aron October 29, 2009 at 1:56 pm
10 Heel October 29, 2009 at 2:20 pm
11 Heel October 29, 2009 at 2:31 pm
12 Jane November 13, 2009 at 2:33 pm

Leave a Comment

Previous post: When asking for more information is better

Next post: 1 Simple Step to Improve Airline User Experience