Rails Coach Charles Max Wood
-
- Technology
Your Playbook for Ruby on Rails
-
-
032 RC CoffeeScript
CoffeeScript is a language written by Jeremy Ashkenas that compiles to Javascript. Its syntax is much more friendly than native JavaScript. Especially if you're used to languages like Ruby or Python.
As or Rails 3.1, CoffeeScript is available by default and a coffeescript file is created in /app/assets/javascripts every time you run the scaffold generator.
A few of my favorite features of the language are:
I can ignore parenthesis (mostly), semi-colons, and curly braces
Function notation
Objects with nested notation
Variable safety (not creating globals)
Splats on lists
Classes
Always returns last expression
String interpolation
I don't like:
Operator aliases
Resources:
CoffeeScript Webpage
CoffeeScript Cookbook
CoffeeScript Basics (video)
CoffeeScript: The Cool Parts (video) -
031 RC Generators
A generator is a way of creating code from the command line. Rails has several of these built in, including generators for models, controllers, tests, helpers, scaffold (models, views, and controllers that support Rails' RESTful routing), and much more.
Generators are actually relatively simple. They are made up of two parts. The generator itself, and the generator's templates. In the Ruby on Rails source code there's an assets generator and the javascript template and stylesheet templates it uses.
I've also created a model generator for my Sandra ORM. You can find it here.
Understanding how models work, you can see how simple it is for the Rails Core Team to build in generators for other things like models, controllers, helpers, tests, assets, mailers, etc.
To see the full list of generators available in a Rails application run `rails generate` or `rails g`.
To create your own generators in your project, put them under /lib/generators or better yet, use the generator for generators like this: `rails generate generator widget` and you'll get a widget generator all set up for you in the /lib/generators folder that's ready for you to customize. -
030 RC NoSQL
NoSQL is a terrible term for a collection of widely varied databases. You have key-value stores like Redis, Tokyo Cabinet, Memcached, etc. You also have document databases like couchDB and mongoDB. Finally you have column based systems like Cassandra. And still others like HBase.
In a lot of cases, there are gems for these. I've used several of them such as the gems for managing Cassandra, couchDB, and mongoDB. -
028 RC Backbone.js
I've been using Backbone.js for a few weeks and really like the way it helps you manage your data on the client side. It's also a terrific way to keep your UI in sync when your data changes through Javascript events.
-
029 RC Ruby-doc.org
One of the most handy websites out there for people trying to find specific API's in Ruby is ruby-doc.org.
From the main page, you can search or select your Ruby version.
From the core page, you can narrow down the class or method you're looking for.
From the std-lib page, you can read docs and see where different aspects of the programming language are implemented.
On each class' page, you can find the specific functionality you need in the menu on the left.