You are viewing an archived version of danielfischer.com

 

19 Rails Tricks That You May Not Know About

Published: October 8th, 2007

A couple new tricks in a trade never hurts anybody, but 19?! Check this out.

I came across a very helpful article from Ruby Inside today, “19 Rails Tricks Most Rails Coders Don’t Know“. I actually knew all of those tricks, but I’ve actually forgot a few a long the way; so it was a nice helpful reminder to read that list over. One of the more interesting ones was this little bugger:

Convert arrays to sentences in views - If you were collecting a bunch of names to be shown in a view, you might end up with an array like ['Peter', 'Fred', 'Chris'], and joining these with commas and inserting ‘and’ before the final one is a common pain. Not so, if you use the array method to_sentence as provided in Rails. names.to_sentence would return Peter, Fred, and Chris.

There’s a ton of little snippets of information like above from this article. Did you find any of them to be helpful? Go ahead and post your own tip, maybe we can create our own list!

“Peter, Fred, and Chris”
not being native english speaking I wonder whether the comma before the and is really required/correct. In german we would write:
“Peter, Fred und Chris”

gravatar

It’s generally motivated to use “Peter, Fred, and Chris”. However, if I recall correctly, the comma is not required before an ‘and’.

gravatar
Enter your comment

Ready. Set. Go.

In terms of the formatting, you're allowed to use markdown, textile, or basic html; it's truly up to you -- what strikes your fancy?

You don't have to worry about your e-mail address being sold to a russian-spam-mafia. I'm only going to use it for my own weird needs; like asking you out for a date on a lonely night of coding.