From d1037a473b2099b0a96a0b2aad26f33747da49f8 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 18 Jul 2010 18:02:40 -0400 Subject: [PATCH 01/26] replacing around with for in the comments for callbacks --- activemodel/lib/active_model/callbacks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb index e7aad17021..8c10c54b54 100644 --- a/activemodel/lib/active_model/callbacks.rb +++ b/activemodel/lib/active_model/callbacks.rb @@ -19,7 +19,7 @@ module ActiveModel # # define_model_callbacks :create, :update # - # This will provide all three standard callbacks (before, around and after) around + # This will provide all three standard callbacks (before, around and after) for # both the :create and :update methods. To implement, you need to wrap the methods # you want callbacks on in a block so that the callbacks get a chance to fire: # From bcec0f6528839616cad09374f77014a3969eb63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 19 Jul 2010 12:06:19 +0200 Subject: [PATCH 02/26] correct typos in Routing examples --- actionpack/lib/action_dispatch/routing.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index da62b14f9b..8afc685fdf 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -106,7 +106,7 @@ module ActionDispatch # You can specify a regular expression to define a format for a parameter. # # controller 'geocode' do - # match 'geocode/:postalcode' => :show', :constraints => { + # match 'geocode/:postalcode' => :show, :constraints => { # :postalcode => /\d{5}(-\d{4})?/ # } # @@ -114,13 +114,13 @@ module ActionDispatch # expression modifiers: # # controller 'geocode' do - # match 'geocode/:postalcode' => :show', :constraints => { + # match 'geocode/:postalcode' => :show, :constraints => { # :postalcode => /hx\d\d\s\d[a-z]{2}/i # } # end # # controller 'geocode' do - # match 'geocode/:postalcode' => :show', :constraints => { + # match 'geocode/:postalcode' => :show, :constraints => { # :postalcode => /# Postcode format # \d{5} #Prefix # (-\d{4})? #Suffix From 767de13ff4a19a53d3fe99edb5554040cb6e5e60 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 20 Jul 2010 06:56:20 -0400 Subject: [PATCH 03/26] expanded comment for update_attribute method --- activerecord/lib/active_record/persistence.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 7ec443ccc7..68f5be63d6 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -102,8 +102,15 @@ module ActiveRecord became end - # Updates a single attribute and saves the record without going through the normal validation procedure - # or callbacks. This is especially useful for boolean flags on existing records. + # Updates a single attribute and saves the record. + # This is especially useful for boolean flags on existing records. Also note that + # + # * validation is skipped + # * No callbacks are invoked + # * updated_at/updated_on column is updated if that column is available + # * does not work on associations + # * does not work on attr_accessor attributes. The attribute that is being updated must be column name. + # def update_attribute(name, value) changes = record_update_timestamps || {} From 2e4b741111b93d13b2b19537cf68645aff14c57e Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Tue, 20 Jul 2010 14:22:19 +0200 Subject: [PATCH 04/26] Active Record Validations and Callbacks guide: Fixed typos and rephrased some paragraphs for clarity --- ...ctive_record_validations_callbacks.textile | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 84c33e34f9..be9917868f 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1,22 +1,22 @@ h2. Active Record Validations and Callbacks -This guide teaches you how to hook into the lifecycle 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 lifecycle. +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. After reading this guide and trying out the presented concepts, we hope that you'll be able to: -* Understand the lifecycle of Active Record objects +* Understand the life cycle of Active Record objects * Use the built-in Active Record validation helpers * Create your own custom validation methods * Work with the error messages generated by the validation process -* Create callback methods that respond to events in the object lifecycle +* Create callback methods that respond to events in the object life cycle * Create special classes that encapsulate common behavior for your callbacks -* Create Observers that respond to lifecycle events outside of the original class +* Create Observers that respond to life cycle events outside of the original class endprologue. -h3. The Object Lifecycle +h3. The Object Life Cycle -During the normal operation of a Rails application, objects may be created, updated, and destroyed. Active Record provides hooks into this object lifecycle so that you can control your application and its data. +During the normal operation of a Rails application, objects may be created, updated, and destroyed. Active Record provides hooks into this object life cycle so that you can control your application and its data. 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's state. @@ -57,7 +57,7 @@ We can see how it works by looking at some +rails console+ output: => false -Creating and saving a new record will send an SQL +INSERT+ operation to the database. Updating an existing record will send an SQL +UPDATE+ 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 +INSERT+ or +UPDATE+ 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. +Creating and saving a new record will send a SQL +INSERT+ operation to the database. Updating an existing record will send a SQL +UPDATE+ 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 +INSERT+ or +UPDATE+ 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. CAUTION: 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's possible to save an object in the database in an invalid state if you aren't careful. @@ -838,7 +838,7 @@ This will result in something like the following: h3. Callbacks Overview -Callbacks are methods that get called at certain moments of an object's lifecycle. With callbacks it's possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database. +Callbacks are methods that get called at certain moments of an object's life cycle. With callbacks it's possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database. h4. Callback Registration @@ -984,7 +984,7 @@ h3. Halting Execution As you start registering new callbacks for your models, they will be queued for execution. This queue will include all your model's validations, the registered callbacks, and the database operation to be executed. -The whole callback chain is wrapped in a transaction. If any before callback method returns exactly +false+ or raises an exception the execution chain gets halted and a ROLLBACK is issued. After callbacks can only accomplish that by raising an exception. +The whole callback chain is wrapped in a transaction. If any before callback method returns exactly +false+ or raises an exception the execution chain gets halted and a ROLLBACK is issued; after callbacks can only accomplish that by raising an exception. WARNING. Raising an arbitrary exception may break code that expects +save+ and friends not to fail like that. The +ActiveRecord::Rollback+ exception is thought precisely to tell Active Record a rollback is going on. That one is internally captured but not reraised. @@ -1020,7 +1020,7 @@ Like in validations, we can also make our callbacks conditional, calling them on h4. Using +:if+ and +:unless+ with a Symbol -You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before the callback. If this method returns +false+ the callback won't be executed. This is the most common option. Using this form of registration it's also possible to register several different methods that should be called to check if the callback should be executed. +You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before the callback. When using the +:if+ option, the callback won't be executed if the method returns +false+; when using the +:unless+ option, the callback won't be executed if the method returns +true+. This is the most common option. Using this form of registration it's also possible to register several different methods that should be called to check if the callback should be executed. class Order < ActiveRecord::Base @@ -1135,7 +1135,7 @@ Observers are conventionally placed inside of your +app/models+ directory and re config.active_record.observers = :user_observer -As usual, settings in +config/environments+ take precedence over those in +config/environment.rb+. So, if you prefer that an observer not run in all environments, you can simply register it in a specific environment instead. +As usual, settings in +config/environments+ take precedence over those in +config/environment.rb+. So, if you prefer that an observer doesn't run in all environments, you can simply register it in a specific environment instead. h4. Sharing Observers @@ -1162,6 +1162,7 @@ h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks +* July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. "Jaime Iniesta":http://jaimeiniesta.com * May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com * May 15, 2010: Validation Errors section updated by "Emili ParreƱo":http://www.eparreno.com * March 7, 2009: Callbacks revision by Trevor Turk From 6914d67ed15d41a239407e3c724b670d95a740a6 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Tue, 20 Jul 2010 18:17:29 +0200 Subject: [PATCH 05/26] non-singleton true and false should go on regular font --- .../guides/source/active_record_validations_callbacks.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index be9917868f..c7ba130a90 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1020,7 +1020,7 @@ Like in validations, we can also make our callbacks conditional, calling them on h4. Using +:if+ and +:unless+ with a Symbol -You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before the callback. When using the +:if+ option, the callback won't be executed if the method returns +false+; when using the +:unless+ option, the callback won't be executed if the method returns +true+. This is the most common option. Using this form of registration it's also possible to register several different methods that should be called to check if the callback should be executed. +You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before the callback. When using the +:if+ option, the callback won't be executed if the method returns false; when using the +:unless+ option, the callback won't be executed if the method returns true. This is the most common option. Using this form of registration it's also possible to register several different methods that should be called to check if the callback should be executed. class Order < ActiveRecord::Base From 24c0bc52d260db4146525c6720be0f9be2c5fd0f Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Wed, 21 Jul 2010 17:10:24 +0200 Subject: [PATCH 06/26] Mention that ActionMailer::Base.default_url_options is now deprecated --- actionmailer/lib/action_mailer/base.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 7f2ed5ba64..7bbde53306 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -125,14 +125,13 @@ module ActionMailer #:nodoc: # make sense to generate relative URLs in email messages. # # It is also possible to set a default host that will be used in all mailers by setting the :host - # option in the ActionMailer::Base.default_url_options hash as follows: - # - # ActionMailer::Base.default_url_options[:host] = "example.com" - # - # This can also be set as a configuration option in config/application.rb: + # option as a configuration option in config/application.rb: # # config.action_mailer.default_url_options = { :host => "example.com" } # + # Setting ActionMailer::Base.default_url_options directly is now deprecated, use the configuration + # option mentioned above to set the default host. + # # If you do decide to set a default :host for your mailers you will want to use the # :only_path => false option when using url_for. This will ensure that absolute URLs are # generated because the url_for view helper will, by default, generate relative URLs when a From 680f0459a3a4fe59b215d26c2de03f963c2c29ee Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Wed, 21 Jul 2010 19:21:05 +0200 Subject: [PATCH 07/26] doc: form_for does return output rather than merely evaluate its block --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 711c455ded..b8c163e1c2 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -150,10 +150,6 @@ module ActionView # here a named route directly as well. Defaults to the current action. # * :html - Optional HTML attributes for the form tag. # - # Worth noting is that the +form_for+ tag is called in a ERb evaluation - # block, not an ERb output block. So that's <% %>, not - # <%= %>. - # # Also note that +form_for+ doesn't create an exclusive scope. It's still # possible to use both the stand-alone FormHelper methods and methods # from FormTagHelper. For example: From b2818b24725e5bc468af8ef870c21f4098b20822 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 22 Jul 2010 00:16:26 +0200 Subject: [PATCH 08/26] routing guide: a "photo" resource has by convention paths under "photos", in plural --- railties/guides/source/routing.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 72a76e25bb..ae80ba77e4 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -441,13 +441,13 @@ h4. Segment Constraints You can use the +:constraints+ option to enforce a format for a dynamic segment: -match 'photo/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ } +match 'photos/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ } -This route would match URLs such as +/photo/A12345+. You can more succinctly express the same route this way: +This route would match URLs such as +/photos/A12345+. You can more succinctly express the same route this way: -match 'photo/:id' => 'photos#show', :id => /[A-Z]\d{5}/ +match 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ +:constraints+ takes regular expression. However note that regexp anchors can't be used within constraints. For example following route will not work: @@ -472,7 +472,7 @@ You can also constrain a route based on any method on the {:subdomain => "admin"} +match "photos", :constraints => {:subdomain => "admin"} You can also specify constrains in a block form: @@ -511,10 +511,10 @@ h4. Route Globbing Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example -match 'photo/*other' => 'photos#unknown' +match 'photos/*other' => 'photos#unknown' -This route would match +photo/12+ or +/photo/long/path/to/12+, setting +params[:other]+ to +"12"+ or +"long/path/to/12"+. +This route would match +photos/12+ or +/photos/long/path/to/12+, setting +params[:other]+ to +"12"+ or +"long/path/to/12"+. h4. Redirection From 5cba6635787ed65a420d48ea0e93ff4af2ba59f2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 22 Jul 2010 00:32:39 +0200 Subject: [PATCH 09/26] routing guide: say "path" when you mean path --- railties/guides/source/routing.textile | 72 +++++++++++++------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index ae80ba77e4..7e6d6b5b34 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -5,14 +5,14 @@ This guide covers the user-facing features of Rails routing. By referring to thi * Understand the code in +routes.rb+ * Construct your own routes, using either the preferred resourceful style or with the @match@ method * Identify what parameters to expect an action to receive -* Automatically create URLs using route helpers +* Automatically create paths and URLs using route helpers * Use advanced techniques such as constraints and Rack endpoints endprologue. h3. The Purpose of the Rails Router -The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate URLs, avoiding the need to hardcode URL strings in your views. +The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views. h4. Connecting URLs to Code @@ -30,9 +30,9 @@ match "/patients/:id" => "patients#show" the request is dispatched to the +patients+ controller's +show+ action with { :id => "17" } in +params+. -h4. Generating URLs from Code +h4. Generating Paths and URLs from Code -You can also generate URLs. If your application contains this code: +You can also generate paths and URLs. If your application contains this code: @patient = Patient.find(17) @@ -76,7 +76,7 @@ resources :photos creates seven different routes in your application, all mapping to the +Photos+ controller: -|_. Verb |_.URL |_.action |_.used for| +|_. Verb |_.Path |_.action |_.used for| |GET |/photos |index |display a list of all photos| |GET |/photos/new |new |return an HTML form for creating a new photo| |POST |/photos |create |create a new photo| @@ -85,7 +85,7 @@ creates seven different routes in your application, all mapping to the +Photos+ |PUT |/photos/:id |update |update a specific photo| |DELETE |/photos/:id |destroy |delete a specific photo| -h4. URLs and Paths +h4. Paths and URLs Creating a resourceful route will also expose a number of helpers to the controllers in your application. In the case of +resources :photos+: @@ -130,7 +130,7 @@ resource :geocoder creates six different routes in your application, all mapping to the +Geocoders+ controller: -|_. Verb |_.URL |_.action |_.used for| +|_. Verb |_.Path |_.action |_.used for| |GET |/geocoder/new |new |return an HTML form for creating the geocoder| |POST |/geocoder |create |create the new geocoder| |GET |/geocoder |show |display the one and only geocoder resource| @@ -160,7 +160,7 @@ end This will create a number of routes for each of the +posts+ and +comments+ controller. For +Admin::PostsController+, Rails will create: -|_. Verb |_.URL |_.action |_. helper | +|_. Verb |_.Path |_.action |_. helper | |GET |/admin/photos |index | admin_photos_path | |GET |/admin/photos/new |new | new_admin_photos_path | |POST |/admin/photos |create | admin_photos_path | @@ -197,16 +197,16 @@ or, for a single case resources :posts, :path => "/admin" -In each of these cases, the named routes remain the same as if you did not use +scope+. In the last case, the following URLs map to +PostsController+: +In each of these cases, the named routes remain the same as if you did not use +scope+. In the last case, the following paths map to +PostsController+: -|_. Verb |_.URL |_.action |_. helper | -|GET |photos |index | photos_path | -|GET |photos/new |new | photos_path | -|POST |photos |create | photos_path | -|GET |photos/1 |show | photo_path(id) | -|GET |photos/1/edit |edit | edit_photo_path(id) | -|PUT |photos/1 |update | photo_path(id) | -|DELETE |photos/1 |destroy | photo_path(id) | +|_. Verb |_.Path |_.action |_. helper | +|GET |/admin/photos |index | photos_path | +|GET |/admin/photos/new |new | photos_path | +|POST |/admin/photos |create | photos_path | +|GET |/admin/photos/1 |show | photo_path(id) | +|GET |/admin/photos/1/edit |edit | edit_photo_path(id) | +|PUT |/admin/photos/1 |update | photo_path(id) | +|DELETE |/admin/photos/1 |destroy | photo_path(id) | h4. Nested Resources @@ -232,7 +232,7 @@ end In addition to the routes for magazines, this declaration will also route ads to an +AdsController+. The ad URLs require a magazine: -|_.Verb |_.URL |_.action |_.used for| +|_.Verb |_.Path |_.action |_.used for| |GET |/magazines/1/ads |index |display a list of all ads for a specific magazine| |GET |/magazines/1/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine| |POST |/magazines/1/ads |create |create a new ad belonging to a specific magazine| @@ -256,7 +256,7 @@ resources :publishers do end -Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as +Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize paths such as
 /publishers/1/magazines/2/photos/3
@@ -266,9 +266,9 @@ The corresponding route helper would be +publisher_magazine_photo_url+, requirin
 
 TIP: _Resources should never be nested more than 1 level deep._
 
-h4. Creating URLs From Objects
+h4. Creating Paths and URLs From Objects
 
-In addition to using the routing helpers, Rails can also create URLs from an array of parameters. For example, suppose you have this set of routes:
+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:
 
 
 resources :magazines do
@@ -340,7 +340,7 @@ resources :photos do
 end
 
 
-This will enable Rails to recognize URLs such as +/photos/search+ with GET, and route to the +search+ action of +PhotosController+. It will also create the +search_photos_url+ and +search_photos_path+ route helpers.
+This will enable Rails to recognize paths such as +/photos/search+ with GET, and route to the +search+ action of +PhotosController+. It will also create the +search_photos_url+ and +search_photos_path+ route helpers.
 
 Just as with member routes, you can pass +:on+ to a route:
 
@@ -380,7 +380,7 @@ You can set up as many dynamic segments within a regular route as you like. Anyt
 match ':controller/:action/:id/:user_id'
 
 
-An incoming URL of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+.
+An incoming path of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+.
 
 NOTE: You can't use +namespace+ or +:module+ with a +:controller+ path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g:
 
@@ -396,7 +396,7 @@ You can specify static segments when creating a route:
 match ':controller/:action/:id/with_user/:user_id'
 
 
-This route would respond to URLs such as +/photos/show/1/with_user/2+. In this case, +params+ would be { :controller => "photos", :action => "show", :id => "1", :user_id => "2" }.
+This route would respond to paths such as +/photos/show/1/with_user/2+. In this case, +params+ would be { :controller => "photos", :action => "show", :id => "1", :user_id => "2" }.
 
 h4. The Query String
 
@@ -406,7 +406,7 @@ The +params+ will also include any parameters from the query string. For example
 match ':controller/:action/:id'
 
 
-An incoming URL of +/photos/show/1?user_id=2+ will be dispatched to the +show+ action of the +Photos+ controller. +params+ will be { :controller => "photos", :action => "show", :id => "1", :user_id => "2" }.
+An incoming path of +/photos/show/1?user_id=2+ will be dispatched to the +show+ action of the +Photos+ controller. +params+ will be { :controller => "photos", :action => "show", :id => "1", :user_id => "2" }.
 
 h4. Defining Defaults
 
@@ -416,7 +416,7 @@ You do not need to explicitly use the +:controller+ and +:action+ symbols within
 match 'photos/:id' => 'photos#show'
 
 
-With this route, Rails will match an incoming URL of +/photos/12+ to the +show+ action of  +PhotosController+.
+With this route, Rails will match an incoming path of +/photos/12+ to the +show+ action of  +PhotosController+.
 
 You can also define other defaults in a route by supplying a hash for the +:defaults+ option. This even applies to parameters that you do not specify as dynamic segments. For example:
 
@@ -444,7 +444,7 @@ You can use the +:constraints+ option to enforce a format for a dynamic segment:
 match 'photos/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ }
 
 
-This route would match URLs such as +/photos/A12345+. You can more succinctly express the same route this way:
+This route would match paths such as +/photos/A12345+. You can more succinctly express the same route this way:
 
 
 match 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/
@@ -573,9 +573,9 @@ The +:controller+ option lets you explicitly specify a controller to use for the
 resources :photos, :controller => "images"
 
 
-will recognize incoming URLs beginning with +/photo+ but route to the +Images+ controller:
+will recognize incoming paths beginning with +/photo+ but route to the +Images+ controller:
 
-|_. Verb |_.URL          |_.action |
+|_. Verb |_.Path         |_.action |
 |GET     |/photos        |index    |
 |GET     |/photos/new    |new      |
 |POST    |/photos        |create   |
@@ -584,7 +584,7 @@ will recognize incoming URLs beginning with +/photo+ but route to the +Images+ c
 |PUT     |/photos/1      |update   |
 |DELETE  |/photos/1      |destroy  |
 
-NOTE: Use +photos_path+, +new_photos_path+, etc. to generate URLs for this resource.
+NOTE: Use +photos_path+, +new_photos_path+, etc. to generate paths for this resource.
 
 h4. Specifying Constraints
 
@@ -615,9 +615,9 @@ The +:as+ option lets you override the normal naming for the named route helpers
 resources :photos, :as => "images"
 
 
-will recognize incoming URLs beginning with +/photos+ and route the requests to +PhotosController+:
+will recognize incoming paths beginning with +/photos+ and route the requests to +PhotosController+:
 
-|_.HTTP verb|_.URL           |_.action |_.named helper   |
+|_.HTTP verb|_.Path          |_.action |_.named helper   |
 |GET        |/photos         |index    | images_path     |
 |GET        |/photos/new     |new      | new_image_path  |
 |POST       |/photos         |create   | images_path     |
@@ -628,20 +628,20 @@ will recognize incoming URLs beginning with +/photos+ and route the requests to
 
 h4. Overriding the +new+ and +edit+ Segments
 
-The +:path_names+ option lets you override the automatically-generated "new" and "edit" segments in URLs:
+The +:path_names+ option lets you override the automatically-generated "new" and "edit" segments in paths:
 
 
 resources :photos, :path_names => { :new => 'make', :edit => 'change' }
 
 
-This would cause the routing to recognize URLs such as
+This would cause the routing to recognize paths such as
 
 
 /photos/make
 /photos/1/change
 
 
-NOTE: The actual action names aren't changed by this option. The two URLs shown would still route to the new and edit actions.
+NOTE: The actual action names aren't changed by this option. The two paths shown would still route to the +new+ and +edit+ actions.
 
 TIP: If you find yourself wanting to change this option uniformly for all of your routes, you can use a scope:
 
@@ -709,7 +709,7 @@ end
 
 Rails now creates routes to the +CategoriesControlleR+.
 
-|_.HTTP verb|_.URL                      |_.action |
+|_.HTTP verb|_.Path                     |_.action |
 |GET        |/kategorien                |index    |
 |GET        |/kategorien/neu            |new      |
 |POST       |/kategorien                |create   |

From 56669ec3048de316918ec5ad554fff83d757911b Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Thu, 22 Jul 2010 01:27:02 +0200
Subject: [PATCH 10/26] camelize and underscore are sort of inverse of each
 other, but not in a mathematical sense [#5174 state:resolved]

---
 .../lib/active_support/inflector/methods.rb          | 12 +++++++++++-
 .../source/active_support_core_extensions.textile    |  6 +++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index b3dc5b2f3a..de49750083 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -20,6 +20,11 @@ module ActiveSupport
     #   "active_record".camelize(:lower)        # => "activeRecord"
     #   "active_record/errors".camelize         # => "ActiveRecord::Errors"
     #   "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
+    #
+    # As a rule of thumb you can think of +camelize+ as the inverse of +underscore+,
+    # though there are cases where that does not hold:
+    #
+    #   "SSLError".underscore.camelize # => "SslError"
     def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
       if first_letter_in_uppercase
         lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
@@ -28,13 +33,18 @@ module ActiveSupport
       end
     end
 
-    # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
+    # Makes an underscored, lowercase form from the expression in the string.
     #
     # Changes '::' to '/' to convert namespaces to paths.
     #
     # Examples:
     #   "ActiveRecord".underscore         # => "active_record"
     #   "ActiveRecord::Errors".underscore # => active_record/errors
+    #
+    # As a rule of thumb you can think of +underscore+ as the inverse of +camelize+,
+    # though there are cases where that does not hold:
+    #
+    #   "SSLError".underscore.camelize # => "SslError"
     def underscore(camel_cased_word)
       word = camel_cased_word.to_s.dup
       word.gsub!(/::/, '/')
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index a0ed8d6a90..297dad2ccc 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1469,13 +1469,15 @@ end
 
 That may be handy to compute method names in a language that follows that convention, for example JavaScript.
 
+INFO: As a rule of thumb you can think of +camelize+ as the inverse of +underscore+, though there are cases where that does not hold: "SSLError".underscore.camelize gives back "SslError".
+
 +camelize+ is aliased to +camelcase+.
 
 NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
 
 h5. +underscore+
 
-The method +underscore+ is the inverse of +camelize+, explained above:
+The method +underscore+ goes the other way around, from camel case to paths:
 
 
 "Product".underscore   # => "product"
@@ -1508,6 +1510,8 @@ def load_missing_constant(from_mod, const_name)
 end
 
 
+INFO: As a rule of thumb you can think of +underscore+ as the inverse of +camelize+, though there are cases where that does not hold. For example, "SSLError".underscore.camelize gives back "SslError".
+
 NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
 
 h5. +titleize+

From 4ed9bd6431d1733d83de0b461280f77f78a9c4c6 Mon Sep 17 00:00:00 2001
From: Bobby Wilson 
Date: Wed, 21 Jul 2010 20:34:00 -0700
Subject: [PATCH 11/26] Changed code style that was incorrectly rendering block
 style instead of inline.

---
 railties/guides/source/routing.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index 7e6d6b5b34..7b665d81e7 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -3,7 +3,7 @@ h2. Rails Routing from the Outside In
 This guide covers the user-facing features of Rails routing. By referring to this guide, you will be able to:
 
 * Understand the code in +routes.rb+
-* Construct your own routes, using either the preferred resourceful style or with the @match@ method
+* Construct your own routes, using either the preferred resourceful style or with the match method
 * Identify what parameters to expect an action to receive
 * Automatically create paths and URLs using route helpers
 * Use advanced techniques such as constraints and Rack endpoints

From 89b5e79632c4f0b18099faa846e45741b7c5e700 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mislav=20Marohni=C4=87?= 
Date: Sun, 18 Jul 2010 14:58:40 +0200
Subject: [PATCH 12/26] revise download/installation/support sections in
 READMEs

 - don't reference ancient gem versions
 - don't link to old API doc subdomains
 - point to GitHub instead of RubyForge
 - point to Lighthouse account for support
---
 actionmailer/README.rdoc  | 33 ++++++++++++++++++++-------------
 actionpack/README.rdoc    | 20 ++++++++++----------
 activerecord/README.rdoc  | 20 +++++++++-----------
 activesupport/README.rdoc | 29 ++++++++++++++---------------
 4 files changed, 53 insertions(+), 49 deletions(-)

diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc
index 3dd56a6fd8..1b9cb8a570 100644
--- a/actionmailer/README.rdoc
+++ b/actionmailer/README.rdoc
@@ -121,31 +121,38 @@ The Base class has the full list of configuration options. Here's an example:
 
 == Dependencies
 
-Action Mailer requires that the Action Pack is either available to be required immediately
-or is accessible as a GEM.
+Action Mailer depends on Action Pack.
 
-Additionally, Action Mailer requires the Mail gem, http://github.com/mikel/mail
+Additionally, Action Mailer requires the {Mail gem}[http://github.com/mikel/mail].
 
-== Download
+== Bundled software
+
+* Text::Format 0.63 by Austin Ziegler released under OpenSource
+  Read more on http://www.halostatue.ca/ruby/Text__Format.html
+
+
+== Download and installation
 
 The latest version of Action Mailer can be installed with Rubygems:
 
-* gem install actionmailer
+  % [sudo] gem install actionmailer
 
-Documentation can be found at 
+Source code can be downloaded as part of the Rails project on GitHub
+
+* http://github.com/rails/rails/tree/master/actionmailer/
 
-* http://api.rubyonrails.org
 
 == License
 
 Action Mailer is released under the MIT license.
 
+
 == Support
 
-The Action Mailer homepage is http://www.rubyonrails.org. You can find
-the Action Mailer RubyForge page at http://rubyforge.org/projects/actionmailer.
-And as Jim from Rake says:
+API documentation is at
 
-   Feel free to submit commits or feature requests.  If you send a patch,
-   remember to update the corresponding unit tests.  If fact, I prefer
-   new feature to be submitted in the form of new unit tests.
+* http://api.rubyonrails.com
+
+Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
+
+* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets
diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc
index 272feb63d0..7294e7f2d4 100644
--- a/actionpack/README.rdoc
+++ b/actionpack/README.rdoc
@@ -355,15 +355,15 @@ new model). After creating the post, it'll redirect to the show page using
 an URL such as /weblog/5 (where 5 is the id of the post).
 
 
-== Download
+== Download and installation
 
 The latest version of Action Pack can be installed with Rubygems:
 
-* gem install actionpack
+  % [sudo] gem install actionpack
 
-Documentation can be found at 
+Source code can be downloaded as part of the Rails project on GitHub
 
-* http://api.rubyonrails.org
+* http://github.com/rails/rails/tree/master/actionpack/
 
 
 == License
@@ -373,10 +373,10 @@ Action Pack is released under the MIT license.
 
 == Support
 
-The Action Pack homepage is http://www.rubyonrails.org. You can find
-the Action Pack RubyForge page at http://rubyforge.org/projects/actionpack.
-And as Jim from Rake says:
+API documentation is at
 
-   Feel free to submit commits or feature requests.  If you send a patch,
-   remember to update the corresponding unit tests.  If fact, I prefer
-   new feature to be submitted in the form of new unit tests.
+* http://api.rubyonrails.com
+
+Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
+
+* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets
diff --git a/activerecord/README.rdoc b/activerecord/README.rdoc
index 0446180207..efa3c7e7ac 100644
--- a/activerecord/README.rdoc
+++ b/activerecord/README.rdoc
@@ -307,15 +307,15 @@ Admit the Database:
 * Doesn't attempt to duplicate or replace data definitions
 
 
-== Download
+== Download and installation
 
 The latest version of Active Record can be installed with Rubygems:
 
-* gem install activerecord
+  % [sudo] gem install activerecord
 
-Documentation can be found at 
+Source code can be downloaded as part of the Rails project on GitHub
 
-* http://api.rubyonrails.org
+* http://github.com/rails/rails/tree/master/activerecord/
 
 
 == License
@@ -325,12 +325,10 @@ Active Record is released under the MIT license.
 
 == Support
 
-The Active Record homepage is http://www.rubyonrails.com. You can find the Active Record
-RubyForge page at http://rubyforge.org/projects/activerecord. And as Jim from Rake says:
+API documentation is at
 
-   Feel free to submit commits or feature requests.  If you send a patch,
-   remember to update the corresponding unit tests.  If fact, I prefer
-   new feature to be submitted in the form of new unit tests.
+* http://api.rubyonrails.com
 
-For other information, feel free to ask on the rubyonrails-talk 
-(http://groups.google.com/group/rubyonrails-talk) mailing list.
+Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
+
+* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets
diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc
index aa86f1fd65..77b8a64304 100644
--- a/activesupport/README.rdoc
+++ b/activesupport/README.rdoc
@@ -1,19 +1,20 @@
-= Active Support -- Utility classes and standard library extensions from Rails
+= Active Support -- Utility classes and Ruby extensions from Rails
 
-Active Support is a collection of various utility classes and standard library extensions that were found useful
-for Rails. All these additions have hence been collected in this bundle as way to gather all that sugar that makes
-Ruby sweeter.
+Active Support is a collection of utility classes and standard library
+extensions that were found useful for the Rails framework. These additions
+reside in this package so they can be loaded as needed in Ruby projects
+outside of Rails.
 
 
-== Download
+== Download and installation
 
 The latest version of Active Support can be installed with Rubygems:
 
-* gem install activesupport
+  % [sudo] gem install activesupport
 
-Documentation can be found at 
+Source code can be downloaded as part of the Rails project on GitHub
 
-* http://api.rubyonrails.org
+* http://github.com/rails/rails/tree/master/activesupport/
 
 
 == License
@@ -23,12 +24,10 @@ Active Support is released under the MIT license.
 
 == Support
 
-The Active Support homepage is http://www.rubyonrails.com. You can find the Active Support
-RubyForge page at http://rubyforge.org/projects/activesupport. And as Jim from Rake says:
+API documentation is at
 
-   Feel free to submit commits or feature requests.  If you send a patch,
-   remember to update the corresponding unit tests.  If fact, I prefer
-   new feature to be submitted in the form of new unit tests.
+* http://api.rubyonrails.com
 
-For other information, feel free to ask on the ruby-talk mailing list
-(which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com.
+Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
+
+* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets

From a1023b0bf0508378e8e6fcb68f83d87a7981faf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mislav=20Marohni=C4=87?= 
Date: Mon, 19 Jul 2010 13:51:04 +0200
Subject: [PATCH 13/26] improve Action Pack README

 - revise introductory text
 - list modules contained in the package
 - improve examples
 - remove obsolete `scaffold` and `form` examples
---
 actionpack/README.rdoc | 150 +++++++++++++++--------------------------
 1 file changed, 55 insertions(+), 95 deletions(-)

diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc
index 7294e7f2d4..0e7d164623 100644
--- a/actionpack/README.rdoc
+++ b/actionpack/README.rdoc
@@ -1,25 +1,35 @@
-= Action Pack -- On rails from request to response
+= Action Pack -- From request to response
 
-Action Pack splits the response to a web request into a controller part
-(performing the logic) and a view part (rendering a template). This two-step
-approach is known as an action, which will normally create, read, update, or
-delete (CRUD for short) some sort of model part (often backed by a database)
-before choosing either to render a template or redirecting to another action.
+Action Pack is a framework for handling and responding to web requests. It it
+provides mechanisms for *routing* (mapping request URLs to actions), defining
+*controllers* that implement actions, and generating responses by rendering
+*views*, which are templates of various formats. In short, Action Pack
+provides the view and controller layers in the MVC paradigm.
 
-Action Pack implements these actions as public methods on Action Controllers
-and uses Action Views to implement the template rendering. Action Controllers
-are then responsible for handling all the actions relating to a certain part
-of an application. This grouping usually consists of actions for lists and for
-CRUDs revolving around a single (or a few) model objects. So ContactsController
-would be responsible for listing contacts, creating, deleting, and updating
-contacts. A WeblogController could be responsible for both posts and comments.
+It consists of several modules:
 
-Action View templates are written using embedded Ruby in tags mingled in with
-the HTML. To avoid cluttering the templates with code, a bunch of helper
-classes provide common behavior for forms, dates, and strings. And it's easy
-to add specific helpers to keep the separation as the application evolves.
+* Action Dispatch, which parses information about the web request, handles
+  routing as defined by the user, and does advanced processing related to HTTP
+  such as MIME-type negotiation, decoding parameters in POST/PUT bodies,
+  handling HTTP caching logic, cookies and sessions.
 
-A short rundown of the major features:
+* Action Controller, which provides a base controller class that can be
+  subclassed to implement filters and actions to handle requests. The result
+  of an action is typically content generated from views.
+
+* Action View, which handles view template lookup and rendering, and provides
+  view helpers that assist when building HTML forms, Atom feeds and more.
+  Template formats that Action View handles are ERb (embedded Ruby, typically
+  used to inline short Ruby snippets inside HTML), XML Builder and RJS
+  (dynamically generated JavaScript from Ruby code).
+
+With the Ruby on Rails framework, users only directly interface with the
+Action Controller module. Necessary Action Dispatch functionality is activated
+by default and Action View rendering is implicitly triggered by Action
+Controller. However, these modules are designed to function on their own and
+can be used outside of Rails.
+
+A short rundown of some of the major features:
 
 * Actions grouped in controller as methods instead of separate command objects
   and can therefore share helper methods
@@ -31,26 +41,29 @@ A short rundown of the major features:
 
       def update
         @customer = find_customer
-        @customer.attributes = params[:customer]
-        @customer.save ?
-          redirect_to(:action => "show") :
-          render(:action => "edit")
+        if @customer.update_attributes(params[:customer])
+          redirect_to :action => "show"
+        else
+          render :action => "edit"
+        end
       end
 
       private
-        def find_customer() Customer.find(params[:id]) end
+        def find_customer
+          Customer.find params[:id]
+        end
     end
 
   {Learn more}[link:classes/ActionController/Base.html]
 
 
-* Embedded Ruby for templates (no new "easy" template language)
+* ERb templates (static content mixed with dynamic output from ruby)
 
     <% for post in @posts %>
       Title: <%= post.title %>
     <% end %>
 
-    All post titles: <%= @posts.collect{ |p| p.title }.join ", " %>
+    All post titles: <%= @posts.collect{ |p| p.title }.join(", ") %>
 
     <% unless @person.is_client? %>
       Not for clients to see...
@@ -59,7 +72,7 @@ A short rundown of the major features:
   {Learn more}[link:classes/ActionView.html]
 
 
-* Builder-based templates (great for XML content, like RSS)
+* "Builder" templates (great for XML content, like RSS)
 
     xml.rss("version" => "2.0") do
       xml.channel do
@@ -84,11 +97,16 @@ A short rundown of the major features:
   {Learn more}[link:classes/ActionView/Base.html]
 
 
-* Filters for pre and post processing of the response (as methods, procs, and classes)
+* Filters for pre- and post-processing of the response
 
     class WeblogController < ActionController::Base
+      # filters as methods
       before_filter :authenticate, :cache, :audit
+      
+      # filter as a proc
       after_filter { |c| c.response.body = Gzip::compress(c.response.body) }
+      
+      # class filter
       after_filter LocalizeFilter
 
       def index
@@ -111,16 +129,14 @@ A short rundown of the major features:
 
 * Helpers for forms, dates, action links, and text
 
-    <%= text_field "post", "title", "size" => 30 %>
-    <%= html_date_select(Date.today) %>
+    <%= text_field_tag "post", "title", "size" => 30 %>
     <%= link_to "New post", :controller => "post", :action => "new" %>
     <%= truncate(post.title, :length => 25) %>
 
   {Learn more}[link:classes/ActionView/Helpers.html]
 
 
-* Layout sharing for template reuse (think simple version of Struts
-  Tiles[http://jakarta.apache.org/struts/userGuide/dev_tiles.html])
+* Layout sharing for template reuse
 
     class WeblogController < ActionController::Base
       layout "weblog_layout"
@@ -141,22 +157,22 @@ A short rundown of the major features:
   {Learn more}[link:classes/ActionController/Layout/ClassMethods.html]
 
 
-* Routing makes pretty urls incredibly easy
+* Routing makes pretty URLs incredibly easy
 
-    map.connect 'clients/:client_name/:project_name/:controller/:action'
+    match 'clients/:client_name/:project_name/:controller/:action'
 
-    Accessing /clients/37signals/basecamp/project/dash calls ProjectController#dash with
-    { "client_name" => "37signals", "project_name" => "basecamp" } in params[:params]
+    Accessing "/clients/37signals/basecamp/project/index" calls ProjectController#index with
+    { "client_name" => "37signals", "project_name" => "basecamp" } in `params`
 
-    From that URL, you can rewrite the redirect in a number of ways:
+    From that action, you can write the redirect in a number of ways:
 
     redirect_to(:action => "edit") =>
-      /clients/37signals/basecamp/project/dash
+      /clients/37signals/basecamp/project/edit
 
     redirect_to(:client_name => "nextangle", :project_name => "rails") =>
-      /clients/nextangle/rails/project/dash
+      /clients/nextangle/rails/project/index
 
-  {Learn more}[link:classes/ActionController/Base.html]
+  {Learn more}[link:classes/ActionDispatch/Routing.html]
 
 
 * Easy testing of both controller and rendered template through ActionController::TestCase
@@ -233,62 +249,6 @@ A short rundown of the major features:
   {Learn more}[link:classes/ActionController/Rescue.html]
 
 
-* Scaffolding for Active Record model objects
-
-    class AccountController < ActionController::Base
-      scaffold :account
-    end
-
-    The AccountController now has the full CRUD range of actions and default
-    templates: list, show, destroy, new, create, edit, update
-
-  {Learn more}[link:classes/ActionController/Scaffolding/ClassMethods.html]
-
-
-* Form building for Active Record model objects
-
-    The post object has a title (varchar), content (text), and
-    written_on (date)
-
-    <%= form "post" %>
-
-    ...will generate something like (the selects will have more options, of
-    course):
-
-    
-

- Title:
- -

-

- Content:
- -

-

- Written on:
- - - -

- - -
- - This form generates a params[:post] array that can be used directly in a save action: - - class WeblogController < ActionController::Base - def create - post = Post.create(params[:post]) - redirect_to :action => "show", :id => post.id - end - end - - {Learn more}[link:classes/ActionView/Helpers/ActiveRecordHelper.html] - - -* Runs on top of WEBrick, Mongrel, CGI, FCGI, and mod_ruby - - == Simple example (from outside of Rails) This example will implement a simple weblog system using inline templates and From d5ee17ed200a4cb0481e99c4d40d9b584418a520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 19 Jul 2010 13:55:18 +0200 Subject: [PATCH 14/26] improve Active Record README - revise introductory text - improve examples - don't claim that Oracle, SQL Server, or DB2 are supported - remove lengthy "simple example" --- activerecord/README.rdoc | 224 ++++++++++----------------------------- 1 file changed, 56 insertions(+), 168 deletions(-) diff --git a/activerecord/README.rdoc b/activerecord/README.rdoc index efa3c7e7ac..8dbd6c82b5 100644 --- a/activerecord/README.rdoc +++ b/activerecord/README.rdoc @@ -1,49 +1,52 @@ -= Active Record -- Object-relation mapping put on rails += Active Record -- Object-relational mapping put on rails -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[http://www.martinfowler.com/eaaCatalog/activeRecord.html] -by the same name as described by Martin Fowler: +Active Record connects classes to relational database tables to establish an +almost zero-configuration persistence layer for applications. The library +provides a base class that, when subclassed, sets up a mapping between the new +class and an existing table in the database. In context of an application, +these classes are commonly referred to as *models*. Models can also be +connected to other models; this is done by defining *associations*. - "An object that wraps a row in a database table or view, encapsulates - the database access, and adds domain logic on that data." +Active Record relies heavily on naming in that it uses class and association +names to establish mappings between respective database tables and foreign key +columns. Although these mappings can be defined explicitly, it's recommended +to follow naming conventions, especially when getting started with the +library. -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. - -A short rundown of the major features: +A short rundown of some of the major features: * Automated mapping between classes and tables, attributes and columns. - class Product < ActiveRecord::Base; end + class Product < ActiveRecord::Base + end - ...is automatically mapped to the table named "products", such as: + The Product class is automatically mapped to the table named "products", + which might look like this: CREATE TABLE products ( id int(11) NOT NULL auto_increment, name varchar(255), PRIMARY KEY (id) ); - - ...which again gives Product#name and Product#name=(new_name) + + This would also define the following accessors: `Product#name` and + `Product#name=(new_name)` {Learn more}[link:classes/ActiveRecord/Base.html] -* Associations between objects controlled by simple meta-programming macros. +* Associations between objects defined by simple class methods. class Firm < ActiveRecord::Base has_many :clients has_one :account - belongs_to :conglomorate + belongs_to :conglomerate end {Learn more}[link:classes/ActiveRecord/Associations/ClassMethods.html] -* Aggregations of value objects controlled by simple meta-programming macros. +* Aggregations of value objects. class Account < ActiveRecord::Base composed_of :balance, :class_name => "Money", @@ -65,23 +68,19 @@ A short rundown of the major features: end {Learn more}[link:classes/ActiveRecord/Validations.html] - -* Callbacks as methods or queues on the entire lifecycle (instantiation, saving, destroying, validating, etc). + + +* Callbacks available for the entire lifecycle (instantiation, saving, destroying, validating, etc.) class Person < ActiveRecord::Base - def before_destroy # is called just before Person#destroy - CreditCard.find(credit_card_id).destroy - end - end - - class Account < ActiveRecord::Base - after_find :eager_load, 'self.class.announce(#{id})' + before_destroy :invalidate_payment_plan + # the `invalidate_payment_plan` method gets called just before Person#destroy end {Learn more}[link:classes/ActiveRecord/Callbacks.html] -* Observers for the entire lifecycle +* Observers that react to changes in a model class CommentObserver < ActiveRecord::Observer def after_create(comment) # is called just after Comment#save @@ -122,40 +121,24 @@ A short rundown of the major features: {Learn more}[link:classes/ActiveRecord/Reflection/ClassMethods.html] -* Direct manipulation (instead of service invocation) +* Database abstraction through simple adapters - So instead of (Hibernate[http://www.hibernate.org/] example): + # connect to SQLite3 + ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "dbfile.sqlite3") - long pkId = 1234; - DomesticCat pk = (DomesticCat) sess.load( Cat.class, new Long(pkId) ); - // something interesting involving a cat... - sess.save(cat); - sess.flush(); // force the SQL INSERT + # connect to MySQL with authentication + ActiveRecord::Base.establish_connection( + :adapter => "mysql", + :host => "localhost", + :username => "me", + :password => "secret", + :database => "activerecord" + ) - Active Record lets you: - - pkId = 1234 - cat = Cat.find(pkId) - # something even more interesting involving the same cat... - cat.save - - {Learn more}[link:classes/ActiveRecord/Base.html] - - -* Database abstraction through simple adapters (~100 lines) with a shared connector - - ActiveRecord::Base.establish_connection(:adapter => "sqlite", :database => "dbfile") - - ActiveRecord::Base.establish_connection( - :adapter => "mysql", - :host => "localhost", - :username => "me", - :password => "secret", - :database => "activerecord" - ) - - {Learn more}[link:classes/ActiveRecord/Base.html#M000081] and read about the built-in support for - MySQL[link:classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html], PostgreSQL[link:classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html], SQLite[link:classes/ActiveRecord/ConnectionAdapters/SQLiteAdapter.html], Oracle[link:classes/ActiveRecord/ConnectionAdapters/OracleAdapter.html], SQLServer[link:classes/ActiveRecord/ConnectionAdapters/SQLServerAdapter.html], and DB2[link:classes/ActiveRecord/ConnectionAdapters/DB2Adapter.html]. + {Learn more}[link:classes/ActiveRecord/Base.html] and read about the built-in support for + MySQL[link:classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html], + PostgreSQL[link:classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html], and + SQLite3[link:classes/ActiveRecord/ConnectionAdapters/SQLite3Adapter.html]. * Logging support for Log4r[http://log4r.sourceforge.net] and Logger[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc] @@ -169,11 +152,11 @@ A short rundown of the major features: class AddSystemSettings < ActiveRecord::Migration def self.up create_table :system_settings do |t| - t.string :name - t.string :label - t.text :value - t.string :type - t.integer :position + t.string :name + t.string :label + t.text :value + t.string :type + t.integer :position end SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1 @@ -186,111 +169,16 @@ A short rundown of the major features: {Learn more}[link:classes/ActiveRecord/Migration.html] -== Simple example (1/2): Defining tables and classes (using MySQL) - -Data definitions are specified only in the database. Active Record queries the database for -the column names (that then serves to determine which attributes are valid) on regular -object instantiation through the new constructor and relies on the column names in the rows -with the finders. - - # CREATE TABLE companies ( - # id int(11) unsigned NOT NULL auto_increment, - # client_of int(11), - # name varchar(255), - # type varchar(100), - # PRIMARY KEY (id) - # ) - -Active Record automatically links the "Company" object to the "companies" table - - class Company < ActiveRecord::Base - has_many :people, :class_name => "Person" - end - - class Firm < Company - has_many :clients - - def people_with_all_clients - clients.inject([]) { |people, client| people + client.people } - end - end - -The foreign_key is only necessary because we didn't use "firm_id" in the data definition - - class Client < Company - belongs_to :firm, :foreign_key => "client_of" - end - - # CREATE TABLE people ( - # id int(11) unsigned NOT NULL auto_increment, - # name text, - # company_id text, - # PRIMARY KEY (id) - # ) - -Active Record will also automatically link the "Person" object to the "people" table - - class Person < ActiveRecord::Base - belongs_to :company - end - -== Simple example (2/2): Using the domain - -Picking a database connection for all the Active Records - - ActiveRecord::Base.establish_connection( - :adapter => "mysql", - :host => "localhost", - :username => "me", - :password => "secret", - :database => "activerecord" - ) - -Create some fixtures - - firm = Firm.new("name" => "Next Angle") - # SQL: INSERT INTO companies (name, type) VALUES("Next Angle", "Firm") - firm.save - - client = Client.new("name" => "37signals", "client_of" => firm.id) - # SQL: INSERT INTO companies (name, client_of, type) VALUES("37signals", 1, "Firm") - client.save - -Lots of different finders - - # SQL: SELECT * FROM companies WHERE id = 1 - next_angle = Company.find(1) - - # SQL: SELECT * FROM companies WHERE id = 1 AND type = 'Firm' - next_angle = Firm.find(1) - - # SQL: SELECT * FROM companies WHERE id = 1 AND name = 'Next Angle' - next_angle = Company.find(:first, :conditions => "name = 'Next Angle'") - - next_angle = Firm.find_by_sql("SELECT * FROM companies WHERE id = 1").first - -The supertype, Company, will return subtype instances - - Firm === next_angle - -All the dynamic methods added by the has_many macro - - next_angle.clients.empty? # true - next_angle.clients.size # total number of clients - all_clients = next_angle.clients - -Constrained finds makes access security easier when ID comes from a web-app - - # SQL: SELECT * FROM companies WHERE client_of = 1 AND type = 'Client' AND id = 2 - thirty_seven_signals = next_angle.clients.find(2) - -Bi-directional associations thanks to the "belongs_to" macro - - thirty_seven_signals.firm.nil? # true - == Philosophy +Active Record is an implementation of the object-relational mapping (ORM) +pattern[http://www.martinfowler.com/eaaCatalog/activeRecord.html] by the same +name described by Martin Fowler: + + "An object that wraps a row in a database table or view, + encapsulates the database access, and adds domain logic on that data." + Active Record attempts to provide a coherent wrapper as a solution for the inconvenience that is object-relational mapping. The prime directive for this mapping has been to minimize the amount of code needed to build a real-world domain model. This is made possible From 6b11d0bf68ecb1960f6a6dc5b11bb8cc904df5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 22 Jul 2010 09:23:22 +0200 Subject: [PATCH 15/26] remove unneeded "Dependencies" section from Action Mailer README Other READMEs don't have dependencies indicated, and installing a gem takes care of dependencies automatically. For developers, dependencies are indicated in the Gemfile. --- actionmailer/README.rdoc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index 1b9cb8a570..64b0333c0a 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -119,17 +119,6 @@ The Base class has the full list of configuration options. Here's an example: :authentication => :plain # :plain, :login or :cram_md5 } -== Dependencies - -Action Mailer depends on Action Pack. - -Additionally, Action Mailer requires the {Mail gem}[http://github.com/mikel/mail]. - -== Bundled software - -* Text::Format 0.63 by Austin Ziegler released under OpenSource - Read more on http://www.halostatue.ca/ruby/Text__Format.html - == Download and installation From 3e196db6ad57abcd9fc07ec2c5044b85bb13217e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 22 Jul 2010 09:59:58 +0200 Subject: [PATCH 16/26] improve Active Model README - fix indentation problems - revised introductory text to state right away what the library is - improved examples: reduce heavy usage of ellipsis, don't mark paragraphs of text as code --- activemodel/README.rdoc | 120 ++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 71 deletions(-) diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc index 6f162ef408..89cacbcab4 100644 --- a/activemodel/README.rdoc +++ b/activemodel/README.rdoc @@ -1,21 +1,21 @@ -= Active Model - defined interfaces for Rails - -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. You can include -functionality from the following modules: += Active Model -- model interfaces for Rails -* Adding attribute magic to your objects +Active Model provides a known set of interfaces for usage in model classes. +They allow for Action Pack helpers to interact with non-ActiveRecord models, +for example. Active Model also helps building custom ORMs for use outside of +the Rails framework. + +Prior to Rails 3.0, if a plugin or gem developer wanted 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 exacly conform to the Active Record interface. This would result +in code duplication and fragile applications that broke on upgrades. + +Active Model solves this. You can include functionality from the following +modules: + +* Add attribute magic to objects - Add prefixes and suffixes to defined attribute methods... - class Person include ActiveModel::AttributeMethods @@ -23,17 +23,18 @@ functionality from the following modules: define_attribute_methods [:name, :age] attr_accessor :name, :age - + def clear_attribute(attr) send("#{attr}=", nil) end end - ...gives you clear_name, clear_age. + person.clear_name + person.clear_age {Learn more}[link:classes/ActiveModel/AttributeMethods.html] -* Adding callbacks to your objects +* Callbacks for certain operations class Person extend ActiveModel::Callbacks @@ -45,26 +46,16 @@ functionality from the following modules: end end end - - ...gives you before_create, around_create and after_create class methods that - wrap your create method. - + + This generates +before_create+, +around_create+ and +after_create+ + class methods that wrap your create method. + {Learn more}[link:classes/ActiveModel/CallBacks.html] -* For classes that already look like an Active Record object +* Tracking value changes - class Person - include ActiveModel::Conversion - end - - ...returns the class itself when sent :to_model + The ActiveModel::Dirty module allows for tracking attribute changes: - {Learn more}[link:classes/ActiveModel/Conversion.html] - -* Tracking changes in your object - - Provides all the value tracking features implemented by ActiveRecord... - person = Person.new person.name # => nil person.changed? # => false @@ -75,14 +66,14 @@ functionality from the following modules: person.name = 'robert' person.save person.previous_changes # => {'name' => ['bob, 'robert']} - + {Learn more}[link:classes/ActiveModel/Dirty.html] -* Adding +errors+ support to your object +* Adding +errors+ interface to objects - Provides the error messages to allow your object to interact with Action Pack - helpers seamlessly... - + Exposing error messages allows objects to interact with Action Pack + helpers seamlessly. + class Person def initialize @@ -102,51 +93,38 @@ functionality from the following modules: end - ... gives you... - person.errors.full_messages # => ["Name Can not be nil"] + person.errors.full_messages # => ["Name Can not be nil"] {Learn more}[link:classes/ActiveModel/Errors.html] -* Testing the compliance of your object +* Model name introspection - Use ActiveModel::Lint to test the compliance of your object to the - basic ActiveModel API... - - {Learn more}[link:classes/ActiveModel/Lint/Tests.html] - -* Providing a human face to your object - - ActiveModel::Naming provides your model with the model_name convention - and a human_name attribute... - class NamedPerson extend ActiveModel::Naming end - ...gives you... - NamedPerson.model_name #=> "NamedPerson" NamedPerson.model_name.human #=> "Named person" {Learn more}[link:classes/ActiveModel/Naming.html] -* Adding observer support to your objects +* Observer support - ActiveModel::Observers allows your object to implement the Observer - pattern in a Rails App and take advantage of all the standard observer - functions. + ActiveModel::Observers allows your object to implement the Observer + pattern in a Rails App and take advantage of all the standard observer + functions. {Learn more}[link:classes/ActiveModel/Observer.html] -* Making your object serializable +* Making objects serializable - ActiveModel::Serialization provides a standard interface for your object - to provide to_json or to_xml serialization... - + ActiveModel::Serialization provides a standard interface for your object + to provide +to_json+ or +to_xml+ serialization. + s = SerialPerson.new s.serializable_hash # => {"name"=>nil} s.to_json # => "{\"name\":null}" @@ -154,36 +132,36 @@ functionality from the following modules: {Learn more}[link:classes/ActiveModel/Serialization.html] -* Integrating with Rail's internationalization (i18n) handling through - ActiveModel::Translations... +* Internationalization (i18n) support class Person extend ActiveModel::Translation end + + Person.human_attribute_name('my_attribute') + #=> "My attribute" {Learn more}[link:classes/ActiveModel/Translation.html] -* Providing a full Validation stack for your objects... +* Validation support class Person include ActiveModel::Validations attr_accessor :first_name, :last_name - validates_each :first_name, :last_name do |record, attr, value| record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z end end - person = Person.new person.first_name = 'zoolander' - person.valid? #=> false + person.valid? #=> false {Learn more}[link:classes/ActiveModel/Validations.html] -* Make custom validators +* Custom validators class Person include ActiveModel::Validations @@ -196,7 +174,7 @@ functionality from the following modules: record.errors[:name] = "must exist" if record.name.blank? end end - + p = ValidatorPerson.new p.valid? #=> false p.errors.full_messages #=> ["Name must exist"] From 2d2bde9f543a1508e9b149751a4566780033e3f0 Mon Sep 17 00:00:00 2001 From: Ivan Torres Date: Thu, 22 Jul 2010 10:10:38 -0500 Subject: [PATCH 17/26] [PATCH] Update guides after Jeremy Kemper's changes on fieldWithErrors to field_with_errors [#157 state:resolved] --- .../guides/source/active_record_validations_callbacks.textile | 4 ++-- railties/guides/source/configuring.textile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index c7ba130a90..37a65d211e 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -799,7 +799,7 @@ h4. Customizing the Error Messages CSS The selectors to customize the style of error messages are: -* +.fieldWithErrors+ - Style for the form fields and labels with errors. +* +.field_with_errors+ - Style for the form fields and labels with errors. * +#errorExplanation+ - Style for the +div+ element with the error messages. * +#errorExplanation h2+ - Style for the header of the +div+ element. * +#errorExplanation p+ - Style for the paragraph that holds the message that appears right below the header of the +div+ element. @@ -811,7 +811,7 @@ The name of the class and the id can be changed with the +:class+ and +:id+ opti h4. Customizing the Error Messages HTML -By default, form fields with errors are displayed enclosed by a +div+ element with the +fieldWithErrors+ CSS class. However, it's possible to override that. +By default, form fields with errors are displayed enclosed by a +div+ element with the +field_with_errors+ CSS class. However, it's possible to override that. The way form fields with errors are treated is defined by +ActionView::Base.field_error_proc+. This is a +Proc+ that receives two parameters: diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 86655746e4..2ab28596d8 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -181,7 +181,7 @@ There are only a few configuration options for Action View, starting with four o * +config.action_view.warn_cache_misses+ tells Rails to display a warning whenever an action results in a cache miss on your view paths. The default is +false+. -* +config.action_view.field_error_proc+ provides an HTML generator for displaying errors that come from Active Record. The default is Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>" } +* +config.action_view.field_error_proc+ provides an HTML generator for displaying errors that come from Active Record. The default is Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>" } * +config.action_view.default_form_builder+ tells Rails which form builder to use by default. The default is +ActionView::Helpers::FormBuilder+. From cf5c2bacb09bb6aa18cf5fa9b1abe022613e33c6 Mon Sep 17 00:00:00 2001 From: Andrew Kaspick Date: Thu, 22 Jul 2010 14:59:52 -0500 Subject: [PATCH 18/26] update remote_function docs referencing link_to_remote --- actionpack/lib/action_view/helpers/prototype_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 28b8a27eef..99f9363a9a 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -102,7 +102,7 @@ module ActionView :form, :with, :update, :script, :type ]).merge(CALLBACKS) # Returns the JavaScript needed for a remote function. - # Takes the same arguments as link_to_remote. + # See the link_to_remote documentation at http://github.com/rails/prototype_legacy_helper as it takes the same arguments. # # Example: # # Generates: