Skip to content

Instantly share code, notes, and snippets.

@dekom
Created March 20, 2012 01:18
Show Gist options
  • Save dekom/2129509 to your computer and use it in GitHub Desktop.
Save dekom/2129509 to your computer and use it in GitHub Desktop.
[NOTES] Ruby on Rails Tutorial

Chapter 3: Static Pages

Layout: Key function used

yield(:title) and provide(:title, 'Home')

stylesheet_link_tag 'application', :media => 'all', javascript_include_tag 'application, csrf_meta_tags

Also, yield in application layout? How does it work?

In rspec: let(:base_title) { "Ruby on Rails Tutorial Sample App"}

Notable gem or plugins

RVM Bundler integration

Guard

Spork

Chapter 5: Filling in the layout

Bootstrap

The Asset Pipeline

Rails 3.1+ offers 3 canonical directories for static assets:

  • app/assets: assets specific to the present application
  • lib/assets: assets for libraries written by your dev team
  • vendor/assets: assets from third-party vendors

Each sub-asset directory separating javascript and stylesheets have a manifest file, telling what files to load, using Sprocket syntax.

Preprocessor engines

Preprocessor engines are run depending on the file extensions in the assets pipeline. The default engines for Rails 3.1+ are Sass, CoffeeScript, and ERB. Engines can be chained by adding engine extensions to the files (right to left evaluation).

RSpec

Notable rspec function used:

  • before
  • subject and shortened it

Chapter 6: Modeling Users

make model's attributes accessible with attr_accessible. Always do this to prevent mass assignment exploits (which happened to Github).

annotate model's attributes with the annotate gem. Make sure the version is at least 2.4.1.beta for it to work with newest release of Rake.

Validation

Read about Rails's validation methods

Secure Password with Authentication

Read about RSpec's syntax and methods, especially the new, less verbose calls.

RSpec's let method:

It "takes a symbol as argument and a block, and creates a local variable with same name as the symbol and its value is the return value of the block.

The magical has_secure_password method. Source code here

This magical method requires the model (and table) to have password_digest as one of the columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment