rails 4.1.4 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -10
  3. data/guides/CHANGELOG.md +15 -25
  4. data/guides/Rakefile +5 -3
  5. data/guides/assets/javascripts/guides.js +6 -0
  6. data/guides/assets/stylesheets/main.css +4 -1
  7. data/guides/bug_report_templates/action_controller_gem.rb +2 -2
  8. data/guides/bug_report_templates/action_controller_master.rb +3 -2
  9. data/guides/rails_guides/helpers.rb +1 -1
  10. data/guides/rails_guides/levenshtein.rb +29 -21
  11. data/guides/rails_guides/markdown/renderer.rb +1 -1
  12. data/guides/rails_guides/markdown.rb +11 -7
  13. data/guides/rails_guides.rb +2 -2
  14. data/guides/source/2_2_release_notes.md +1 -1
  15. data/guides/source/2_3_release_notes.md +4 -4
  16. data/guides/source/3_0_release_notes.md +8 -8
  17. data/guides/source/3_1_release_notes.md +5 -2
  18. data/guides/source/3_2_release_notes.md +6 -3
  19. data/guides/source/4_0_release_notes.md +6 -3
  20. data/guides/source/4_1_release_notes.md +10 -11
  21. data/guides/source/4_2_release_notes.md +850 -0
  22. data/guides/source/_license.html.erb +1 -1
  23. data/guides/source/_welcome.html.erb +2 -8
  24. data/guides/source/action_controller_overview.md +84 -10
  25. data/guides/source/action_mailer_basics.md +91 -28
  26. data/guides/source/action_view_overview.md +140 -130
  27. data/guides/source/active_job_basics.md +318 -0
  28. data/guides/source/active_model_basics.md +371 -17
  29. data/guides/source/active_record_basics.md +19 -18
  30. data/guides/source/active_record_callbacks.md +12 -9
  31. data/guides/source/{migrations.md → active_record_migrations.md} +135 -226
  32. data/guides/source/active_record_postgresql.md +433 -0
  33. data/guides/source/active_record_querying.md +269 -259
  34. data/guides/source/active_record_validations.md +21 -12
  35. data/guides/source/active_support_core_extensions.md +113 -73
  36. data/guides/source/active_support_instrumentation.md +10 -7
  37. data/guides/source/api_documentation_guidelines.md +62 -16
  38. data/guides/source/asset_pipeline.md +264 -67
  39. data/guides/source/association_basics.md +81 -74
  40. data/guides/source/caching_with_rails.md +32 -7
  41. data/guides/source/command_line.md +52 -30
  42. data/guides/source/configuring.md +132 -29
  43. data/guides/source/constant_autoloading_and_reloading.md +1297 -0
  44. data/guides/source/contributing_to_ruby_on_rails.md +192 -112
  45. data/guides/source/credits.html.erb +2 -2
  46. data/guides/source/debugging_rails_applications.md +448 -294
  47. data/guides/source/development_dependencies_install.md +47 -36
  48. data/guides/source/documents.yaml +19 -7
  49. data/guides/source/engines.md +210 -189
  50. data/guides/source/form_helpers.md +79 -56
  51. data/guides/source/generators.md +24 -11
  52. data/guides/source/getting_started.md +339 -201
  53. data/guides/source/i18n.md +111 -68
  54. data/guides/source/index.html.erb +1 -0
  55. data/guides/source/initialization.md +109 -62
  56. data/guides/source/layout.html.erb +1 -4
  57. data/guides/source/layouts_and_rendering.md +18 -17
  58. data/guides/source/maintenance_policy.md +26 -4
  59. data/guides/source/nested_model_forms.md +7 -4
  60. data/guides/source/plugins.md +27 -27
  61. data/guides/source/rails_application_templates.md +21 -3
  62. data/guides/source/rails_on_rack.md +12 -9
  63. data/guides/source/routing.md +100 -74
  64. data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
  65. data/guides/source/security.md +40 -34
  66. data/guides/source/testing.md +188 -117
  67. data/guides/source/upgrading_ruby_on_rails.md +284 -29
  68. data/guides/source/working_with_javascript_in_rails.md +18 -16
  69. data/guides/w3c_validator.rb +2 -0
  70. metadata +40 -94
  71. data/guides/code/getting_started/Gemfile +0 -40
  72. data/guides/code/getting_started/Gemfile.lock +0 -125
  73. data/guides/code/getting_started/README.rdoc +0 -28
  74. data/guides/code/getting_started/Rakefile +0 -6
  75. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  76. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  77. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  78. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  79. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  80. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  81. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  82. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  83. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  84. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  85. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  86. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  87. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  88. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  89. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  90. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  91. data/guides/code/getting_started/app/models/comment.rb +0 -3
  92. data/guides/code/getting_started/app/models/post.rb +0 -7
  93. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  94. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  95. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  96. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  97. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  98. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  99. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  100. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  101. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  102. data/guides/code/getting_started/bin/bundle +0 -4
  103. data/guides/code/getting_started/bin/rails +0 -4
  104. data/guides/code/getting_started/bin/rake +0 -4
  105. data/guides/code/getting_started/config/application.rb +0 -18
  106. data/guides/code/getting_started/config/boot.rb +0 -4
  107. data/guides/code/getting_started/config/database.yml +0 -25
  108. data/guides/code/getting_started/config/environment.rb +0 -5
  109. data/guides/code/getting_started/config/environments/development.rb +0 -30
  110. data/guides/code/getting_started/config/environments/production.rb +0 -80
  111. data/guides/code/getting_started/config/environments/test.rb +0 -36
  112. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  113. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  114. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  115. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  116. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  117. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  118. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  119. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  120. data/guides/code/getting_started/config/locales/en.yml +0 -23
  121. data/guides/code/getting_started/config/routes.rb +0 -7
  122. data/guides/code/getting_started/config.ru +0 -4
  123. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  124. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  125. data/guides/code/getting_started/db/schema.rb +0 -33
  126. data/guides/code/getting_started/db/seeds.rb +0 -7
  127. data/guides/code/getting_started/public/404.html +0 -60
  128. data/guides/code/getting_started/public/422.html +0 -60
  129. data/guides/code/getting_started/public/500.html +0 -59
  130. data/guides/code/getting_started/public/favicon.ico +0 -0
  131. data/guides/code/getting_started/public/robots.txt +0 -5
  132. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  133. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  134. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  135. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  136. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  137. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  138. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  139. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  140. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  141. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  142. data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -39,13 +39,13 @@ to run integration tests using a dummy Rails application. Create your
39
39
  plugin with the command:
40
40
 
41
41
  ```bash
42
- $ bin/rails plugin new yaffle
42
+ $ rails plugin new yaffle
43
43
  ```
44
44
 
45
45
  See usage and options by asking for help:
46
46
 
47
47
  ```bash
48
- $ bin/rails plugin --help
48
+ $ rails plugin new --help
49
49
  ```
50
50
 
51
51
  Testing Your Newly Generated Plugin
@@ -57,7 +57,7 @@ You can navigate to the directory that contains the plugin, run the `bundle inst
57
57
  You should see:
58
58
 
59
59
  ```bash
60
- 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
60
+ 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
61
61
  ```
62
62
 
63
63
  This will tell you that everything got generated properly and you are ready to start adding functionality.
@@ -85,19 +85,19 @@ Run `rake` to run the test. This test should fail because we haven't implemented
85
85
 
86
86
  ```bash
87
87
  1) Error:
88
- test_to_squawk_prepends_the_word_squawk(CoreExtTest):
89
- NoMethodError: undefined method `to_squawk' for [Hello World](String)
90
- test/core_ext_test.rb:5:in `test_to_squawk_prepends_the_word_squawk'
88
+ CoreExtTest#test_to_squawk_prepends_the_word_squawk:
89
+ NoMethodError: undefined method `to_squawk' for "Hello World":String
90
+ /path/to/yaffle/test/core_ext_test.rb:5:in `test_to_squawk_prepends_the_word_squawk'
91
91
  ```
92
92
 
93
93
  Great - now you are ready to start development.
94
94
 
95
- In `lib/yaffle.rb`, add `require "yaffle/core_ext"`:
95
+ In `lib/yaffle.rb`, add `require 'yaffle/core_ext'`:
96
96
 
97
97
  ```ruby
98
98
  # yaffle/lib/yaffle.rb
99
99
 
100
- require "yaffle/core_ext"
100
+ require 'yaffle/core_ext'
101
101
 
102
102
  module Yaffle
103
103
  end
@@ -118,7 +118,7 @@ end
118
118
  To test that your method does what it says it does, run the unit tests with `rake` from your plugin directory.
119
119
 
120
120
  ```bash
121
- 3 tests, 3 assertions, 0 failures, 0 errors, 0 skips
121
+ 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
122
122
  ```
123
123
 
124
124
  To see this in action, change to the test/dummy directory, fire up a console and start squawking:
@@ -149,7 +149,7 @@ end
149
149
  ```ruby
150
150
  # yaffle/lib/yaffle.rb
151
151
 
152
- require "yaffle/core_ext"
152
+ require 'yaffle/core_ext'
153
153
  require 'yaffle/acts_as_yaffle'
154
154
 
155
155
  module Yaffle
@@ -196,16 +196,16 @@ When you run `rake`, you should see the following:
196
196
 
197
197
  ```
198
198
  1) Error:
199
- test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest):
199
+ ActsAsYaffleTest#test_a_hickwalls_yaffle_text_field_should_be_last_squawk:
200
200
  NameError: uninitialized constant ActsAsYaffleTest::Hickwall
201
- test/acts_as_yaffle_test.rb:6:in `test_a_hickwalls_yaffle_text_field_should_be_last_squawk'
201
+ /path/to/yaffle/test/acts_as_yaffle_test.rb:6:in `test_a_hickwalls_yaffle_text_field_should_be_last_squawk'
202
202
 
203
203
  2) Error:
204
- test_a_wickwalls_yaffle_text_field_should_be_last_tweet(ActsAsYaffleTest):
204
+ ActsAsYaffleTest#test_a_wickwalls_yaffle_text_field_should_be_last_tweet:
205
205
  NameError: uninitialized constant ActsAsYaffleTest::Wickwall
206
- test/acts_as_yaffle_test.rb:10:in `test_a_wickwalls_yaffle_text_field_should_be_last_tweet'
206
+ /path/to/yaffle/test/acts_as_yaffle_test.rb:10:in `test_a_wickwalls_yaffle_text_field_should_be_last_tweet'
207
207
 
208
- 5 tests, 3 assertions, 0 failures, 2 errors, 0 skips
208
+ 4 runs, 2 assertions, 0 failures, 2 errors, 0 skips
209
209
  ```
210
210
 
211
211
  This tells us that we don't have the necessary models (Hickwall and Wickwall) that we are trying to test.
@@ -270,18 +270,18 @@ You can then return to the root directory (`cd ../..`) of your plugin and rerun
270
270
 
271
271
  ```
272
272
  1) Error:
273
- test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest):
274
- NoMethodError: undefined method `yaffle_text_field' for #<Class:0x000001016661b8>
275
- /Users/xxx/.rvm/gems/ruby-1.9.2-p136@xxx/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in `method_missing'
276
- test/acts_as_yaffle_test.rb:5:in `test_a_hickwalls_yaffle_text_field_should_be_last_squawk'
273
+ ActsAsYaffleTest#test_a_hickwalls_yaffle_text_field_should_be_last_squawk:
274
+ NoMethodError: undefined method `yaffle_text_field' for #<Class:0x007fd105e3b218>
275
+ activerecord (4.1.5) lib/active_record/dynamic_matchers.rb:26:in `method_missing'
276
+ /path/to/yaffle/test/acts_as_yaffle_test.rb:6:in `test_a_hickwalls_yaffle_text_field_should_be_last_squawk'
277
277
 
278
278
  2) Error:
279
- test_a_wickwalls_yaffle_text_field_should_be_last_tweet(ActsAsYaffleTest):
280
- NoMethodError: undefined method `yaffle_text_field' for #<Class:0x00000101653748>
281
- Users/xxx/.rvm/gems/ruby-1.9.2-p136@xxx/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in `method_missing'
282
- test/acts_as_yaffle_test.rb:9:in `test_a_wickwalls_yaffle_text_field_should_be_last_tweet'
279
+ ActsAsYaffleTest#test_a_wickwalls_yaffle_text_field_should_be_last_tweet:
280
+ NoMethodError: undefined method `yaffle_text_field' for #<Class:0x007fd105e409c0>
281
+ activerecord (4.1.5) lib/active_record/dynamic_matchers.rb:26:in `method_missing'
282
+ /path/to/yaffle/test/acts_as_yaffle_test.rb:10:in `test_a_wickwalls_yaffle_text_field_should_be_last_tweet'
283
283
 
284
- 5 tests, 3 assertions, 0 failures, 2 errors, 0 skips
284
+ 4 runs, 2 assertions, 0 failures, 2 errors, 0 skips
285
285
 
286
286
  ```
287
287
 
@@ -312,7 +312,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
312
312
  When you run `rake`, you should see the tests all pass:
313
313
 
314
314
  ```bash
315
- 5 tests, 5 assertions, 0 failures, 0 errors, 0 skips
315
+ 4 runs, 4 assertions, 0 failures, 0 errors, 0 skips
316
316
  ```
317
317
 
318
318
  ### Add an Instance Method
@@ -386,7 +386,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
386
386
  Run `rake` one final time and you should see:
387
387
 
388
388
  ```
389
- 7 tests, 7 assertions, 0 failures, 0 errors, 0 skips
389
+ 6 runs, 6 assertions, 0 failures, 0 errors, 0 skips
390
390
  ```
391
391
 
392
392
  NOTE: The use of `write_attribute` to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use. For example, you could also use:
@@ -440,5 +440,5 @@ $ bin/rake rdoc
440
440
 
441
441
  * [Developing a RubyGem using Bundler](https://github.com/radar/guides/blob/master/gem-development.md)
442
442
  * [Using .gemspecs as Intended](http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/)
443
- * [Gemspec Reference](http://docs.rubygems.org/read/chapter/20)
443
+ * [Gemspec Reference](http://guides.rubygems.org/specification-reference/)
444
444
  * [GemPlugins: A Brief Introduction to the Future of Rails Plugins](http://www.intridea.com/blog/2008/6/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins)
@@ -38,9 +38,11 @@ generate(:scaffold, "person name:string")
38
38
  route "root to: 'people#index'"
39
39
  rake("db:migrate")
40
40
 
41
- git :init
42
- git add: "."
43
- git commit: %Q{ -m 'Initial commit' }
41
+ after_bundle do
42
+ git :init
43
+ git add: "."
44
+ git commit: %Q{ -m 'Initial commit' }
45
+ end
44
46
  ```
45
47
 
46
48
  The following sections outline the primary methods provided by the API:
@@ -228,6 +230,22 @@ git add: "."
228
230
  git commit: "-a -m 'Initial commit'"
229
231
  ```
230
232
 
233
+ ### after_bundle(&block)
234
+
235
+ Registers a callback to be executed after the gems are bundled and binstubs
236
+ are generated. Useful for all generated files to version control:
237
+
238
+ ```ruby
239
+ after_bundle do
240
+ git :init
241
+ git add: '.'
242
+ git commit: "-a -m 'Initial commit'"
243
+ end
244
+ ```
245
+
246
+ The callbacks gets executed even if `--skip-bundle` and/or `--skip-spring` has
247
+ been passed.
248
+
231
249
  Advanced Usage
232
250
  --------------
233
251
 
@@ -18,7 +18,7 @@ Introduction to Rack
18
18
 
19
19
  Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.
20
20
 
21
- - [Rack API Documentation](http://rack.rubyforge.org/doc/)
21
+ * [Rack API Documentation](http://rack.github.io/)
22
22
 
23
23
  Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack's basics, you should check out the [Resources](#resources) section below.
24
24
 
@@ -27,10 +27,9 @@ Rails on Rack
27
27
 
28
28
  ### Rails Application's Rack Object
29
29
 
30
- `ApplicationName::Application` is the primary Rack application object of a Rails
30
+ `Rails.application` is the primary Rack application object of a Rails
31
31
  application. Any Rack compliant web server should be using
32
- `ApplicationName::Application` object to serve a Rails
33
- application. `Rails.application` refers to the same application object.
32
+ `Rails.application` object to serve a Rails application.
34
33
 
35
34
  ### `rails server`
36
35
 
@@ -100,6 +99,10 @@ To find out more about different `rackup` options:
100
99
  $ rackup --help
101
100
  ```
102
101
 
102
+ ### Development and auto-reloading
103
+
104
+ Middlewares are loaded once and are not monitored for changes. You will have to restart the server for changes to be reflected in the running application.
105
+
103
106
  Action Dispatcher Middleware Stack
104
107
  ----------------------------------
105
108
 
@@ -141,7 +144,7 @@ use ActionDispatch::ParamsParser
141
144
  use Rack::Head
142
145
  use Rack::ConditionalGet
143
146
  use Rack::ETag
144
- run MyApp::Application.routes
147
+ run Rails.application.routes
145
148
  ```
146
149
 
147
150
  The default middlewares shown here (and some others) are each summarized in the [Internal Middlewares](#internal-middleware-stack) section, below.
@@ -201,7 +204,7 @@ use ActionDispatch::Static
201
204
  use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000001c304c8>
202
205
  use Rack::Runtime
203
206
  ...
204
- run Blog::Application.routes
207
+ run Rails.application.routes
205
208
  ```
206
209
 
207
210
  If you want to remove session related middleware, do the following:
@@ -230,7 +233,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
230
233
 
231
234
  **`ActionDispatch::Static`**
232
235
 
233
- * Used to serve static assets. Disabled if `config.serve_static_assets` is `false`.
236
+ * Used to serve static files. Disabled if `config.serve_static_files` is `false`.
234
237
 
235
238
  **`Rack::Lock`**
236
239
 
@@ -274,7 +277,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
274
277
 
275
278
  **`ActionDispatch::Callbacks`**
276
279
 
277
- * Runs the prepare callbacks before serving the request.
280
+ * Provides callbacks to be executed before and after dispatching the request.
278
281
 
279
282
  **`ActiveRecord::Migration::CheckPending`**
280
283
 
@@ -304,7 +307,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
304
307
 
305
308
  * Parses out parameters from the request into `params`.
306
309
 
307
- **`ActionDispatch::Head`**
310
+ **`Rack::Head`**
308
311
 
309
312
  * Converts HEAD requests to `GET` requests and serves them as so.
310
313