railties 3.0.0.rc → 3.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +80 -75
  2. data/README.rdoc +1 -1
  3. data/guides/assets/stylesheets/main.css +14 -14
  4. data/guides/rails_guides.rb +20 -1
  5. data/guides/rails_guides/generator.rb +7 -7
  6. data/guides/source/2_3_release_notes.textile +5 -5
  7. data/guides/source/3_0_release_notes.textile +4 -3
  8. data/guides/source/action_controller_overview.textile +32 -17
  9. data/guides/source/action_view_overview.textile +44 -44
  10. data/guides/source/active_record_basics.textile +2 -2
  11. data/guides/source/active_record_querying.textile +7 -7
  12. data/guides/source/active_record_validations_callbacks.textile +20 -20
  13. data/guides/source/active_support_core_extensions.textile +370 -198
  14. data/guides/source/ajax_on_rails.textile +17 -17
  15. data/guides/source/api_documentation_guidelines.textile +3 -3
  16. data/guides/source/association_basics.textile +2 -2
  17. data/guides/source/caching_with_rails.textile +5 -5
  18. data/guides/source/command_line.textile +8 -8
  19. data/guides/source/configuring.textile +6 -6
  20. data/guides/source/contributing_to_rails.textile +14 -11
  21. data/guides/source/debugging_rails_applications.textile +8 -6
  22. data/guides/source/form_helpers.textile +1 -1
  23. data/guides/source/generators.textile +34 -30
  24. data/guides/source/getting_started.textile +13 -13
  25. data/guides/source/i18n.textile +12 -1
  26. data/guides/source/index.html.erb +4 -0
  27. data/guides/source/initialization.textile +67 -72
  28. data/guides/source/layout.html.erb +1 -0
  29. data/guides/source/layouts_and_rendering.textile +9 -9
  30. data/guides/source/nested_model_forms.textile +7 -7
  31. data/guides/source/plugins.textile +1 -1
  32. data/guides/source/rails_application_templates.textile +2 -2
  33. data/guides/source/routing.textile +27 -5
  34. data/guides/source/security.textile +6 -6
  35. data/guides/w3c_validator.rb +9 -9
  36. data/lib/rails/application.rb +1 -0
  37. data/lib/rails/application/configuration.rb +1 -1
  38. data/lib/rails/code_statistics.rb +4 -4
  39. data/lib/rails/commands.rb +1 -1
  40. data/lib/rails/commands/dbconsole.rb +1 -1
  41. data/lib/rails/commands/plugin.rb +1 -1
  42. data/lib/rails/commands/runner.rb +1 -1
  43. data/lib/rails/deprecation.rb +31 -52
  44. data/lib/rails/engine.rb +1 -1
  45. data/lib/rails/engine/configuration.rb +28 -1
  46. data/lib/rails/generators.rb +2 -2
  47. data/lib/rails/generators/actions.rb +3 -3
  48. data/lib/rails/generators/active_model.rb +3 -3
  49. data/lib/rails/generators/base.rb +1 -1
  50. data/lib/rails/generators/rails/app/app_generator.rb +9 -3
  51. data/lib/rails/generators/rails/app/templates/Gemfile +2 -2
  52. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +4 -13
  53. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  54. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +4 -0
  55. data/lib/rails/generators/rails/app/templates/config/routes.rb +4 -4
  56. data/lib/rails/generators/rails/app/templates/public/index.html +0 -23
  57. data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +1 -1
  58. data/lib/rails/generators/rails/generator/USAGE +3 -2
  59. data/lib/rails/generators/rails/migration/USAGE +4 -4
  60. data/lib/rails/generators/rails/plugin/USAGE +1 -1
  61. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  62. data/lib/rails/generators/test_case.rb +1 -1
  63. data/lib/rails/info_controller.rb +1 -1
  64. data/lib/rails/plugin.rb +1 -1
  65. data/lib/rails/rack/log_tailer.rb +2 -5
  66. data/lib/rails/railtie.rb +22 -22
  67. data/lib/rails/script_rails_loader.rb +2 -2
  68. data/lib/rails/tasks/documentation.rake +5 -5
  69. data/lib/rails/tasks/framework.rake +1 -1
  70. data/lib/rails/tasks/routes.rake +23 -9
  71. data/lib/rails/test_unit/testing.rake +3 -2
  72. data/lib/rails/version.rb +1 -1
  73. metadata +10 -10
@@ -213,9 +213,9 @@ If you open this file in a new Rails application, you'll see a default database
213
213
  * The +test+ environment is used to run automated tests
214
214
  * The +production+ environment is used when you deploy your application for the world to use.
215
215
 
216
- h5. Configuring a SQLite3 Database
216
+ h5. Configuring an SQLite3 Database
217
217
 
218
- Rails comes with built-in support for "SQLite3":http://www.sqlite.org, 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 a SQLite database when creating a new project, but you can always change it later.
218
+ Rails comes with built-in support for "SQLite3":http://www.sqlite.org, 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.
219
219
 
220
220
  Here's the section of the default configuration file (<tt>config/database.yml</tt>) with connection information for the development environment:
221
221
 
@@ -475,13 +475,13 @@ After the console loads, you can use it to work with your application's models:
475
475
 
476
476
  <shell>
477
477
  >> p = Post.new(:content => "A new post")
478
- => #<Post id: nil, name: nil, title: nil,
478
+ => #<Post id: nil, name: nil, title: nil,
479
479
  content: "A new post", created_at: nil,
480
480
  updated_at: nil>
481
481
  >> p.save
482
482
  => false
483
483
  >> p.errors
484
- => #<OrderedHash { :title=>["can't be blank",
484
+ => #<OrderedHash { :title=>["can't be blank",
485
485
  "is too short (minimum is 5 characters)"],
486
486
  :name=>["can't be blank"] }>
487
487
  </shell>
@@ -742,7 +742,7 @@ def update
742
742
 
743
743
  respond_to do |format|
744
744
  if @post.update_attributes(params[:post])
745
- format.html { redirect_to(@post,
745
+ format.html { redirect_to(@post,
746
746
  :notice => 'Post was successfully updated.') }
747
747
  format.xml { head :ok }
748
748
  else
@@ -1056,7 +1056,7 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f
1056
1056
  </p>
1057
1057
 
1058
1058
  <h2>Comments</h2>
1059
- <%= render :partial => "comments/comment",
1059
+ <%= render :partial => "comments/comment",
1060
1060
  :collection => @post.comments %>
1061
1061
 
1062
1062
  <h2>Add a comment:</h2>
@@ -1127,7 +1127,7 @@ Then you make the +app/views/posts/show.html.erb+ look like the following:
1127
1127
  </p>
1128
1128
 
1129
1129
  <h2>Comments</h2>
1130
- <%= render :partial => "comments/comment",
1130
+ <%= render :partial => "comments/comment",
1131
1131
  :collection => @post.comments %>
1132
1132
 
1133
1133
  <h2>Add a comment:</h2>
@@ -1213,15 +1213,15 @@ Rails provides a very simple HTTP authentication system that will work nicely in
1213
1213
  <ruby>
1214
1214
  class ApplicationController < ActionController::Base
1215
1215
  protect_from_forgery
1216
-
1216
+
1217
1217
  private
1218
-
1218
+
1219
1219
  def authenticate
1220
1220
  authenticate_or_request_with_http_basic do |user_name, password|
1221
1221
  user_name == 'admin' && password == 'password'
1222
1222
  end
1223
1223
  end
1224
-
1224
+
1225
1225
  end
1226
1226
  </ruby>
1227
1227
 
@@ -1381,7 +1381,7 @@ Finally, we will edit the <tt>app/views/posts/show.html.erb</tt> template to sho
1381
1381
  </p>
1382
1382
 
1383
1383
  <h2>Comments</h2>
1384
- <%= render :partial => "comments/comment",
1384
+ <%= render :partial => "comments/comment",
1385
1385
  :collection => @post.comments %>
1386
1386
 
1387
1387
  <h2>Add a comment:</h2>
@@ -1405,7 +1405,7 @@ Open up <tt>app/helpers/posts_helper.rb</tt> and add the following:
1405
1405
  <erb>
1406
1406
  module PostsHelper
1407
1407
  def join_tags(post)
1408
- post.tags.map { |t| t.name }.join(", ")
1408
+ post.tags.map { |t| t.name }.join(", ")
1409
1409
  end
1410
1410
  end
1411
1411
  </erb>
@@ -1436,7 +1436,7 @@ Now you can edit the view in <tt>app/views/posts/show.html.erb</tt> to look like
1436
1436
  </p>
1437
1437
 
1438
1438
  <h2>Comments</h2>
1439
- <%= render :partial => "comments/comment",
1439
+ <%= render :partial => "comments/comment",
1440
1440
  :collection => @post.comments %>
1441
1441
 
1442
1442
  <h2>Add a comment:</h2>
@@ -231,6 +231,17 @@ end
231
231
 
232
232
  Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
233
233
 
234
+ If you don'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:
235
+
236
+ <ruby>
237
+ # config/routes.rb
238
+ scope "(:locale)", :locale => /en|nl/ do
239
+ resources :books
240
+ end
241
+ </ruby>
242
+
243
+ With this approach you will not get a +Routing Error+ when accessing your resources such as +http://localhost:3001/books+ without a locale. This is useful for when you want to use the default locale when one is not specified.
244
+
234
245
  Of course, you need to take special care of the root URL (usually "homepage" or "dashboard") of your application. An URL like +http://localhost:3001/nl+ will not work automatically, because the +root :to => "books#index"+ declaration in your +routes.rb+ doesn't take locale into account. (And rightly so: there's only one "root" URL.)
235
246
 
236
247
  You would probably need to map URLs like these:
@@ -518,7 +529,7 @@ es:
518
529
  title: "Título"
519
530
  </yaml>
520
531
 
521
- you can look up the +books.index.title+ value *inside* +app/views/books/index.html.erb+ template like this (note the dot):
532
+ you can look up the +books.index.title+ value *inside* +app/views/books/index.html.erb+ template like this (note the dot):
522
533
 
523
534
  <ruby>
524
535
  <%= t '.title' %>
@@ -88,6 +88,10 @@ Ruby on Rails Guides
88
88
 
89
89
  <dl>
90
90
 
91
+ <%= guide("Active Support Core Extensions", 'active_support_core_extensions.html') do %>
92
+ <p>This guide documents the Ruby core extensions defined in Active Support.</p>
93
+ <% end %>
94
+
91
95
  <%= guide("Rails Internationalization API", 'i18n.html') do %>
92
96
  <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>
93
97
  <% end %>
@@ -118,7 +118,7 @@ Now with Rails 3 we have a Gemfile which defines the basics our application need
118
118
 
119
119
  # Bundle the extra gems:
120
120
  # gem 'bj'
121
- # gem 'nokogiri', '1.4.1'
121
+ # gem 'nokogiri'
122
122
  # gem 'sqlite3-ruby', :require => 'sqlite3'
123
123
  # gem 'aws-s3', :require => 'aws/s3'
124
124
 
@@ -141,16 +141,16 @@ Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This
141
141
  * activesupport-3.0.0.beta4.gem
142
142
  * arel-0.4.0.gem
143
143
  * builder-2.1.2.gem
144
- * bundler-1.0.0.beta.5.gem
144
+ * bundler-1.0.0.rc.6.gem
145
145
  * erubis-2.6.6.gem
146
146
  * i18n-0.4.1.gem
147
147
  * mail-2.2.5.gem
148
148
  * memcache-client-1.8.5.gem
149
149
  * mime-types-1.16.gem
150
- * nokogiri-1.4.2.gem
150
+ * nokogiri-1.4.3.1.gem
151
151
  * polyglot-0.3.1.gem
152
152
  * rack-1.2.1.gem
153
- * rack-mount-0.6.9.gem
153
+ * rack-mount-0.6.12.gem
154
154
  * rack-test-0.5.4.gem
155
155
  * rails-3.0.0.beta4.gem
156
156
  * railties-3.0.0.beta4.gem
@@ -160,7 +160,7 @@ Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This
160
160
  * text-hyphen-1.0.0.gem
161
161
  * thor-0.13.7.gem
162
162
  * treetop-1.4.8.gem
163
- * tzinfo-0.3.22.gem
163
+ * tzinfo-0.3.23.gem
164
164
 
165
165
  TODO: Prettify when it becomes more stable.
166
166
 
@@ -229,7 +229,7 @@ This file goes on to define some classes that will be automatically loaded using
229
229
  <ruby>
230
230
  require "active_support/inflector/methods"
231
231
  require "active_support/lazy_load_hooks"
232
-
232
+
233
233
  module ActiveSupport
234
234
  module Autoload
235
235
  def self.extended(base)
@@ -250,7 +250,7 @@ This file goes on to define some classes that will be automatically loaded using
250
250
  end
251
251
  super const_name, location
252
252
  end
253
-
253
+
254
254
  ...
255
255
  end
256
256
  end
@@ -258,28 +258,23 @@ This file goes on to define some classes that will be automatically loaded using
258
258
 
259
259
  h4. Lazy Hooks
260
260
 
261
- At the top if the +ActiveSupport::Autoload+ module is the +def self.extended+ method:
262
-
263
- <ruby>
264
- def self.extended(base)
265
- base.extend(LazyLoadHooks)
266
- end
267
- </ruby>
268
-
269
- This is called when we extend this module into one of our classes or modules, such is the case later on when we call +extend ActiveSupport::LazyLoadHooks+ not only in the +ActiveSupport+ module, but in all of the Railtie modules (+ActiveRecord+ and so on), as well as in a couple of places.
270
-
271
261
  +ActiveSupport::LazyLoadHooks+ is responsible for defining methods used for running hooks that are defined during the initialization process, such as the one defined inside the +active_record.initialize_timezone+ initializer:
272
262
 
273
263
  <ruby>
274
264
  initializer "active_record.initialize_timezone" do
275
- ActiveRecord.base_hook do
265
+ ActiveSupport.on_load(:active_record) do
276
266
  self.time_zone_aware_attributes = true
277
267
  self.default_timezone = :utc
278
268
  end
279
269
  end
280
270
  </ruby>
281
271
 
282
- When the initializer is ran it defines a +base_hook+ for +ActiveRecord+ and will only run it when +run_base_hooks+ is called, which in the case of Active Record, is ran after the entirety of +activerecord/lib/active_record/base.rb+ has been evaluated.
272
+ When the initializer runs it invokes method +on_load+ for +ActiveRecord+ and the block passed to it would be called only when +run_load_hooks+ is called.
273
+ When the entirety of +activerecord/lib/active_record/base.rb+ has been evaluated then +run_load_hooks+ is invoked. The very last line of +activerecord/lib/active_record/base.rb+ is:
274
+
275
+ <ruby>
276
+ ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
277
+ </ruby>
283
278
 
284
279
  h4. +require 'active_support'+ cont'd.
285
280
 
@@ -342,7 +337,7 @@ As you can see for the duration of the +eager_autoload+ block the class variable
342
337
  autoload :I18n, "active_support/i18n"
343
338
  </ruby>
344
339
 
345
- So we know the ones in +eager_autoload+ are eagerly loaded and it does this by storing them in an +@@autoloads+ hash object and then loading them via +eager_autoload!+ which is called via the +preload_frameworks+ initializer defined in _railties/lib/rails/application/bootstrap.rb_.
340
+ So we know the ones in +eager_autoload+ are eagerly loaded and it does this by storing them in an +@@autoloads+ hash object and then loading them via +eager_autoload!+ which is called via the +preload_frameworks+ initializer defined in _railties/lib/rails/application/bootstrap.rb_.
346
341
 
347
342
  The classes and modules that are not +eager_autoload+'d are automatically loaded as they are references
348
343
 
@@ -428,16 +423,16 @@ Now that Rails has required Action Dispatch and it has required Rack, Rails can
428
423
  <ruby>
429
424
  module Rails
430
425
  class Server < ::Rack::Server
431
-
426
+
432
427
  ...
433
-
428
+
434
429
  def initialize(*)
435
430
  super
436
431
  set_environment
437
432
  end
438
-
433
+
439
434
  ...
440
-
435
+
441
436
  def set_environment
442
437
  ENV["RAILS_ENV"] ||= options[:environment]
443
438
  end
@@ -491,7 +486,7 @@ And +default_options+ like this:
491
486
  :AccessLog => [],
492
487
  :config => "config.ru"
493
488
  }
494
- end
489
+ end
495
490
  </ruby>
496
491
 
497
492
  Here it is important to note that the default environment is _development_. After +Rack::Server#initialize+ has done its thing it returns to +Rails::Server#initialize+ which calls +set_environment+:
@@ -757,7 +752,7 @@ If you wish to know more about how they're deprecated see the +require 'active_s
757
752
 
758
753
  h4. +require 'rails/log_subscriber'+
759
754
 
760
- The +Rails::LogSubscriber+ 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 (+info+, +debug+, +warn+, +error+, +fatal+ or +unknown+) from the +Rails::LogSubscriber+ 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 +Rails::Rack::Logger+ middleware.
755
+ The +Rails::LogSubscriber+ 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 (+info+, +debug+, +warn+, +error+, +fatal+ or +unknown+) from the +Rails::LogSubscriber+ 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 +Rails::Rack::Logger+ middleware.
761
756
 
762
757
  Each Railtie defines its own class that descends from +Rails::LogSubscriber+ with each defining its own methods for logging individual tasks.
763
758
 
@@ -826,7 +821,7 @@ TODO: Quotify.
826
821
  <plain>
827
822
  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:
828
823
 
829
- "An object that wraps a row in a database table or view, encapsulates
824
+ "An object that wraps a row in a database table or view, encapsulates
830
825
  the database access, and adds domain logic on that data."
831
826
 
832
827
  Active Record's main contribution to the pattern is to relieve the original of two stunting problems:
@@ -915,7 +910,7 @@ h5. +require 'active_record'+
915
910
 
916
911
  Back the initial require from the _railtie.rb_.
917
912
 
918
- The _active_support_ and _active_model_ requires are again just an insurance for if we're loading Active Record outside of the scope of Rails. In _active_record.rb_ the ActiveRecord +Module+ is initialized and in it there is defined a couple of +autoloads+ and +eager_autoloads+.
913
+ The _active_support_ and _active_model_ requires are again just an insurance for if we're loading Active Record outside of the scope of Rails. In _active_record.rb_ the ActiveRecord +Module+ is initialized and in it there is defined a couple of +autoloads+ and +eager_autoloads+.
919
914
 
920
915
  There's a new method here called +autoload_under+ which is defined in +ActiveSupport::Autoload+. This sets the autoload path to temporarily be the specified path, in this case +relation+ for the +autoload+'d classes inside the block.
921
916
 
@@ -940,7 +935,7 @@ Inside the Active Record Railtie the +ActiveRecord::Railtie+ class is defined:
940
935
  <ruby>
941
936
  module ActiveRecord
942
937
  class Railtie < Rails::Railtie
943
-
938
+
944
939
  ...
945
940
  end
946
941
  end
@@ -969,8 +964,8 @@ This Railtie is +require+'d by Active Record's Railtie.
969
964
  From the Active Model readme:
970
965
 
971
966
  <plain>
972
- 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.
973
-
967
+ 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.
968
+
974
969
  Active Model is a solution for this problem.
975
970
 
976
971
  Active Model provides a known set of interfaces that your objects can implement to then present a common interface to the Action Pack helpers.
@@ -1004,7 +999,7 @@ This first makes a couple of requires:
1004
999
  require "action_view/railtie"
1005
1000
  </ruby>
1006
1001
 
1007
- The _action_controller_ file is explained in the very next section. The require to _rails_ is requiring the already-required _railties/lib/rails.rb_. If you wish to know about the require to _action_view/railtie_ this is explained in the Action View Railtie section.
1002
+ The _action_controller_ file is explained in the very next section. The require to _rails_ is requiring the already-required _railties/lib/rails.rb_. If you wish to know about the require to _action_view/railtie_ this is explained in the Action View Railtie section.
1008
1003
 
1009
1004
  h5. +require 'action_controller+
1010
1005
 
@@ -1014,7 +1009,7 @@ h5. +require 'abstract_controller'+
1014
1009
 
1015
1010
  +AbstractController+ provides the functionality of TODO.
1016
1011
 
1017
- This file is in _actionpack/lib/abstract_controller.rb_ and begins by attempting to add the path to Active Support to the load path, which it would succeed in if it wasn't already set by anything loaded before it. In this case, it's not going to be set due to Arel already loading it in (TODO: right?).
1012
+ This file is in _actionpack/lib/abstract_controller.rb_ and begins by attempting to add the path to Active Support to the load path, which it would succeed in if it wasn't already set by anything loaded before it. In this case, it's not going to be set due to Arel already loading it in (TODO: right?).
1018
1013
 
1019
1014
  The next thing in this file four +require+ calls:
1020
1015
 
@@ -1151,9 +1146,9 @@ For an explanation of this file _activesupport/lib/active_support/core_ext/class
1151
1146
 
1152
1147
  h5. +require 'active_support/deprecation/proxy_wrappers'+
1153
1148
 
1154
- This file, _activesupport/lib/active_support/deprecation/proxy_wrappers.rb_, defines a couple of deprecation classes, which are +DeprecationProxy+, +DeprecationObjectProxy+, +DeprecationInstanceVariableProxy+, +DeprecationConstantProxy+ which are all namespaced into +ActiveSupport::Deprecation+. These last three are all subclasses of +DeprecationProxy+.
1149
+ This file, _activesupport/lib/active_support/deprecation/proxy_wrappers.rb_, defines a couple of deprecation classes, which are +DeprecationProxy+, +DeprecationObjectProxy+, +DeprecationInstanceVariableProxy+, +DeprecationConstantProxy+ which are all namespaced into +ActiveSupport::Deprecation+. These last three are all subclasses of +DeprecationProxy+.
1155
1150
 
1156
- Why do we mention them here? Beside the obvious-by-now fact that we're covering just about everything about the initialization process in this guide, if you're deprecating something in your library and you use Active Support, you too can use the +DeprecationProxy+ class (and it's subclasses) too.
1151
+ Why do we mention them here? Beside the obvious-by-now fact that we're covering just about everything about the initialization process in this guide, if you're deprecating something in your library and you use Active Support, you too can use the +DeprecationProxy+ class (and it's subclasses) too.
1157
1152
 
1158
1153
 
1159
1154
  h6. +DeprecationProxy+
@@ -1182,7 +1177,7 @@ This class is used only in _railties/lib/rails/deprecation.rb_, loaded further o
1182
1177
  end).new
1183
1178
  </ruby>
1184
1179
 
1185
- There is similar definitions for the other constants of +RAILS_ENV+ and +RAILS_DEFAULT_LOGGER+. 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're deprecated using the +DeprecationProxy+ class. Whenever you call +RAILS_ROOT+ this will raise a warning, telling you: "RAILS_ROOT is deprecated! Use Rails.root instead".... TODO: investigate if simply calling it does raise this warning. This same rule applies to +RAILS_ENV+ and +RAILS_DEFAULT_LOGGER+, their new alternatives are +Rails.env+ and +Rails.logger+ respectively.
1180
+ There is similar definitions for the other constants of +RAILS_ENV+ and +RAILS_DEFAULT_LOGGER+. 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're deprecated using the +DeprecationProxy+ class. Whenever you call +RAILS_ROOT+ this will raise a warning, telling you: "RAILS_ROOT is deprecated! Use Rails.root instead".... TODO: investigate if simply calling it does raise this warning. This same rule applies to +RAILS_ENV+ and +RAILS_DEFAULT_LOGGER+, their new alternatives are +Rails.env+ and +Rails.logger+ respectively.
1186
1181
 
1187
1182
  h6. +DeprecatedObjectProxy+
1188
1183
 
@@ -1208,7 +1203,7 @@ This makes more sense in the wider scope of the initializer:
1208
1203
  end
1209
1204
  </ruby>
1210
1205
 
1211
- +ActionController::Routing::Routes+ was the previous constant used in defining routes in Rails 2 applications, now it's simply a method on +Rails.application+ rather than it's own individual class: +Rails.application.routes+. Both of these still call the +draw+ method on the returned object to end up defining the routes.
1206
+ +ActionController::Routing::Routes+ was the previous constant used in defining routes in Rails 2 applications, now it's simply a method on +Rails.application+ rather than it's own individual class: +Rails.application.routes+. Both of these still call the +draw+ method on the returned object to end up defining the routes.
1212
1207
 
1213
1208
 
1214
1209
  h6. +DeprecatedInstanceVariableProxy+
@@ -1367,7 +1362,7 @@ Here again we have the addition of the path to Active Support to the load path a
1367
1362
 
1368
1363
  And these have already been required. If you wish to know what these files do go to the explanation of each in the "Common Includes" section. TODO: link to them!
1369
1364
 
1370
- This file goes on to +require 'action_pack'+ which consists of all this code (comments stripped):
1365
+ This file goes on to +require 'action_pack'+ which consists of all this code (comments stripped):
1371
1366
 
1372
1367
  <ruby>
1373
1368
  require 'action_pack/version'
@@ -1450,11 +1445,11 @@ After including +ActiveSupport::Benchmarkable+, the helpers which we have declar
1450
1445
 
1451
1446
  h5. +ActionView::Rendering+
1452
1447
 
1453
- This module, from _actionpack/lib/action_view/render/rendering.rb_ defines a method you may be a little too familiar with: +render+. This is the +render+ use for rendering all kinds of things, such as partials, templates and text.
1448
+ This module, from _actionpack/lib/action_view/render/rendering.rb_ defines a method you may be a little too familiar with: +render+. This is the +render+ use for rendering all kinds of things, such as partials, templates and text.
1454
1449
 
1455
1450
  h5. +ActionView::Partials+
1456
1451
 
1457
- This module, from _actionpack/lib/action_view/render/partials.rb_, defines +ActionView::Partials::PartialRenderer+ which you can probably guess is used for rendering partials.
1452
+ This module, from _actionpack/lib/action_view/render/partials.rb_, defines +ActionView::Partials::PartialRenderer+ which you can probably guess is used for rendering partials.
1458
1453
 
1459
1454
  h5. +ActionView::Layouts+
1460
1455
 
@@ -1492,7 +1487,7 @@ Next, the Railtie itself is defined:
1492
1487
  end
1493
1488
  end
1494
1489
  end
1495
- </ruby>
1490
+ </ruby>
1496
1491
 
1497
1492
  The +ActionView::LogSubscriber+ sets up a method called +render_template+ which is called when a template is rendered. TODO: 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.
1498
1493
 
@@ -1507,7 +1502,7 @@ are used to consolidate code for sending out forgotten passwords, welcome
1507
1502
  wishes on signup, invoices for billing, and any other use case that requires
1508
1503
  a written notification to either a person or another system.
1509
1504
 
1510
- Action Mailer is in essence a wrapper around Action Controller and the
1505
+ Action Mailer is in essence a wrapper around Action Controller and the
1511
1506
  Mail gem. It provides a way to make emails using templates in the same
1512
1507
  way that Action Controller renders views using templates.
1513
1508
 
@@ -1585,7 +1580,7 @@ which is used by the +ActionMailer::MailerHelper+ method +block_format+:
1585
1580
  :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
1586
1581
  ).format
1587
1582
  }.join("\n")
1588
-
1583
+
1589
1584
  # Make list points stand on their own line
1590
1585
  formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
1591
1586
  formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
@@ -1692,7 +1687,7 @@ There is only one initializer defined here: +set_configs+. This is covered later
1692
1687
 
1693
1688
  h4. ActionDispatch Railtie
1694
1689
 
1695
- ActionDispatch handles all dispatch work for Rails. It interfaces with Action Controller to determine what action to undertake when a request comes in. TODO: I would quote the README but it is strangely absent. Flyin' blind here!
1690
+ ActionDispatch handles all dispatch work for Rails. It interfaces with Action Controller to determine what action to undertake when a request comes in. TODO: I would quote the README but it is strangely absent. Flyin' blind here!
1696
1691
 
1697
1692
  The ActionDispatch Railtie was previously required when we called +require 'rails'+, but we will cover the Railtie here too.
1698
1693
 
@@ -1822,7 +1817,7 @@ This +called_from+ setting looks a little overwhelming to begin with, but the sh
1822
1817
  base.send(:include, self::Configurable)
1823
1818
  subclasses << base
1824
1819
  end
1825
- end
1820
+ end
1826
1821
  </ruby>
1827
1822
 
1828
1823
  Again, +YourApp::Application+ will return false for +abstract_railtie+ and so the code inside the +unless+ will be ran. The first line:
@@ -1891,7 +1886,7 @@ Now that we've covered the boot process of Rails the next line best to cover wou
1891
1886
  Rails::Server.start
1892
1887
  </ruby>
1893
1888
 
1894
- The keen-eyed observer will note that this +when+ also specifies the argument could also be simply +'s'+ thereby making the full command +rails s+. This is the same with the other commands with +generate+ becoming +g+, +console+ becoming +c+ and +dbconsole+ becoming +db+.
1889
+ The keen-eyed observer will note that this +when+ also specifies the argument could also be simply +'s'+ thereby making the full command +rails s+. This is the same with the other commands with +generate+ becoming +g+, +console+ becoming +c+ and +dbconsole+ becoming +db+.
1895
1890
 
1896
1891
  This code here ensures we are at the +ROOT_PATH+ of our application (this constant was defined in _script/rails_) and then calls +Rails::Server.start+. +Rails::Server+ descends from +Rack::Server+ which is defined in the rack gem. The +Rails::Server.start+ method is defined like this:
1897
1892
 
@@ -2002,7 +1997,7 @@ Finally! We've arrived at +default_options+ which leads into our next point quit
2002
1997
  end
2003
1998
  </ruby>
2004
1999
 
2005
- We're not debugging anything, so there goes the first 7 lines, we're not warning, nor are we including, requiring, daemonising or writing out a pid file. That's everything except the final line, which calls +run+ with the +wrapped_app+ which is then defined like this:
2000
+ We're not debugging anything, so there goes the first 7 lines, we're not warning, nor are we including, requiring, daemonising or writing out a pid file. That's everything except the final line, which calls +run+ with the +wrapped_app+ which is then defined like this:
2006
2001
 
2007
2002
  <ruby>
2008
2003
  def wrapped_app
@@ -2056,7 +2051,7 @@ First this reads your config file and checks it for +#\+ at the beginning. This
2056
2051
 
2057
2052
  require ::File.expand_path('../config/environment', __FILE__)
2058
2053
  run YourApp::Application.instance
2059
-
2054
+
2060
2055
  </ruby>
2061
2056
 
2062
2057
  TODO: Is the above correct? I am simply guessing!
@@ -2251,7 +2246,7 @@ The method +find_with_root_flag+ is defined on +Rails::Engine+ (the superclass o
2251
2246
  Pathname.new(root).expand_path : Pathname.new(root).realpath
2252
2247
  end
2253
2248
  </ruby>
2254
-
2249
+
2255
2250
  +called_from+ goes through the +caller+ which is the stacktrace of the current thread, in the case of your application it would go a little like this:
2256
2251
 
2257
2252
  <pre>
@@ -2279,7 +2274,7 @@ The method +find_with_root_flag+ is defined on +Rails::Engine+ (the superclass o
2279
2274
  end
2280
2275
  </ruby>
2281
2276
 
2282
- The +call_stack+ here is the +caller+ output shown previously, minus everything after the first +:+ on all the lines. The first path that matches this is _/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta1/lib/rails_. Yours may vary slightly, but should always end in _railties-x.x.x/lib/rails_.
2277
+ The +call_stack+ here is the +caller+ output shown previously, minus everything after the first +:+ on all the lines. The first path that matches this is _/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta1/lib/rails_. Yours may vary slightly, but should always end in _railties-x.x.x/lib/rails_.
2283
2278
 
2284
2279
  The code in +find_root_with_flag+ will go up this directory structure until it reaches the top, which in this case is +/+.
2285
2280
 
@@ -2307,7 +2302,7 @@ At the root of the system it looks for +config.ru+. TODO: Why? Obviously it's no
2307
2302
  @serve_static_assets = true
2308
2303
  @time_zone = "UTC"
2309
2304
  @consider_all_requests_local = true
2310
- end
2305
+ end
2311
2306
  </ruby>
2312
2307
 
2313
2308
  The +super+ method here is the +initialize+ method in +Rails::Engine::Configuration+:
@@ -2609,7 +2604,7 @@ The +plugins+ method it calls is a little more complex:
2609
2604
  </ruby>
2610
2605
 
2611
2606
  When we call +@config.paths.vendor.plugins+ it will return +"vendor/plugins"+.
2612
-
2607
+
2613
2608
 
2614
2609
  If you've defined specific plugin requirements for your application in _config/application.rb_ by using this code:
2615
2610
 
@@ -2730,7 +2725,7 @@ Now we finally have all the +initializers+ we can go through them and call +run+
2730
2725
  end
2731
2726
  </ruby>
2732
2727
 
2733
- You may remember that the +@context+ in this code is +YourApp::Application+ and calling +instance_exec+ on this class will make a new instance of it and execute the code within the +&block+ passed to it. This code within the block is the code from all the initializers.
2728
+ You may remember that the +@context+ in this code is +YourApp::Application+ and calling +instance_exec+ on this class will make a new instance of it and execute the code within the +&block+ passed to it. This code within the block is the code from all the initializers.
2734
2729
 
2735
2730
  h3. Bootstrap Initializers
2736
2731
 
@@ -2764,15 +2759,15 @@ We've seen +config.paths+ before when loading the plugins and they're explained
2764
2759
  <ruby>
2765
2760
  module Rails
2766
2761
  class << self
2767
-
2762
+
2768
2763
  ...
2769
-
2764
+
2770
2765
  def env
2771
2766
  @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
2772
2767
  end
2773
-
2768
+
2774
2769
  ...
2775
-
2770
+
2776
2771
  end
2777
2772
  end
2778
2773
  </ruby>
@@ -2958,7 +2953,7 @@ This is where it gets loaded. The +eager_autoload!+ method is defined like this:
2958
2953
  end
2959
2954
  </ruby>
2960
2955
 
2961
- With +@@autoloads+ being
2956
+ With +@@autoloads+ being
2962
2957
 
2963
2958
 
2964
2959
  * load_all_active_support
@@ -3149,9 +3144,9 @@ h4. +ActionDispatch::MiddlewareStack.new+
3149
3144
  <ruby>
3150
3145
  module ActionDispatch
3151
3146
  class MiddlewareStack < Array
3152
-
3147
+
3153
3148
  ...
3154
-
3149
+
3155
3150
  def initialize(*args, &block)
3156
3151
  super(*args)
3157
3152
  block.call(self) if block_given?
@@ -3193,9 +3188,9 @@ This +initialize+ method also is in a class who's ancestry is important so once
3193
3188
  <ruby>
3194
3189
  module ActionController
3195
3190
  class Middleware < Metal
3196
-
3191
+
3197
3192
  ...
3198
-
3193
+
3199
3194
  def initialize(app)
3200
3195
  super()
3201
3196
  @_app = app
@@ -3212,9 +3207,9 @@ This is another subclassed class, this time from +ActionController::AbstractCont
3212
3207
 
3213
3208
  <ruby>
3214
3209
  class Metal < AbstractController::Base
3215
-
3210
+
3216
3211
  ...
3217
-
3212
+
3218
3213
  def initialize(*)
3219
3214
  @_headers = {}
3220
3215
  super
@@ -3222,7 +3217,7 @@ This is another subclassed class, this time from +ActionController::AbstractCont
3222
3217
  end
3223
3218
  </ruby>
3224
3219
 
3225
- The single +*+ in the argument listing means we can accept any number of arguments, we just don't care what they are.
3220
+ The single +*+ in the argument listing means we can accept any number of arguments, we just don't care what they are.
3226
3221
 
3227
3222
  h4. +AbstractController::Base.initialize+
3228
3223
 
@@ -3237,7 +3232,7 @@ This may be anti-climatic, but the initialize method here just returns an +Abstr
3237
3232
 
3238
3233
  h4. +ActionDispatch::MiddlewareStack.use+
3239
3234
 
3240
- Now we're back to this method, from our foray into the depths of how +Middleware.new+ works, we've showed that it is an instance of +AbstractController::Base+. Therefore it does
3235
+ Now we're back to this method, from our foray into the depths of how +Middleware.new+ works, we've showed that it is an instance of +AbstractController::Base+. Therefore it does
3241
3236
 
3242
3237
  TODO: ELABORATE ON THIS SECTION, including explaining what all the pieces of middleware do. Then explain how the default_middleware_stack does what it does, whatever that is.
3243
3238
 
@@ -3314,7 +3309,7 @@ In a standard Rails application we have this in our _config/environments/develop
3314
3309
  end
3315
3310
  </ruby>
3316
3311
 
3317
- It's a little bit sneaky here, but +configure+ is +alias+'d to +class_eval+ on subclasses of +Rails::Application+ which of course includes +YourApp::Application+. This means that the code inside the +configure do+ block will be evaled within the context of +YourApp::Application+. The +config+ method here is the one mentioned before: the +Rails::Application::Configuration+ object. The methods on it should look familiar too: they're the ones that had +attr_accessor+ and +attr_writer+ definitions.
3312
+ It's a little bit sneaky here, but +configure+ is +alias+'d to +class_eval+ on subclasses of +Rails::Application+ which of course includes +YourApp::Application+. This means that the code inside the +configure do+ block will be evaled within the context of +YourApp::Application+. The +config+ method here is the one mentioned before: the +Rails::Application::Configuration+ object. The methods on it should look familiar too: they're the ones that had +attr_accessor+ and +attr_writer+ definitions.
3318
3313
 
3319
3314
  The ones down the bottom, +config.action_controller+, +config.action_view+ and +config.action_mailer+ aren't defined by +attr_accessor+ or +attr_writer+, rather they're undefined methods and therefore will trigger the +method_missing+ on the +Rails::Application::Configuration+ option.
3320
3315
 
@@ -3386,7 +3381,7 @@ I'm going to show you two methods since the third one, +self.plugin_name+, calls
3386
3381
  @plugins ||= []
3387
3382
  @plugins << klass unless klass == Plugin
3388
3383
  end
3389
-
3384
+
3390
3385
  def self.plugins
3391
3386
  @plugins
3392
3387
  end
@@ -3477,7 +3472,7 @@ h5. +Rack::Handler::WEBrick+
3477
3472
  This class is subclassed from +WEBrick::HTTPServlet::AbstractServlet+ 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.
3478
3473
 
3479
3474
 
3480
- +Rack::Server+ has handlers for the request and by default the handler for a _rails server_ server is
3475
+ +Rack::Server+ has handlers for the request and by default the handler for a _rails server_ server is
3481
3476
 
3482
3477
  h3. Cruft!
3483
3478
 
@@ -3711,7 +3706,7 @@ This file is _activesupport/lib/active_support/inflector.rb_ and makes a couple
3711
3706
  require 'active_support/core_ext/string/inflections'
3712
3707
  </ruby>
3713
3708
 
3714
- The files included here define methods for modifying strings, such as +transliterate+ which will convert a Unicode string to its ASCII version, +parameterize+ for making strings into url-safe versions, +camelize+ for camel-casing a string such as +string_other+ into +StringOther+ and +ordinalize+ converting a string such as +101+ into +101st+. More information about these methods can be found in the Active Support Core Extensions Guide. TODO: Link to AS Guide.
3709
+ The files included here define methods for modifying strings, such as +transliterate+ which will convert a Unicode string to its ASCII version, +parameterize+ for making strings into url-safe versions, +camelize+ for camel-casing a string such as +string_other+ into +StringOther+ and +ordinalize+ converting a string such as +101+ into +101st+. More information about these methods can be found in the Active Support Core Extensions Guide. TODO: Link to AS Guide.
3715
3710
 
3716
3711
  h4. +require 'active_support/core_ext/module/delegation'+
3717
3712
 
@@ -3720,7 +3715,7 @@ _activesupport/lib/active_support/core_ext/module/delegation.rb_ defines the +de
3720
3715
  <ruby>
3721
3716
  class Client < ActiveRecord::Base
3722
3717
  has_one :address
3723
-
3718
+
3724
3719
  delegate :address_line_1, :to => :address
3725
3720
  end
3726
3721
  </ruby>
@@ -3741,7 +3736,7 @@ h4. +require 'active_support/core_ext/class/attribute_accessors'+
3741
3736
 
3742
3737
  The file, _activesupport/lib/active_support/core_ext/class/attribute_accessors.rb_, defines the class accessor methods +cattr_writer+, +cattr_reader+ and +cattr_accessor+. +cattr_accessor+ defines a +cattr_reader+ and +cattr_writer+ for the symbol passed in. These methods work by defining class variables when you call their dynamic methods.
3743
3738
 
3744
- Throughout the Railties there a couple of common includes. They are listed here for your convenience.
3739
+ Throughout the Railties there a couple of common includes. They are listed here for your convenience.
3745
3740
 
3746
3741
  h4. +require 'active_support/core_ext/module/attr_internal+
3747
3742