9780596521424
index.html

Rails 3 in a Nutshell

Cody Fauser

James MacAulay

Edward Ocampo-Gooding

John Guenin

This work has been released under the Creative Commons Attribution-Noncommercial license.

Abstract

Note

You are reading the text of an O'Reilly book that's under development. The authors are publishing the book to this site as it's being written, and we're putting it here to get feedback from you. This book uses the Open Feedback Publishing System (OFPS), an O'Reilly experiment that tries to bridge the gap between private manuscripts and public blogs.

Next to every paragraph, there is a link you can use to comment on what you're reading. We are grateful for any feedback you have: questions, comments, suggestions, and corrections are all welcome and appreciated.

Rails in a Nutshell is a concise introduction to Rails, an overview of commands and configurations, and a guide to the parts of Rails you’ll be using every day.

Full of examples and explanations, this book kicks your skills into high-gear by showing you how to take advantage of the Model-View-Controller concept with tiny but expressive bits of Ruby that power some of the world’s biggest and fastest web services.

Fast to launch and a pleasure to get there are hallmarks of working with Rails. Rails in a Nutshell gets the right stuff in your hands quickly and without fuss, so you can experience it yourself.

Follow the progress of the book on Twitter twitter.com/railsnutshell, at railsinanutshell.com, and at the book's catalog page.


1. Preface
Intentions of the authors
2. Rails in a Nutshell
Architecture
Model
View
Controller
Mailer
Web Services
Plugins
Getting Started
Generate a Rails application
Start up your app
Generate a scaffolded resource
Running database migrations
Check out your working application
Setting up a default route
XSS protection
View helpers
Model validations
RSS feeds & request formats
View layouts
Routes
Model associations
Nested resources
Partials
AJAX
The Console
Summary
3. The Core Bits
MVC and Routing
4. Active Model
Attributes
Tracking Changes
Validations
Built-in macros
Callbacks
5. Active Record
Your interfaces to Active Record
The database and its schema
Model definitions
Relations
Record instances
Connecting to a Database
A Model's Names
Developing your Database Schema with Migrations
Type Mapping
Tables
Columns
Manipulating tables
Associations
belongs_to
has_one
Options
Associations as roles
Polymorphic associations
Attributes
Tracking Changes
Validations
When validations don't happen
Built-in macros
Callbacks
Single Table Inheritance
Aggregation
Creating
Finding the records you want
Constructing Relations
scoped
where
select
group & having
order
limit & offset
includes
eager_load
preload
joins
lock
readonly
create_with
from
only & except
Calculations
Updating
Deleting
Named Scopes
Transactions
Dynamic Scopes
Observers
6. Action Controller
Getting Started
Record Identification
Responding to Requests
The HEAD Response
Rendering a Response
Redirecting
Response Headers
Cookies
Working with Cookies
Permanent Cookies
Signed Cookies
Sessions
Using the session
Session Stores
Configuration
Flash
Storing Objects in the Flash
Accessing the Flash from View Templates
Limiting an Object to the Current Request
Keeping the Flash for an Extra Request
Discarding the Flash at the End of the Current Request
Controller Callbacks
Before Filters
After FiltersIncomplete – show example
Around FiltersIncomplete – show example
Defining Filters
Limiting Filters to Particular Actions
Sending FilesIncomplete
7. Routing
Defining Routes
Basic Routing
HTTP Verbs
Named Parameters
Optional Matching
Specifying Defaults for Named Parameters
Constraints
Named Routes
Specifying a root Route
Scopes
Resources
Namespaces
Redirects
test
Generating URIs From Routes
8. Debugging and Testing
First make it correct
9. Testing
Terminology
Unit Tests
Assertions
Test Helper Methods
Fixtures
Functional Tests
View Tests
View Helper Tests
Routing Tests
Integration Tests
Creating an integration test
Integration testing commands
Testing the article workflow
Testing multiple sessions
Extending integration tests with helpers
Stubbing & Mocking
Stubbing a method
Stub & Mock Objects
Running tests
Using rake
Test environment
Debugging within a test
10. Debugging
Logs
Debugger
API testing with Charles the Web debugging proxy
Debugging Javascript with browser tools
Firebug
Safari Web Inspector
Internet Explorer Developer Toolbar
11. Production Environments
Rails Environments
Changing Environments
Server setup
Installing Passenger for Apache
Managing deployments
Common Capistrano tasks
Installing Capistrano
Configuring Capistrano
Server directory structure
Custom Environments
Deployment with JRuby
JRuby Advantages
JRuby Disadvantages
Getting started with JRuby on Rails
Running Rails on GlassFish
Running Multithreaded Rails
Create a Web Application Archive
12. Performance Tuning
Making it go faster
13. Profiling
Where is it slow?
14. Database Tuning
Indexes are awesome
15. Caching
Cache Stores
Using the Cache Store
Caching with Action Controller
Page caching
Action caching
Fragment caching
Cache Sweepers
HTTP Caching
16. Rack
Getting Started
Environment
Middleware
Rackup
run(app)
use(middleware, *args)
map(path){ block }
Using Rack in your Rails Application
The Rails Middleware Stack
Creating Custom Middleware
Installing Middleware
Routing to a Rack Application
17. More Rails
Even more
18. Action Mailer
Sending Email
Mailers
Rendering the Email Body
Creating and Sending Mail
Generating URIs
HTML Email
Adding Attachments
Configuration
SMTP Delivery Options
Sendmail Delivery Options
File Delivery Options
Test Delivery Settings
Receiving Email
19. Active Resource
Background
Client and Server
Web Service Client
Web Service Server
Finding Resources
Finding all resources
Finding a single resource by ID
Finding resources from custom paths
Creating Resources
Creating a resource
Validation and Errors
Updating Resources
Deleting Resource
Making Custom Requests
HTTP Authentication
20. Active Support
MessageVerifier
MessageEncryptor
SecureRandom
Cache
Commonly Used Methods
Storage Implementations
Time, Date, and DateTime
Describing moments in time
Direct time duration manipulation
Is it in the future? Is it today? Is it in the past?
Time Arithmetic
Time Zone Conversions
Formatting Time-like objects
Days in a month
Memoizable
Enumerable
Array
Hash
Range
Numeric
Integer
Float
Callbacks
Base64
Gzip compression & decompression
JSON serialization
XML serialization
NilClass
Inflections
StringInquirer
Module
Class
Object
Multibyte
21. Internationalization
Locale Detection
Locale Persistence
Translation
Regional Locales and Fallbacks
Formatting
Pluralization
Localizing Views
Locale Organization
Backends
What else is out there?
22. Plugins
Installing Plugins
Writing a Plugin
Hooking into Active Record
23. Appendix
Configuration
Configuration
Environments
Action Mailer Configuration
Active Support Cache Store
Rails Initializers
Logging
Configuration
HTTP Status Codes
HTTP Status Code Mapping
Memcached
Installing Memcached
24. Installing Rails
It’s easy
25. Tools
Tools
cURL
26. cURL
It is super handy
27. memcached configuration for fun and profit
Configuration
28. HTTP Status Codes
A list of responses
Site last updated on: February 4, 2012 at 11:31:56 AM PST
Cover for Rails 3 in a Nutshell

View 5 comments

  1. freethinker – Posted Oct. 5, 2010

    are the books docbook sources available?

  2. edward – Posted Oct. 16, 2010

    Hi Pratik,

    The docbook sources are heavily modified by some code-generation tools and other stuff that pieces it all together, so I imagine they wouldn't be that useful.

    Once the first edition is out, ping us again and we'll see if we can figure something out.

  3. smith hogg – Posted June 14, 2011

    Post is nicely written and it contains many good things for me. I am glad to find your impressive way of writing the post. Now it become easy for me to understand and implement the concept.Essay writing

    Edited on June 14, 2011, 3:45 p.m. PDT

  4. mill mrmill – Posted March 7, 2012

    Your blog is great. Your thoughts are also very good and i am very inspired from your post. That is why I visit this blog again and again and will come back in future too.

    Edited on March 7, 2012, 6:17 p.m. PST

  5. auei – Posted today

    I've never considered that surfing can be so much helpful and entertaining. I'm truly happy and grateful for sharing me with this kind of terrific points. Really an excellent page... you are only the best. videos gratis - sex shop - webcam porno - maduras - jovencitas - xxx - videos x - redtube - travestis - porno

Add a comment

View 15 comments

  1. MikeSummers – Posted Oct. 21, 2009

    Will there be an Action View Chapter? A placeholder would be good.

  2. codyfauser – Posted Oct. 21, 2009

    Mike,

    There will be. The incomplete sections are currently not shown, but you're right, it would be good to have the table of contents complete with the entire structure. However, that might also make it frustrating if most parts are empty.

  3. blaix – Posted Oct. 27, 2009

    I think a complete table of contents would help so we're not worried something important might not be covered.

  4. alexbaum – Posted Oct. 28, 2009

    Hi. We would like to translate this book to russian lang, have we rights to do this? We start at http://railstranslate.novarchiv.org, but Wiki is not usable to do this :). Can you recommend any service for open-translate?

    PS: Thanks for this book :)

  5. alexbaum – Posted Oct. 28, 2009

    We are http://translated.by/you/rails-in-a-nutshell/ :)

  6. faisal – Posted Nov. 23, 2009

    Can we get a one-page version of the book (including comments) so we can load it into our Kindles or what have you?

  7. zawaideh – Posted Feb. 6, 2010

    I am unable to post comments next to the paragraphs.. is this the only place to do so?

  8. Constantine – Posted April 21, 2010

    Unable to post individual comments, but on page http://rails-nutshell.labs.oreilly.com/ch01.html#id1978287 it says

    "With the server running in a terminal, vist http://localhost:3000 in a web browser. If everything is working correctly, you should be looking at a web page with some suggestions on how to get started writing your application.

    Follow its advice and use the script/generate command to create

    Looking at the nouns in the project description, it’s clear that a video is going to be a resource this application is going to use. Each video resource will have a title and some HTML embed code."

    Which has a sentence with no end or finishing punctuation.

  9. edward – Posted Oct. 16, 2010

    Hi folks,

    It looks like we missed responding to the questions in this thread. Sorry about that.

    Faisal: Thanks for the tip. The intro’s been updated, but needs another go-over now that Rails 3 is out. (I’ve been writing a few of the other chapters since.)

    Zaid: you should be able to add it to any paragraph. If you can’t, then that’s our fault. Any place in particular where you can’t?

    Constantine: it looks like there

  10. jeromewilson – Posted Nov. 7, 2010

    Attempting to access chapter 1 throws a server error :(

  11. guanxsi – Posted Nov. 7, 2010

    server error in chapter1 for 3 days already

  12. edwardog – Posted Nov. 8, 2010

    Sorry about that – we don’t get exception logs with this setup. It’s fixed now.

    Thanks for taking a look!

  13. Catherine Young – Posted June 24, 2011

    I have never considered that surfing can be so much helpful and entertaining. I'm truly happy and grateful for sharing me with this kind of terrific points. Really an excellent page...you are only the best.

    Edited on June 24, 2011, 3:36 a.m. PDT

  14. Caro Hankmann – Posted Oct. 31, 2011

    Its nice

    Edited on October 31, 2011, 10:28 a.m. PDT

  15. mimim – Posted March 9, 2012

    This chapter seems to be good to know. I already learned some chapters from this.

Add a comment