1. Code
  2. Roundups

10 Awesome Ruby on Rails Techniques to Get You Started

Scroll to top
Read Time: 5 min

Rails has seemingly set the web development world on fire these past few years. Popular web applications like Basecamp and Twitter have pushed Rails into the limelight as an excellent framework that any programmer (or even non-programmer) can quickly use to create applications.

One of the most popular aspects of Rails is how easy and intuitive it is to start using right out of the box. Here are 10 tips that beginners can use to help with getting started with the powerful framework.

1. Utilize Source Annotations

If you're a beginning programmer, you'll soon realize that a major part of writing code is correctly writing source annotations and comments. While this tip isn't necessarily Rails specific, it sure does pertain to solid rails coding. If you're going to annotate your code, use these aptly named keywords:

  • TODO - Used to show code that is incomplete or needs some work
  • FIXME - Used to show code that is broken or buggy
  • OPTIMIZE - Used where further optimizations need to be done

Using these function while programming Rails is especially helpful as Rails allows for adding rake tasks that help you search the code for all the occurrences and prints them out with the file name, line number, and the description.

Perfect for finding those little things that need some TLC within your code.

2. Monitor Your Apps!

As your Rails applications start to become more complex, you'll start to notice that some processes might need a tad more TLC in terms of optimization. In order to find those little bugs and errors in your code, try using the excellent Relic RPM to monitor your applications. Relic RPM gives you a chance to monitor all of the processes of your application, and gives you visual graphs and other helpful information to really get a handle on the processes that are causing slowness in your app.

The RailsTips blog has an excellent review of Relic RPM. Analytics are indispensable for developing successful and efficient Rails applications.

Photo by helmet13

3. Group Operations in a Transaction

ActiveRecord is the handy persistence engine that allows you to do many cool things with data and logic. One of the really handy things that ActiveRecord allows you to do is to group multiple inserts in a single transaction. Zen and the Art of Computing gives an excellent example of this technique.

Instead of:


or for rolling back the whole transaction if any insert fails, use:

Photo by Wonderlane

4. Sift Through Page Elements with RJS

One of the incredibly useful aspects of Rails is the built-in support for Javascript and AJAX integrations. They even include a templating language for Javascript called RJS templates. RJS allows the programmer to easily update multiple elements of the page with AJAX.

To take the example a step further, you can use RJS to iterate through page elements and dynamically change them using AJAX. You can even change the elements on the page through CSS queries. For example, you could do something like:

Nifty, eh? Sifting through the elements can be incredibly powerful to use inside your application's interface.

Photo by Phillip Ritz

5. Cache Unchanging Data at Application Startup

Performance may not be a huge issue in the development stages of learning Rails, but eventually you'll want to reach a point where your app is running quickly and smoothly. Caching is an excellent way to speed up an application. RubyInside has an excellent tip on how to cache data that isn't changed often.

"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."

Photo by flydime

6. Practice to Become a Rails Ninja

While it's easy to get started with Rails, it takes work to become a pro. Many times beginning programmers believe that frameworks like Rails take out that learning curve, allowing them to quickly become experts. It never works that way. The Framework is only a tool to help you overcome many of the repetitive tasks associated with Ruby.

Jay Fields knows that mastering Rails isn't easy. In fact he goes on to say the following:

"The screencasts and pictures don't lie. It is easy to learn Rails and quickly become productive. However, the dirty little secret is that it's very hard to be come an expert at utilizing Rails.

"Rails provides many helpers that make your life easy. But, you can't entirely hide the fact that you'll need to be proficient with Ruby, JavaScript, YAML, and SQL. Just like Rails, getting started with any of the above languages is easy, it's mastering them that takes time and effort.

"You should always remember that the biggest aspect of becoming an expert is time and practice. Rails is a great framework, but it can only help you so far without doing any extra learning."

7. Move JavaScript to the Bottom

This is actually a great rule of thumb for just about any language, and it's good to remember if you're just getting started with Rails as well. Moving the Javascript includes to the bottom of the template (right before the

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.