Installing RVM and Rails OS X Mountain Lion

Installing RVM on OS X Mountain Lion.

1. Install command line tools for XCode.

2. Install RVM with stable ruby.

curl -L | bash -s stable --ruby

3. Source the RVM install.

source /Users/owenbyrne/.rvm/scripts/rvm

4. Verify your RVM install and view installed ruby versions.

rvm list

5. Set your default ruby version (2.0.0 in this case).

rvm --default 2.0.0

6. Install Rails

gem install rails --no-rdoc --no-ri


Ruby on Rails Font Awesome setup

Setting up font awesome with Ruby on Rails is very quick and gives you access to all the font awesome…awesomeness.

Step 1.

Copy the font awesome files to app/assets/font

Step 2.

Add the font directory to the assets path in application.rb

config.assets.paths << Rails.root.join("app", "assets", "fonts")

Step 3.

Modify font-awesome.css as follows

@font-face {
  font-family: 'FontAwesome';
  src: url(/assets/fontawesome-webfont.eot);
  src: url(/assets/fontawesome-webfont.eot?#iefix) format('embedded-opentype'), url(/assets/fontawesome-webfont.woff) format('woff'), url(/assets/fontawesome-webfont.ttf) format('truetype'), url(/assets/fontawesome-webfont.svg#FontAwesome) format('svg');
  font-weight: normal;
  font-style: normal;

Step 4.
Move font-awesome.css to your assets/stylesheets directory and restart the rails server.

Rails Cheat Sheet: Active Record Validations

Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers provide common validation rules.

  • acceptance: validates that a checkbox on the user interface was checked when a form is submitted.
  • validated_associated: ensures valid? is called on associated models.
  • confirmation: ensures two text fields contain exactly the same data. This validation creates a virtual attribute with “_confirmation” appended to the field name. Useful for email and password validations.
  • inclusion: ensures an attribute’s value is within a given set. The set may be an enumerable object.
  • exclusion: ensures an attribute’s value is not within a given set. The set may be an enumerable object.
  • format: ensures an attribute’s value matches a regular expression specified using the :with option.
  • length: ensures an attribute’s value falls within, under, over or is exactly the specified length.
  • numericality: ensures an attribute’s value contains only numeric characters.
  • presence: ensures an attribute’s value is not empty.
  • absence: ensures an attribute’s value is empty.
  • uniqueness: ensures an attribute’s value is unique right before it is saved. It does not create a unique constraint in the database so concurrent connections may create duplicates.
  • validates_with: this helper passes the record to another class for validation.
  • validates_each: this helper validates each attribute against a block.

Check out the documentation for more information.

Rails cheat sheet: Active Record Callbacks

Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic before or after an alteration of the object state.

Here is a list with all the available Active Record callbacks, listed in the same order in which they will get called during the respective operations:

Creating an Object


Updating an Object


Destroying an Object