Multiline Comments in Rails ERB Views

If you want to add multiline comments to your Rails .html.erb Views do the following. The =begin and =end need to be at the beginning of the lines for it to work! Also, you cannot have any ERB code in the =begin and =end blocks, if you comment this way. If you want to comment […]

Ruby File Path Separators

File path separators on Unix systems and Windows are different. On Unix, a forward slash / is used and on Windows a backslash \ is used. However, when writing Ruby code you don’t need to worry about this; Just use the forward slash / character and it will be cross-platform for you. An even better […]

Instance and Class Variable Accessor Methods

When you define classes in Ruby, you must specify what kind of access you want to give Instance and Class attributes/variables which are defined in that class. The way you do it is that you write reader and writer methods. You can write these methods out explicitly or use the shorthand attribute (attr_) methods like […]

Ruby Iterators

Here are some Ruby Iterators and description of how they can be used: times Iterate through the block 3 times, n starts at 0 and ends at 2 and is incremented by 1 each time. n is the block variable. upto Iterate through the block 3 times, starting at 1 and ending at 3, each […]

Old Scaffold Problem on Lynda Ruby on Rails Essential Training

There are a number of people following lynda.com’s Ruby on Rails Essential Training tutorial and running into issues since some of the information in the tutorial is outdated. The method scaffold was removed from Rails 2.0. You can still create scaffolds but must do so by generating the scaffold files explicitly. If you see NoMethodError […]

Creating a MySQL Database from Terminal or Command Line

The following assumes you have a successful installation of MySQL on OS X or Linux: Create MySQL Database To Test the Connection

How to upgrade/update the sqlite3 version on your Mac

First check to see which version of sqlite3 you want to upgrade to and figure out what the URL for the tar ball is. In this example, I want to upgrade to version 3.6.18 Visit SQLite3 Download Page Here is one way to do it:

How to Speed up Rendering pages which include lots of JavaScript

When referencing an external JavaScript file within the head tag of your HTML, the rendering of the page is halted while the external JavaScript file is downloaded and loaded. In order to speed up rendering of the page, you can move your javascript_include_tag from your head tag to the last line within your body tag […]

TextMate Shortcuts Cheatsheet

Navigation → and ← (option right and left arrow) – jump between words → and ← (command right and left arrow) – go to beginning or end of line ↑ and ↓ (option up and down arrow) – jump up and down to beginning and end of same level of indentation section ↑ and ↓ […]

Avoid Duplication of Hash Options

There are lots methods in Rails where the last argument is a Hash. Sometimes the same Hash is passed into more than one method, causing you to repeat yourself. For example, when using validation helpers in your models, you may be doing something like this: Using with_options within a Model: Notice, :on => create is […]