30. • mysql, postgres, redis, memcached and
mongodb
•ruby (1.8.7) with rails and sinatra via
rvm gemsets. (& install Ruby 1.9 with rvm)
•python (2.7) with pip.
•node.js (0.2.0) with npm.
•erlang (R13B04) environment.
... and brew, and probably a lot more by
now.
64. require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Totodo
class Application < Rails::Application
# [With a lot of comments cleaned up]
# Configure generators values.
config.generators do |g|
g.orm :active_record
g.template_engine :haml
g.test_framework :rspec, :fixture => true
end
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
end
end
66. # Robin is going to use haml and rspec:
# Configure generators values.
config.generators do |g|
g.orm :active_record
g.template_engine :haml
g.test_framework :rspec
end
74. # Inside his totodo project folder:
$ ls -al script/
total 8
drwxr-xr-x 3 robin staff 102 Dec 20 01:53 .
drwxr-xr-x 21 robin staff 714 Dec 20 01:55 ..
-rwxr-xr-x 1 robin staff 295 Dec 20 01:53 rails
86. class CreateTodos < ActiveRecord::Migration
def self.up
create_table :todos do |t|
t.string :title
t.datetime :due_date
t.boolean :done
t.timestamps
end
end
def self.down
drop_table :todos
end
end
140. @users = User.where(:approved => true)
# If a params[:order] was passed in,
# add that condition to the query:
@users = @users.order(params[:order])
@users.each do |u|
...
end
141. @users = User.where(:approved => true)
# If a params[:order] was passed in,
# add that condition to the query:
@users = @users.order(params[:order])
@users.each do |u| # Query runs here!
...
end
142. We can even chain the last
page of code together:
146. # Rails 2:
class User < ActiveRecord::Base
named_scope :approved, :conditions => {:approved => true}
end
# Rails 3:
class User < ActiveRecord::Base
scope :approved, where(:approved => true)
end
158. class TodosController < ApplicationController
respond_to :html, :xml, :js
# GET /todos
# GET /todos.xml
def index
respond_with(@todos = Todo.all)
end
end
159. As you can see, respond_to
defines the formats the
Controller responds to