rails 4.1.16 → 4.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/guides/CHANGELOG.md +13 -102
  4. data/guides/Rakefile +2 -2
  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 +5 -2
  9. data/guides/bug_report_templates/active_record_master.rb +2 -0
  10. data/guides/rails_guides.rb +2 -2
  11. data/guides/rails_guides/helpers.rb +1 -1
  12. data/guides/rails_guides/levenshtein.rb +29 -21
  13. data/guides/rails_guides/markdown.rb +6 -7
  14. data/guides/rails_guides/markdown/renderer.rb +1 -1
  15. data/guides/source/2_3_release_notes.md +3 -3
  16. data/guides/source/3_0_release_notes.md +4 -4
  17. data/guides/source/3_1_release_notes.md +2 -2
  18. data/guides/source/3_2_release_notes.md +2 -2
  19. data/guides/source/4_1_release_notes.md +8 -9
  20. data/guides/source/4_2_release_notes.md +572 -0
  21. data/guides/source/_license.html.erb +1 -1
  22. data/guides/source/_welcome.html.erb +2 -8
  23. data/guides/source/action_controller_overview.md +79 -7
  24. data/guides/source/action_mailer_basics.md +36 -11
  25. data/guides/source/action_view_overview.md +138 -119
  26. data/guides/source/active_job_basics.md +253 -0
  27. data/guides/source/active_model_basics.md +23 -0
  28. data/guides/source/active_record_basics.md +16 -15
  29. data/guides/source/active_record_callbacks.md +12 -9
  30. data/guides/source/{migrations.md → active_record_migrations.md} +90 -217
  31. data/guides/source/active_record_postgresql.md +437 -0
  32. data/guides/source/active_record_querying.md +261 -261
  33. data/guides/source/active_record_validations.md +7 -7
  34. data/guides/source/active_support_core_extensions.md +105 -44
  35. data/guides/source/active_support_instrumentation.md +3 -2
  36. data/guides/source/api_documentation_guidelines.md +62 -16
  37. data/guides/source/asset_pipeline.md +58 -46
  38. data/guides/source/association_basics.md +47 -38
  39. data/guides/source/caching_with_rails.md +31 -6
  40. data/guides/source/command_line.md +56 -25
  41. data/guides/source/configuring.md +98 -19
  42. data/guides/source/contributing_to_ruby_on_rails.md +174 -111
  43. data/guides/source/credits.html.erb +1 -1
  44. data/guides/source/debugging_rails_applications.md +438 -284
  45. data/guides/source/development_dependencies_install.md +17 -4
  46. data/guides/source/documents.yaml +11 -7
  47. data/guides/source/engines.md +192 -203
  48. data/guides/source/form_helpers.md +54 -45
  49. data/guides/source/generators.md +20 -11
  50. data/guides/source/getting_started.md +330 -191
  51. data/guides/source/i18n.md +92 -62
  52. data/guides/source/index.html.erb +1 -0
  53. data/guides/source/initialization.md +108 -59
  54. data/guides/source/layout.html.erb +1 -4
  55. data/guides/source/layouts_and_rendering.md +24 -23
  56. data/guides/source/nested_model_forms.md +3 -3
  57. data/guides/source/plugins.md +26 -26
  58. data/guides/source/rails_application_templates.md +21 -3
  59. data/guides/source/rails_on_rack.md +1 -1
  60. data/guides/source/routing.md +97 -71
  61. data/guides/source/ruby_on_rails_guides_guidelines.md +10 -12
  62. data/guides/source/security.md +39 -33
  63. data/guides/source/testing.md +111 -108
  64. data/guides/source/upgrading_ruby_on_rails.md +131 -14
  65. data/guides/source/working_with_javascript_in_rails.md +18 -16
  66. data/guides/w3c_validator.rb +2 -0
  67. metadata +37 -94
  68. data/guides/bug_report_templates/generic_gem.rb +0 -15
  69. data/guides/bug_report_templates/generic_master.rb +0 -26
  70. data/guides/code/getting_started/Gemfile +0 -40
  71. data/guides/code/getting_started/Gemfile.lock +0 -125
  72. data/guides/code/getting_started/README.rdoc +0 -28
  73. data/guides/code/getting_started/Rakefile +0 -6
  74. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  75. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  76. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  77. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  78. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  79. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  80. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  81. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  82. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  83. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  84. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  85. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  86. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  87. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  88. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  89. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  90. data/guides/code/getting_started/app/models/comment.rb +0 -3
  91. data/guides/code/getting_started/app/models/post.rb +0 -7
  92. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  93. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  94. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  95. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  96. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  97. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  98. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  99. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  100. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  101. data/guides/code/getting_started/bin/bundle +0 -4
  102. data/guides/code/getting_started/bin/rails +0 -4
  103. data/guides/code/getting_started/bin/rake +0 -4
  104. data/guides/code/getting_started/config.ru +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/db/migrate/20130122042648_create_posts.rb +0 -10
  123. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  124. data/guides/code/getting_started/db/schema.rb +0 -33
  125. data/guides/code/getting_started/db/seeds.rb +0 -7
  126. data/guides/code/getting_started/public/404.html +0 -60
  127. data/guides/code/getting_started/public/422.html +0 -60
  128. data/guides/code/getting_started/public/500.html +0 -59
  129. data/guides/code/getting_started/public/favicon.ico +0 -0
  130. data/guides/code/getting_started/public/robots.txt +0 -5
  131. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  132. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  133. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  134. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  135. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  136. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  137. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  138. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  139. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  140. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  141. data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -28,15 +28,15 @@ config.action_controller.perform_caching = true
28
28
 
29
29
  ### Page Caching
30
30
 
31
- Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. Apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.
31
+ Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. Apache or NGINX), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.
32
32
 
33
- INFO: Page Caching has been removed from Rails 4. See the [actionpack-page_caching gem](https://github.com/rails/actionpack-page_caching). See [DHH's key-based cache expiration overview](http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works) for the newly-preferred method.
33
+ INFO: Page Caching has been removed from Rails 4. See the [actionpack-page_caching gem](https://github.com/rails/actionpack-page_caching). See [DHH's key-based cache expiration overview](http://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works) for the newly-preferred method.
34
34
 
35
35
  ### Action Caching
36
36
 
37
37
  Page Caching cannot be used for actions that have before filters - for example, pages that require authentication. This is where Action Caching comes in. Action Caching works like Page Caching except the incoming web request hits the Rails stack so that before filters can be run on it before the cache is served. This allows authentication and other restrictions to be run while still serving the result of the output from a cached copy.
38
38
 
39
- INFO: Action Caching has been removed from Rails 4. See the [actionpack-action_caching gem](https://github.com/rails/actionpack-action_caching). See [DHH's key-based cache expiration overview](http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works) for the newly-preferred method.
39
+ INFO: Action Caching has been removed from Rails 4. See the [actionpack-action_caching gem](https://github.com/rails/actionpack-action_caching). See [DHH's key-based cache expiration overview](http://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works) for the newly-preferred method.
40
40
 
41
41
  ### Fragment Caching
42
42
 
@@ -105,7 +105,7 @@ This method generates a cache key that depends on all products and can be used i
105
105
  <% end %>
106
106
  ```
107
107
 
108
- If you want to cache a fragment under certain condition you can use `cache_if` or `cache_unless`
108
+ If you want to cache a fragment under certain condition you can use `cache_if` or `cache_unless`
109
109
 
110
110
  ```erb
111
111
  <% cache_if (condition, cache_key_for_products) do %>
@@ -140,6 +140,26 @@ You can also combine the two schemes which is called "Russian Doll Caching":
140
140
 
141
141
  It's called "Russian Doll Caching" because it nests multiple fragments. The advantage is that if a single product is updated, all the other inner fragments can be reused when regenerating the outer fragment.
142
142
 
143
+ ### Low-Level Caching
144
+
145
+ Sometimes you need to cache a particular value or query result, instead of caching view fragments. Rails caching mechanism works great for storing __any__ kind of information.
146
+
147
+ The most efficient way to implement low-level caching is using the `Rails.cache.fetch` method. This method does both reading and writing to the cache. When passed only a single argument, the key is fetched and value from the cache is returned. If a block is passed, the result of the block will be cached to the given key and the result is returned.
148
+
149
+ Consider the following example. An application has a `Product` model with an instance method that looks up the product’s price on a competing website. The data returned by this method would be perfect for low-level caching:
150
+
151
+ ```ruby
152
+ class Product < ActiveRecord::Base
153
+ def competing_price
154
+ Rails.cache.fetch("#{cache_key}/competing_price", expires_in: 12.hours) do
155
+ Competitor::API.find_price(id)
156
+ end
157
+ end
158
+ end
159
+ ```
160
+
161
+ NOTE: Notice that in this example we used `cache_key` method, so the resulting cache-key will be something like `products/233-20140225082222765838000/competing_price`. `cache_key` generates a string based on the model’s `id` and `updated_at` attributes. This is a common convention and has the benefit of invalidating the cache whenever the product is updated. In general, when you use low-level caching for instance level information, you need to generate a cache key.
162
+
143
163
  ### SQL Caching
144
164
 
145
165
  Query caching is a Rails feature that caches the result set returned by each query so that if Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again.
@@ -165,7 +185,7 @@ end
165
185
  Cache Stores
166
186
  ------------
167
187
 
168
- Rails provides different stores for the cached data created by <b>action</b> and <b>fragment</b> caches.
188
+ Rails provides different stores for the cached data created by **action** and **fragment** caches.
169
189
 
170
190
  TIP: Page caches are always stored on disk.
171
191
 
@@ -333,7 +353,12 @@ Instead of an options hash, you can also simply pass in a model, Rails will use
333
353
  class ProductsController < ApplicationController
334
354
  def show
335
355
  @product = Product.find(params[:id])
336
- respond_with(@product) if stale?(@product)
356
+
357
+ if stale?(@product)
358
+ respond_to do |wants|
359
+ # ... normal response processing
360
+ end
361
+ end
337
362
  end
338
363
  end
339
364
  ```
@@ -7,7 +7,6 @@ After reading this guide, you will know:
7
7
  * How to generate models, controllers, database migrations, and unit tests.
8
8
  * How to start a development server.
9
9
  * How to experiment with objects through an interactive shell.
10
- * How to profile and benchmark your new creation.
11
10
 
12
11
  --------------------------------------------------------------------------------
13
12
 
@@ -62,7 +61,7 @@ With no further work, `rails server` will run our new shiny Rails app:
62
61
  $ cd commandsapp
63
62
  $ bin/rails server
64
63
  => Booting WEBrick
65
- => Rails 4.1.4 application starting in development on http://0.0.0.0:3000
64
+ => Rails 4.2.0 application starting in development on http://0.0.0.0:3000
66
65
  => Call with -d to detach
67
66
  => Ctrl-C to shutdown server
68
67
  [2013-08-07 02:00:01] INFO WEBrick 1.3.1
@@ -123,19 +122,18 @@ Usage: rails generate controller NAME [action action] [options]
123
122
  Description:
124
123
  ...
125
124
 
126
- To create a controller within a module, specify the controller name as a
127
- path like 'parent_module/controller_name'.
125
+ To create a controller within a module, specify the controller name as a path like 'parent_module/controller_name'.
128
126
 
129
127
  ...
130
128
 
131
129
  Example:
132
- `rails generate controller CreditCard open debit credit close`
130
+ `rails generate controller CreditCards open debit credit close`
133
131
 
134
- Credit card controller with URLs like /credit_card/debit.
132
+ Credit card controller with URLs like /credit_cards/debit.
135
133
  Controller: app/controllers/credit_card_controller.rb
136
- Test: test/controllers/credit_card_controller_test.rb
137
- Views: app/views/credit_card/debit.html.erb [...]
138
- Helper: app/helpers/credit_card_helper.rb
134
+ Test: test/controllers/credit_cards_controller_test.rb
135
+ Views: app/views/credit_cards/debit.html.erb [...]
136
+ Helper: app/helpers/credit_cards_helper.rb
139
137
  ```
140
138
 
141
139
  The controller generator is expecting parameters in the form of `generate controller ControllerName action1 action2`. Let's make a `Greetings` controller with an action of **hello**, which will say something nice to us.
@@ -151,8 +149,6 @@ $ bin/rails generate controller Greetings hello
151
149
  create test/controllers/greetings_controller_test.rb
152
150
  invoke helper
153
151
  create app/helpers/greetings_helper.rb
154
- invoke test_unit
155
- create test/helpers/greetings_helper_test.rb
156
152
  invoke assets
157
153
  invoke coffee
158
154
  create app/assets/javascripts/greetings.js.coffee
@@ -238,8 +234,6 @@ $ bin/rails generate scaffold HighScore game:string score:integer
238
234
  create test/controllers/high_scores_controller_test.rb
239
235
  invoke helper
240
236
  create app/helpers/high_scores_helper.rb
241
- invoke test_unit
242
- create test/helpers/high_scores_helper_test.rb
243
237
  invoke jbuilder
244
238
  create app/views/high_scores/index.json.jbuilder
245
239
  create app/views/high_scores/show.json.jbuilder
@@ -254,7 +248,7 @@ $ bin/rails generate scaffold HighScore game:string score:integer
254
248
 
255
249
  The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the `high_scores` table and fields), takes care of the route for the **resource**, and new tests for everything.
256
250
 
257
- The migration requires that we **migrate**, that is, run some Ruby code (living in that `20130717151933_create_high_scores.rb`) to modify the schema of our database. Which database? The sqlite3 database that Rails will create for you when we run the `rake db:migrate` command. We'll talk more about Rake in-depth in a little while.
251
+ The migration requires that we **migrate**, that is, run some Ruby code (living in that `20130717151933_create_high_scores.rb`) to modify the schema of our database. Which database? The SQLite3 database that Rails will create for you when we run the `rake db:migrate` command. We'll talk more about Rake in-depth in a little while.
258
252
 
259
253
  ```bash
260
254
  $ bin/rake db:migrate
@@ -290,11 +284,36 @@ If you wish to test out some code without changing any data, you can do that by
290
284
 
291
285
  ```bash
292
286
  $ bin/rails console --sandbox
293
- Loading development environment in sandbox (Rails 4.1.4)
287
+ Loading development environment in sandbox (Rails 4.2.0)
294
288
  Any modifications you make will be rolled back on exit
295
289
  irb(main):001:0>
296
290
  ```
297
291
 
292
+ #### The app and helper objects
293
+
294
+ Inside the `rails console` you have access to the `app` and `helper` instances.
295
+
296
+ With the `app` method you can access url and path helpers, as well as do requests.
297
+
298
+ ```bash
299
+ >> app.root_path
300
+ => "/"
301
+
302
+ >> app.get _
303
+ Started GET "/" for 127.0.0.1 at 2014-06-19 10:41:57 -0300
304
+ ...
305
+ ```
306
+
307
+ With the `helper` method it is possible to access Rails and your application's helpers.
308
+
309
+ ```bash
310
+ >> helper.time_ago_in_words 30.days.ago
311
+ => "about 1 month"
312
+
313
+ >> helper.my_custom_helper
314
+ => "my custom helper"
315
+ ```
316
+
298
317
  ### `rails dbconsole`
299
318
 
300
319
  `rails dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3.
@@ -355,7 +374,8 @@ To get the full backtrace for running rake task you can pass the option
355
374
  ```bash
356
375
  $ bin/rake --tasks
357
376
  rake about # List versions of all Rails frameworks and the environment
358
- rake assets:clean # Remove compiled assets
377
+ rake assets:clean # Remove old compiled assets
378
+ rake assets:clobber # Remove compiled assets
359
379
  rake assets:precompile # Compile all the assets named in config.assets.precompile
360
380
  rake db:create # Create the database from config/database.yml for the current Rails.env
361
381
  ...
@@ -377,13 +397,13 @@ About your application's environment
377
397
  Ruby version 1.9.3 (x86_64-linux)
378
398
  RubyGems version 1.3.6
379
399
  Rack version 1.3
380
- Rails version 4.1.4
400
+ Rails version 4.2.0
381
401
  JavaScript Runtime Node.js (V8)
382
- Active Record version 4.1.4
383
- Action Pack version 4.1.4
384
- Action View version 4.1.4
385
- Action Mailer version 4.1.4
386
- Active Support version 4.1.4
402
+ Active Record version 4.2.0
403
+ Action Pack version 4.2.0
404
+ Action View version 4.2.0
405
+ Action Mailer version 4.2.0
406
+ Active Support version 4.2.0
387
407
  Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
388
408
  Application root /home/foobar/commandsapp
389
409
  Environment development
@@ -393,7 +413,12 @@ Database schema version 20110805173523
393
413
 
394
414
  ### `assets`
395
415
 
396
- You can precompile the assets in `app/assets` using `rake assets:precompile` and remove those compiled assets using `rake assets:clean`.
416
+ You can precompile the assets in `app/assets` using `rake assets:precompile`,
417
+ and remove older compiled assets using `rake assets:clean`. The `assets:clean`
418
+ task allows for rolling deploys that may still be linking to an old asset while
419
+ the new assets are being built.
420
+
421
+ If you want to clear `public/assets` completely, you can use `rake assets:clobber`.
397
422
 
398
423
  ### `db`
399
424
 
@@ -411,7 +436,7 @@ The `doc:` namespace has the tools to generate documentation for your app, API d
411
436
 
412
437
  ### `notes`
413
438
 
414
- `rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.erb`, `.haml` and `.slim` for both default and custom annotations.
439
+ `rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.rake`, `.yml`, `.yaml`, `.ruby`, `.css`, `.js` and `.erb` for both default and custom annotations.
415
440
 
416
441
  ```bash
417
442
  $ bin/rake notes
@@ -425,6 +450,12 @@ app/models/school.rb:
425
450
  * [ 17] [FIXME]
426
451
  ```
427
452
 
453
+ You can add support for new file extensions using `config.annotations.register_extensions` option, which receives a list of the extensions with its corresponding regex to match it up.
454
+
455
+ ```ruby
456
+ config.annotations.register_extensions("scss", "sass", "less") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
457
+ ```
458
+
428
459
  If you are looking for a specific annotation, say FIXME, you can use `rake notes:fixme`. Note that you have to lower case the annotation's name.
429
460
 
430
461
  ```bash
@@ -442,7 +473,7 @@ You can also use custom annotations in your code and list them using `rake notes
442
473
  ```bash
443
474
  $ bin/rake notes:custom ANNOTATION=BUG
444
475
  (in /home/foobar/commandsapp)
445
- app/models/post.rb:
476
+ app/models/article.rb:
446
477
  * [ 23] Have to fix this one before pushing!
447
478
  ```
448
479
 
@@ -56,7 +56,7 @@ These configuration methods are to be called on a `Rails::Railtie` object, such
56
56
  end
57
57
  ```
58
58
 
59
- * `config.asset_host` sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints builtin in browsers using different domain aliases. Shorter version of `config.action_controller.asset_host`.
59
+ * `config.asset_host` sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints built-in in browsers using different domain aliases. Shorter version of `config.action_controller.asset_host`.
60
60
 
61
61
  * `config.autoload_once_paths` accepts an array of paths from which Rails will autoload constants that won't be wiped per request. Relevant if `config.cache_classes` is false, which is the case in development mode by default. Otherwise, all autoloading happens only once. All elements of this array must also be in `autoload_paths`. Default is an empty array.
62
62
 
@@ -110,7 +110,7 @@ numbers. New applications filter out passwords by adding the following `config.f
110
110
 
111
111
  * `config.log_level` defines the verbosity of the Rails logger. This option defaults to `:debug` for all modes except production, where it defaults to `:info`.
112
112
 
113
- * `config.log_tags` accepts a list of methods that respond to `request` object. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications.
113
+ * `config.log_tags` accepts a list of methods that the `request` object responds to. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications.
114
114
 
115
115
  * `config.logger` accepts a logger conforming to the interface of Log4r or the default Ruby `Logger` class. Defaults to an instance of `ActiveSupport::Logger`, with auto flushing off in production mode.
116
116
 
@@ -118,9 +118,9 @@ numbers. New applications filter out passwords by adding the following `config.f
118
118
 
119
119
  * `config.reload_classes_only_on_change` enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to true. If `config.cache_classes` is true, this option is ignored.
120
120
 
121
- * `config.secret_key_base` used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get `config.secret_key_base` initialized to a random key in `config/initializers/secret_token.rb`.
121
+ * `secrets.secret_key_base` is used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get `secrets.secret_key_base` initialized to a random key present in `config/secrets.yml`.
122
122
 
123
- * `config.serve_static_assets` configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won't be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
123
+ * `config.serve_static_assets` configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. NGINX or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won't be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
124
124
 
125
125
  * `config.session_store` is usually set up in `config/initializers/session_store.rb` and specifies what class to use to store the session. Possible values are `:cookie_store` which is the default, `:mem_cache_store`, and `:disabled`. The last one tells Rails not to deal with sessions. Custom session stores can also be specified:
126
126
 
@@ -137,7 +137,7 @@ numbers. New applications filter out passwords by adding the following `config.f
137
137
  * `config.assets.enabled` a flag that controls whether the asset
138
138
  pipeline is enabled. It is set to true by default.
139
139
 
140
- *`config.assets.raise_runtime_errors`* Set this flag to `true` to enable additional runtime error checking. Recommended in `config/environments/development.rb` to minimize unexpected behavior when deploying to `production`.
140
+ * `config.assets.raise_runtime_errors`* Set this flag to `true` to enable additional runtime error checking. Recommended in `config/environments/development.rb` to minimize unexpected behavior when deploying to `production`.
141
141
 
142
142
  * `config.assets.compress` a flag that enables the compression of compiled assets. It is explicitly set to true in `config/environments/production.rb`.
143
143
 
@@ -151,6 +151,8 @@ pipeline is enabled. It is set to true by default.
151
151
 
152
152
  * `config.assets.prefix` defines the prefix where assets are served from. Defaults to `/assets`.
153
153
 
154
+ * `config.assets.manifest` defines the full path to be used for the asset precompiler's manifest file. Defaults to a file named `manifest-<random>.json` in the `config.assets.prefix` directory within the public folder.
155
+
154
156
  * `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb`.
155
157
 
156
158
  * `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`.
@@ -330,6 +332,8 @@ The schema dumper adds one additional configuration option:
330
332
 
331
333
  * `config.action_controller.action_on_unpermitted_parameters` enables logging or raising an exception if parameters that are not explicitly permitted are found. Set to `:log` or `:raise` to enable. The default value is `:log` in development and test environments, and `false` in all other environments.
332
334
 
335
+ * `config.action_controller.always_permitted_parameters` sets a list of whitelisted parameters that are permitted by default. The default values are `['controller', 'action']`.
336
+
333
337
  ### Configuring Action Dispatch
334
338
 
335
339
  * `config.action_dispatch.session_store` sets the name of the store for session data. The default is `:cookie_store`; other valid options include `:active_record_store`, `:mem_cache_store` or the name of your own custom class.
@@ -388,13 +392,13 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
388
392
 
389
393
  * `config.action_view.embed_authenticity_token_in_remote_forms` allows you to set the default behavior for `authenticity_token` in forms with `:remote => true`. By default it's set to false, which means that remote forms will not include `authenticity_token`, which is helpful when you're fragment-caching the form. Remote forms get the authenticity from the `meta` tag, so embedding is unnecessary unless you support browsers without JavaScript. In such case you can either pass `:authenticity_token => true` as a form option or set this config setting to `true`
390
394
 
391
- * `config.action_view.prefix_partial_path_with_controller_namespace` determines whether or not partials are looked up from a subdirectory in templates rendered from namespaced controllers. For example, consider a controller named `Admin::PostsController` which renders this template:
395
+ * `config.action_view.prefix_partial_path_with_controller_namespace` determines whether or not partials are looked up from a subdirectory in templates rendered from namespaced controllers. For example, consider a controller named `Admin::ArticlesController` which renders this template:
392
396
 
393
397
  ```erb
394
- <%= render @post %>
398
+ <%= render @article %>
395
399
  ```
396
400
 
397
- The default setting is `true`, which uses the partial at `/admin/posts/_post.erb`. Setting the value to `false` would render `/posts/_post.erb`, which is the same behavior as rendering from a non-namespaced controller such as `PostsController`.
401
+ The default setting is `true`, which uses the partial at `/admin/articles/_article.erb`. Setting the value to `false` would render `/articles/_article.erb`, which is the same behavior as rendering from a non-namespaced controller such as `ArticlesController`.
398
402
 
399
403
  * `config.action_view.raise_on_missing_translations` determines whether an error should be raised for missing translations
400
404
 
@@ -451,6 +455,18 @@ There are a number of settings available on `config.action_mailer`:
451
455
  config.action_mailer.interceptors = ["MailInterceptor"]
452
456
  ```
453
457
 
458
+ * `config.action_mailer.preview_path` specifies the location of mailer previews.
459
+
460
+ ```ruby
461
+ config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
462
+ ```
463
+
464
+ * `config.action_mailer.show_previews` enable or disable mailer previews. By default this is `true` in development.
465
+
466
+ ```ruby
467
+ config.action_mailer.show_previews = false
468
+ ```
469
+
454
470
  ### Configuring Active Support
455
471
 
456
472
  There are a few configuration options available in Active Support:
@@ -552,7 +568,7 @@ development:
552
568
  $ echo $DATABASE_URL
553
569
  postgresql://localhost/my_database
554
570
 
555
- $ bin/rails runner 'puts ActiveRecord::Base.connections'
571
+ $ bin/rails runner 'puts ActiveRecord::Base.configurations'
556
572
  {"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database"}}
557
573
  ```
558
574
 
@@ -569,7 +585,7 @@ development:
569
585
  $ echo $DATABASE_URL
570
586
  postgresql://localhost/my_database
571
587
 
572
- $ bin/rails runner 'puts ActiveRecord::Base.connections'
588
+ $ bin/rails runner 'puts ActiveRecord::Base.configurations'
573
589
  {"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database", "pool"=>5}}
574
590
  ```
575
591
 
@@ -585,7 +601,7 @@ development:
585
601
  $ echo $DATABASE_URL
586
602
  postgresql://localhost/my_database
587
603
 
588
- $ bin/rails runner 'puts ActiveRecord::Base.connections'
604
+ $ bin/rails runner 'puts ActiveRecord::Base.configurations'
589
605
  {"development"=>{"adapter"=>"sqlite3", "database"=>"NOT_my_database"}}
590
606
  ```
591
607
 
@@ -644,11 +660,9 @@ development:
644
660
  encoding: unicode
645
661
  database: blog_development
646
662
  pool: 5
647
- username: blog
648
- password:
649
663
  ```
650
664
 
651
- Prepared Statements can be disabled thus:
665
+ Prepared Statements are enabled by default on PostgreSQL. You can be disable prepared statements by setting `prepared_statements` to `false`:
652
666
 
653
667
  ```yaml
654
668
  production:
@@ -656,6 +670,16 @@ production:
656
670
  prepared_statements: false
657
671
  ```
658
672
 
673
+ If enabled, Active Record will create up to `1000` prepared statements per database connection by default. To modify this behavior you can set `statement_limit` to a different value:
674
+
675
+ ```
676
+ production:
677
+ adapter: postgresql
678
+ statement_limit: 200
679
+ ```
680
+
681
+ The more prepared statements in use: the more memory your database will require. If your PostgreSQL database is hitting memory limits, try lowering `statement_limit` or disabling prepared statements.
682
+
659
683
  #### Configuring an SQLite3 Database for JRuby Platform
660
684
 
661
685
  If you choose to use SQLite3 and are using JRuby, your `config/database.yml` will look a little different. Here's the development section:
@@ -721,13 +745,47 @@ Rails will now prepend "/app1" when generating links.
721
745
 
722
746
  #### Using Passenger
723
747
 
724
- Passenger makes it easy to run your application in a subdirectory. You can find
725
- the relevant configuration in the
726
- [passenger manual](http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri).
748
+ Passenger makes it easy to run your application in a subdirectory. You can find the relevant configuration in the [Passenger manual](http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri).
727
749
 
728
750
  #### Using a Reverse Proxy
729
751
 
730
- TODO
752
+ Deploying your application using a reverse proxy has definite advantages over traditional deploys. They allow you to have more control over your server by layering the components required by your application.
753
+
754
+ Many modern web servers can be used as a proxy server to balance third-party elements such as caching servers or application servers.
755
+
756
+ One such application server you can use is [Unicorn](http://unicorn.bogomips.org/) to run behind a reverse proxy.
757
+
758
+ In this case, you would need to configure the proxy server (NGINX, Apache, etc) to accept connections from your application server (Unicorn). By default Unicorn will listen for TCP connections on port 8080, but you can change the port or configure it to use sockets instead.
759
+
760
+ You can find more information in the [Unicorn readme](http://unicorn.bogomips.org/README.html) and understand the [philosophy](http://unicorn.bogomips.org/PHILOSOPHY.html) behind it.
761
+
762
+ Once you've configured the application server, you must proxy requests to it by configuring your web server appropriately. For example your NGINX config may include:
763
+
764
+ ```
765
+ upstream application_server {
766
+ server 0.0.0.0:8080
767
+ }
768
+
769
+ server {
770
+ listen 80;
771
+ server_name localhost;
772
+
773
+ root /root/path/to/your_app/public;
774
+
775
+ try_files $uri/index.html $uri.html @app;
776
+
777
+ location @app {
778
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
779
+ proxy_set_header Host $http_host;
780
+ proxy_redirect off;
781
+ proxy_pass http://application_server;
782
+ }
783
+
784
+ # some other configuration
785
+ }
786
+ ```
787
+
788
+ Be sure to read the [NGINX documentation](http://nginx.org/en/docs/) for the most up-to-date information.
731
789
 
732
790
  #### Considerations when deploying to a subdirectory
733
791
 
@@ -939,4 +997,25 @@ ActiveRecord::ConnectionTimeoutError - could not obtain a database connection wi
939
997
  If you get the above error, you might want to increase the size of connection
940
998
  pool by incrementing the `pool` option in `database.yml`
941
999
 
942
- NOTE. As Rails is multi-threaded by default, there could be a chance that several threads may be accessing multiple connections simultaneously. So depending on your current request load, you could very well have multiple threads contending for a limited amount of connections.
1000
+ NOTE. If you are running in a multi-threaded environment, there could be a chance that several threads may be accessing multiple connections simultaneously. So depending on your current request load, you could very well have multiple threads contending for a limited amount of connections.
1001
+
1002
+
1003
+ Custom configuration
1004
+ --------------------
1005
+
1006
+ You can configure your own code through the Rails configuration object with custom configuration. It works like this:
1007
+
1008
+ ```ruby
1009
+ config.x.payment_processing.schedule = :daily
1010
+ config.x.payment_processing.retries = 3
1011
+ config.x.super_debugger = true
1012
+ ```
1013
+
1014
+ These configuration points are then available through the configuration object:
1015
+
1016
+ ```ruby
1017
+ Rails.configuration.x.payment_processing.schedule # => :daily
1018
+ Rails.configuration.x.payment_processing.retries # => 3
1019
+ Rails.configuration.x.super_debugger # => true
1020
+ Rails.configuration.x.super_debugger.not_set # => nil
1021
+ ```