Thursday, September 19, 2024

Nineteen Rails Secrets To Web Development

Ruby on Rails has increased in popularity among web developers seeking a solid framework for their applications, and some helpful hints can make it even better.

A number of resources for the Ruby on Rails framework have arrived online since its debut. The Ruby Inside blog, maintained by English web developer Peter Cooper since May 29th of this year, offers some nice insights into Rails and the underlying Ruby object-oriented language.

His latest post comes in a format most people always enjoy finding online – the list. Cooper’s list of “19 Rails Tricks Most Rails Coders Don’t Know” suits that very well.

One Cooper noted, the acts_as_nested_set, made its quiet debut in Rails:

It’s much like acts_as_tree, but with the added benefit that you can select all of the children (and their own descendants) of a node with a single query. A list of the instance methods is available.
A couple of conversion tricks, like using the array method to_sentence, or the number helpers, have their place. An array of related terms like names can be rendered as a sentence. For numbers, helpers offer nifty shortcuts like formatting a number in currency format, or setting delimiters for them.

One useful speed trick can be accomplished for an application that has unchanging data from restart to restart, Cooper wrote:

If you have data that doesn’t change between application restarts, cache it in a constant somewhere. For example, you might have a YAML or XML file in /config that stores application configuration data, and you could load it into a constant in environment.rb, making lookups quick and easy application-wide.
Cooper also touched on a small framework, BackgrounDRb, that will be recognizable for its utility. This daemon allows the Rails application to send it tasks, and the daemon will complete them in the background.

“It’s extremely powerful, and useful for many tasks such as sending hundreds of e-mails, fetching URLs, and other things you don’t want to slow down the request times for your main app,” said Cooper.

Be sure to check out the rest of Cooper’s list for more excellent insights into working with Rails more effectively.


Tag:

Add to Del.icio.us | Digg | Yahoo! My Web | Furl

Bookmark murdok:

David Utter is a staff writer for murdok covering technology and business.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles