rails 4.1.6 → 4.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +12 -10
  3. data/guides/CHANGELOG.md +64 -17
  4. data/guides/Rakefile +21 -6
  5. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  6. data/guides/assets/javascripts/guides.js +6 -0
  7. data/guides/assets/stylesheets/main.css +4 -1
  8. data/guides/bug_report_templates/action_controller_gem.rb +3 -3
  9. data/guides/bug_report_templates/action_controller_master.rb +3 -2
  10. data/guides/bug_report_templates/active_record_gem.rb +1 -1
  11. data/guides/bug_report_templates/generic_gem.rb +15 -0
  12. data/guides/bug_report_templates/generic_master.rb +26 -0
  13. data/guides/rails_guides/helpers.rb +1 -1
  14. data/guides/rails_guides/levenshtein.rb +27 -21
  15. data/guides/rails_guides/markdown/renderer.rb +1 -1
  16. data/guides/rails_guides/markdown.rb +11 -7
  17. data/guides/rails_guides.rb +2 -2
  18. data/guides/source/2_2_release_notes.md +1 -1
  19. data/guides/source/2_3_release_notes.md +4 -4
  20. data/guides/source/3_0_release_notes.md +8 -8
  21. data/guides/source/3_1_release_notes.md +6 -3
  22. data/guides/source/3_2_release_notes.md +6 -3
  23. data/guides/source/4_0_release_notes.md +6 -3
  24. data/guides/source/4_1_release_notes.md +9 -10
  25. data/guides/source/4_2_release_notes.md +877 -0
  26. data/guides/source/_license.html.erb +1 -1
  27. data/guides/source/_welcome.html.erb +6 -8
  28. data/guides/source/action_controller_overview.md +25 -8
  29. data/guides/source/action_mailer_basics.md +97 -29
  30. data/guides/source/action_view_overview.md +142 -191
  31. data/guides/source/active_job_basics.md +339 -0
  32. data/guides/source/active_model_basics.md +371 -17
  33. data/guides/source/active_record_basics.md +25 -24
  34. data/guides/source/active_record_callbacks.md +12 -9
  35. data/guides/source/{migrations.md → active_record_migrations.md} +95 -220
  36. data/guides/source/active_record_postgresql.md +433 -0
  37. data/guides/source/active_record_querying.md +264 -268
  38. data/guides/source/active_record_validations.md +23 -13
  39. data/guides/source/active_support_core_extensions.md +115 -123
  40. data/guides/source/active_support_instrumentation.md +10 -18
  41. data/guides/source/api_documentation_guidelines.md +63 -17
  42. data/guides/source/asset_pipeline.md +259 -120
  43. data/guides/source/association_basics.md +96 -80
  44. data/guides/source/autoloading_and_reloading_constants.md +1311 -0
  45. data/guides/source/caching_with_rails.md +32 -7
  46. data/guides/source/command_line.md +52 -30
  47. data/guides/source/configuring.md +161 -33
  48. data/guides/source/contributing_to_ruby_on_rails.md +198 -114
  49. data/guides/source/credits.html.erb +2 -2
  50. data/guides/source/debugging_rails_applications.md +440 -286
  51. data/guides/source/development_dependencies_install.md +47 -36
  52. data/guides/source/documents.yaml +19 -7
  53. data/guides/source/engines.md +217 -196
  54. data/guides/source/form_helpers.md +79 -56
  55. data/guides/source/generators.md +24 -11
  56. data/guides/source/getting_started.md +359 -219
  57. data/guides/source/i18n.md +110 -66
  58. data/guides/source/index.html.erb +1 -0
  59. data/guides/source/initialization.md +109 -62
  60. data/guides/source/layout.html.erb +5 -11
  61. data/guides/source/layouts_and_rendering.md +26 -26
  62. data/guides/source/maintenance_policy.md +6 -3
  63. data/guides/source/nested_model_forms.md +7 -4
  64. data/guides/source/plugins.md +27 -27
  65. data/guides/source/rails_application_templates.md +21 -3
  66. data/guides/source/rails_on_rack.md +8 -5
  67. data/guides/source/routing.md +113 -73
  68. data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
  69. data/guides/source/security.md +40 -34
  70. data/guides/source/testing.md +199 -119
  71. data/guides/source/upgrading_ruby_on_rails.md +289 -31
  72. data/guides/source/working_with_javascript_in_rails.md +19 -17
  73. data/guides/w3c_validator.rb +2 -0
  74. metadata +42 -95
  75. data/guides/code/getting_started/Gemfile +0 -40
  76. data/guides/code/getting_started/Gemfile.lock +0 -125
  77. data/guides/code/getting_started/README.rdoc +0 -28
  78. data/guides/code/getting_started/Rakefile +0 -6
  79. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  80. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  81. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  82. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  83. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  84. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  85. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  86. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  87. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  88. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  89. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  90. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  91. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  92. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  93. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  94. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  95. data/guides/code/getting_started/app/models/comment.rb +0 -3
  96. data/guides/code/getting_started/app/models/post.rb +0 -7
  97. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  98. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  99. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  100. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  101. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  102. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  103. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  104. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  105. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  106. data/guides/code/getting_started/bin/bundle +0 -4
  107. data/guides/code/getting_started/bin/rails +0 -4
  108. data/guides/code/getting_started/bin/rake +0 -4
  109. data/guides/code/getting_started/config/application.rb +0 -18
  110. data/guides/code/getting_started/config/boot.rb +0 -4
  111. data/guides/code/getting_started/config/database.yml +0 -25
  112. data/guides/code/getting_started/config/environment.rb +0 -5
  113. data/guides/code/getting_started/config/environments/development.rb +0 -30
  114. data/guides/code/getting_started/config/environments/production.rb +0 -80
  115. data/guides/code/getting_started/config/environments/test.rb +0 -36
  116. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  117. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  118. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  119. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  120. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  121. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  122. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  123. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  124. data/guides/code/getting_started/config/locales/en.yml +0 -23
  125. data/guides/code/getting_started/config/routes.rb +0 -7
  126. data/guides/code/getting_started/config.ru +0 -4
  127. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  128. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  129. data/guides/code/getting_started/db/schema.rb +0 -33
  130. data/guides/code/getting_started/db/seeds.rb +0 -7
  131. data/guides/code/getting_started/public/404.html +0 -60
  132. data/guides/code/getting_started/public/422.html +0 -60
  133. data/guides/code/getting_started/public/500.html +0 -59
  134. data/guides/code/getting_started/public/favicon.ico +0 -0
  135. data/guides/code/getting_started/public/robots.txt +0 -5
  136. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  137. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  138. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  139. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  140. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  141. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  142. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  143. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  144. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  145. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  146. 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,12 +353,17 @@ 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
  ```
340
365
 
341
- If you don't have any special response processing and are using the default rendering mechanism (i.e. you're not using respond_to or calling render yourself) then you've got an easy helper in fresh_when:
366
+ If you don't have any special response processing and are using the default rendering mechanism (i.e. you're not using `respond_to` or calling render yourself) then you've got an easy helper in `fresh_when`:
342
367
 
343
368
  ```ruby
344
369
  class ProductsController < ApplicationController
@@ -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://localhost: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
@@ -80,7 +79,7 @@ The server can be run on a different port using the `-p` option. The default dev
80
79
  $ bin/rails server -e production -p 4000
81
80
  ```
82
81
 
83
- The `-b` option binds Rails to the specified IP, by default it is 0.0.0.0. You can run a server as a daemon by passing a `-d` option.
82
+ The `-b` option binds Rails to the specified IP, by default it is localhost. You can run a server as a daemon by passing a `-d` option.
84
83
 
85
84
  ### `rails generate`
86
85
 
@@ -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.
135
- 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
132
+ Credit card controller with URLs like /credit_cards/debit.
133
+ Controller: app/controllers/credit_cards_controller.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.
@@ -349,13 +368,13 @@ Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'mak
349
368
 
350
369
  You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing `rake --tasks`. Each task has a description, and should help you find the thing you need.
351
370
 
352
- To get the full backtrace for running rake task you can pass the option
353
- ```--trace``` to command line, for example ```rake db:create --trace```.
371
+ To get the full backtrace for running rake task you can pass the option ```--trace``` to command line, for example ```rake db:create --trace```.
354
372
 
355
373
  ```bash
356
374
  $ bin/rake --tasks
357
375
  rake about # List versions of all Rails frameworks and the environment
358
- rake assets:clean # Remove compiled assets
376
+ rake assets:clean # Remove old compiled assets
377
+ rake assets:clobber # Remove compiled assets
359
378
  rake assets:precompile # Compile all the assets named in config.assets.precompile
360
379
  rake db:create # Create the database from config/database.yml for the current Rails.env
361
380
  ...
@@ -374,16 +393,11 @@ INFO: You can also use ```rake -T``` to get the list of tasks.
374
393
  ```bash
375
394
  $ bin/rake about
376
395
  About your application's environment
396
+ Rails version 4.2.0
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
381
400
  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
387
401
  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
402
  Application root /home/foobar/commandsapp
389
403
  Environment development
@@ -393,7 +407,9 @@ Database schema version 20110805173523
393
407
 
394
408
  ### `assets`
395
409
 
396
- You can precompile the assets in `app/assets` using `rake assets:precompile` and remove those compiled assets using `rake assets:clean`.
410
+ You can precompile the assets in `app/assets` using `rake assets:precompile`, and remove older compiled assets using `rake assets:clean`. The `assets:clean` task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
411
+
412
+ If you want to clear `public/assets` completely, you can use `rake assets:clobber`.
397
413
 
398
414
  ### `db`
399
415
 
@@ -411,7 +427,7 @@ The `doc:` namespace has the tools to generate documentation for your app, API d
411
427
 
412
428
  ### `notes`
413
429
 
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.
430
+ `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
431
 
416
432
  ```bash
417
433
  $ bin/rake notes
@@ -425,6 +441,12 @@ app/models/school.rb:
425
441
  * [ 17] [FIXME]
426
442
  ```
427
443
 
444
+ 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.
445
+
446
+ ```ruby
447
+ config.annotations.register_extensions("scss", "sass", "less") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
448
+ ```
449
+
428
450
  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
451
 
430
452
  ```bash
@@ -442,7 +464,7 @@ You can also use custom annotations in your code and list them using `rake notes
442
464
  ```bash
443
465
  $ bin/rake notes:custom ANNOTATION=BUG
444
466
  (in /home/foobar/commandsapp)
445
- app/models/post.rb:
467
+ app/models/article.rb:
446
468
  * [ 23] Have to fix this one before pushing!
447
469
  ```
448
470
 
@@ -472,7 +494,7 @@ Rails comes with a test suite called Minitest. Rails owes its stability to the u
472
494
 
473
495
  ### `tmp`
474
496
 
475
- The `Rails.root/tmp` directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions.
497
+ The `Rails.root/tmp` directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for sessions), process id files, and cached actions.
476
498
 
477
499
  The `tmp:` namespaced tasks will help you clear and create the `Rails.root/tmp` directory:
478
500
 
@@ -33,7 +33,7 @@ In general, the work of configuring Rails means configuring the components of Ra
33
33
  For example, the `config/application.rb` file includes this setting:
34
34
 
35
35
  ```ruby
36
- config.autoload_paths += %W(#{config.root}/extras)
36
+ config.time_zone = 'Central Time (US & Canada)'
37
37
  ```
38
38
 
39
39
  This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same `config` object in `config/application.rb`:
@@ -56,13 +56,13 @@ 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
 
63
63
  * `config.autoload_paths` accepts an array of paths from which Rails will autoload constants. Default is all directories under `app`.
64
64
 
65
- * `config.cache_classes` controls whether or not application classes and modules should be reloaded on each request. Defaults to false in development mode, and true in test and production modes. Can also be enabled with `threadsafe!`.
65
+ * `config.cache_classes` controls whether or not application classes and modules should be reloaded on each request. Defaults to false in development mode, and true in test and production modes.
66
66
 
67
67
  * `config.action_view.cache_template_loading` controls whether or not templates should be reloaded on each request. Defaults to whatever is set for `config.cache_classes`.
68
68
 
@@ -86,7 +86,7 @@ application. Accepts a valid week day symbol (e.g. `:monday`).
86
86
  end
87
87
  ```
88
88
 
89
- * `config.dependency_loading` is a flag that allows you to disable constant autoloading setting it to false. It only has effect if `config.cache_classes` is true, which it is by default in production mode. This flag is set to false by `config.threadsafe!`.
89
+ * `config.dependency_loading` is a flag that allows you to disable constant autoloading setting it to false. It only has effect if `config.cache_classes` is true, which it is by default in production mode.
90
90
 
91
91
  * `config.eager_load` when true, eager loads all registered `config.eager_load_namespaces`. This includes your application, engines, Rails frameworks and any other registered namespace.
92
92
 
@@ -108,19 +108,19 @@ numbers. New applications filter out passwords by adding the following `config.f
108
108
 
109
109
  * `config.log_formatter` defines the formatter of the Rails logger. This option defaults to an instance of `ActiveSupport::Logger::SimpleFormatter` for all modes except production, where it defaults to `Logger::Formatter`.
110
110
 
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`.
111
+ * `config.log_level` defines the verbosity of the Rails logger. This option defaults to `:debug` for all environments.
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
- * `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.
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`.
116
116
 
117
117
  * `config.middleware` allows you to configure the application's middleware. This is covered in depth in the [Configuring Middleware](#configuring-middleware) section below.
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_files` configures Rails itself to serve static files. 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,9 +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`.
141
-
142
- * `config.assets.compress` a flag that enables the compression of compiled assets. It is explicitly set to true in `config/environments/production.rb`.
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`.
143
141
 
144
142
  * `config.assets.css_compressor` defines the CSS compressor to use. It is set by default by `sass-rails`. The unique alternative value at the moment is `:yui`, which uses the `yui-compressor` gem.
145
143
 
@@ -151,7 +149,9 @@ pipeline is enabled. It is set to true by default.
151
149
 
152
150
  * `config.assets.prefix` defines the prefix where assets are served from. Defaults to `/assets`.
153
151
 
154
- * `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb`.
152
+ * `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.
153
+
154
+ * `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb` and `development.rb`.
155
155
 
156
156
  * `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`.
157
157
 
@@ -195,7 +195,7 @@ The full set of methods that can be used in this block are as follows:
195
195
  Every Rails application comes with a standard set of middleware which it uses in this order in the development environment:
196
196
 
197
197
  * `ActionDispatch::SSL` forces every request to be under HTTPS protocol. Will be available if `config.force_ssl` is set to `true`. Options passed to this can be configured by using `config.ssl_options`.
198
- * `ActionDispatch::Static` is used to serve static assets. Disabled if `config.serve_static_assets` is `false`.
198
+ * `ActionDispatch::Static` is used to serve static assets. Disabled if `config.serve_static_files` is `false`.
199
199
  * `Rack::Lock` wraps the app in mutex so it can only be called by a single thread at a time. Only enabled when `config.cache_classes` is `false`.
200
200
  * `ActiveSupport::Cache::Strategy::LocalCache` serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
201
201
  * `Rack::Runtime` sets an `X-Runtime` header, containing the time (in seconds) taken to execute the request.
@@ -212,7 +212,7 @@ Every Rails application comes with a standard set of middleware which it uses in
212
212
  * `ActionDispatch::Flash` sets up the `flash` keys. Only available if `config.action_controller.session_store` is set to a value.
213
213
  * `ActionDispatch::ParamsParser` parses out parameters from the request into `params`.
214
214
  * `Rack::MethodOverride` allows the method to be overridden if `params[:_method]` is set. This is the middleware which supports the PATCH, PUT, and DELETE HTTP method types.
215
- * `ActionDispatch::Head` converts HEAD requests to GET requests and serves them as so.
215
+ * `Rack::Head` converts HEAD requests to GET requests and serves them as so.
216
216
 
217
217
  Besides these usual middleware, you can add your own by using the `config.middleware.use` method:
218
218
 
@@ -223,13 +223,13 @@ config.middleware.use Magical::Unicorns
223
223
  This will put the `Magical::Unicorns` middleware on the end of the stack. You can use `insert_before` if you wish to add a middleware before another.
224
224
 
225
225
  ```ruby
226
- config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
226
+ config.middleware.insert_before Rack::Head, Magical::Unicorns
227
227
  ```
228
228
 
229
229
  There's also `insert_after` which will insert a middleware after another:
230
230
 
231
231
  ```ruby
232
- config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns
232
+ config.middleware.insert_after Rack::Head, Magical::Unicorns
233
233
  ```
234
234
 
235
235
  Middlewares can also be completely swapped out and replaced with others:
@@ -288,8 +288,6 @@ All these configuration options are delegated to the `I18n` library.
288
288
 
289
289
  * `config.active_record.partial_writes` is a boolean value and controls whether or not partial writes are used (i.e. whether updates only set attributes that are dirty). Note that when using partial writes, you should also use optimistic locking `config.active_record.lock_optimistically` since concurrent updates may write attributes based on a possibly stale read state. The default value is `true`.
290
290
 
291
- * `config.active_record.attribute_types_cached_by_default` sets the attribute types that `ActiveRecord::AttributeMethods` will cache by default on reads. The default is `[:datetime, :timestamp, :time, :date]`.
292
-
293
291
  * `config.active_record.maintain_test_schema` is a boolean value which controls whether Active Record should try to keep your test database schema up-to-date with `db/schema.rb` (or `db/structure.sql`) when you run your tests. The default is true.
294
292
 
295
293
  * `config.active_record.dump_schema_after_migration` is a flag which
@@ -330,6 +328,8 @@ The schema dumper adds one additional configuration option:
330
328
 
331
329
  * `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
330
 
331
+ * `config.action_controller.always_permitted_parameters` sets a list of whitelisted parameters that are permitted by default. The default values are `['controller', 'action']`.
332
+
333
333
  ### Configuring Action Dispatch
334
334
 
335
335
  * `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.
@@ -362,6 +362,30 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
362
362
  method should be performed on the parameters. See [Security Guide](security.html#unsafe-query-generation)
363
363
  for more information. It defaults to true.
364
364
 
365
+ * `config.action_dispatch.rescue_responses` configures what exceptions are assigned to an HTTP status. It accepts a hash and you can specify pairs of exception/status. By default, this is defined as:
366
+
367
+ ```ruby
368
+ config.action_dispatch.rescue_responses = {
369
+ 'ActionController::RoutingError' => :not_found,
370
+ 'AbstractController::ActionNotFound' => :not_found,
371
+ 'ActionController::MethodNotAllowed' => :method_not_allowed,
372
+ 'ActionController::UnknownHttpMethod' => :method_not_allowed,
373
+ 'ActionController::NotImplemented' => :not_implemented,
374
+ 'ActionController::UnknownFormat' => :not_acceptable,
375
+ 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
376
+ 'ActionController::InvalidCrossOriginRequest' => :unprocessable_entity,
377
+ 'ActionDispatch::ParamsParser::ParseError' => :bad_request,
378
+ 'ActionController::BadRequest' => :bad_request,
379
+ 'ActionController::ParameterMissing' => :bad_request,
380
+ 'ActiveRecord::RecordNotFound' => :not_found,
381
+ 'ActiveRecord::StaleObjectError' => :conflict,
382
+ 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
383
+ 'ActiveRecord::RecordNotSaved' => :unprocessable_entity
384
+ }
385
+ ```
386
+
387
+ Any exceptions that are not configured will be mapped to 500 Internal Server Error.
388
+
365
389
  * `ActionDispatch::Callbacks.before` takes a block of code to run before the request.
366
390
 
367
391
  * `ActionDispatch::Callbacks.to_prepare` takes a block to run after `ActionDispatch::Callbacks.before`, but before the request. Runs for every request in `development` mode, but only once for `production` or environments with `cache_classes` set to `true`.
@@ -388,13 +412,13 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
388
412
 
389
413
  * `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
414
 
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:
415
+ * `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
416
 
393
417
  ```erb
394
- <%= render @post %>
418
+ <%= render @article %>
395
419
  ```
396
420
 
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`.
421
+ 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
422
 
399
423
  * `config.action_view.raise_on_missing_translations` determines whether an error should be raised for missing translations
400
424
 
@@ -451,12 +475,26 @@ There are a number of settings available on `config.action_mailer`:
451
475
  config.action_mailer.interceptors = ["MailInterceptor"]
452
476
  ```
453
477
 
478
+ * `config.action_mailer.preview_path` specifies the location of mailer previews.
479
+
480
+ ```ruby
481
+ config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
482
+ ```
483
+
484
+ * `config.action_mailer.show_previews` enable or disable mailer previews. By default this is `true` in development.
485
+
486
+ ```ruby
487
+ config.action_mailer.show_previews = false
488
+ ```
489
+
454
490
  ### Configuring Active Support
455
491
 
456
492
  There are a few configuration options available in Active Support:
457
493
 
458
494
  * `config.active_support.bare` enables or disables the loading of `active_support/all` when booting Rails. Defaults to `nil`, which means `active_support/all` is loaded.
459
495
 
496
+ * `config.active_support.test_order` sets the order that test cases are executed. Possible values are `:sorted` and `:random`. Currently defaults to `:sorted`. In Rails 5.0, the default will be changed to `:random` instead.
497
+
460
498
  * `config.active_support.escape_html_entities_in_json` enables or disables the escaping of HTML entities in JSON serialization. Defaults to `false`.
461
499
 
462
500
  * `config.active_support.use_standard_json_time_format` enables or disables serializing dates to ISO 8601 format. Defaults to `true`.
@@ -552,7 +590,7 @@ development:
552
590
  $ echo $DATABASE_URL
553
591
  postgresql://localhost/my_database
554
592
 
555
- $ bin/rails runner 'puts ActiveRecord::Base.connections'
593
+ $ bin/rails runner 'puts ActiveRecord::Base.configurations'
556
594
  {"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database"}}
557
595
  ```
558
596
 
@@ -569,7 +607,7 @@ development:
569
607
  $ echo $DATABASE_URL
570
608
  postgresql://localhost/my_database
571
609
 
572
- $ bin/rails runner 'puts ActiveRecord::Base.connections'
610
+ $ bin/rails runner 'puts ActiveRecord::Base.configurations'
573
611
  {"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database", "pool"=>5}}
574
612
  ```
575
613
 
@@ -585,7 +623,7 @@ development:
585
623
  $ echo $DATABASE_URL
586
624
  postgresql://localhost/my_database
587
625
 
588
- $ bin/rails runner 'puts ActiveRecord::Base.connections'
626
+ $ bin/rails runner 'puts ActiveRecord::Base.configurations'
589
627
  {"development"=>{"adapter"=>"sqlite3", "database"=>"NOT_my_database"}}
590
628
  ```
591
629
 
@@ -644,11 +682,9 @@ development:
644
682
  encoding: unicode
645
683
  database: blog_development
646
684
  pool: 5
647
- username: blog
648
- password:
649
685
  ```
650
686
 
651
- Prepared Statements can be disabled thus:
687
+ Prepared Statements are enabled by default on PostgreSQL. You can be disable prepared statements by setting `prepared_statements` to `false`:
652
688
 
653
689
  ```yaml
654
690
  production:
@@ -656,6 +692,16 @@ production:
656
692
  prepared_statements: false
657
693
  ```
658
694
 
695
+ 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:
696
+
697
+ ```
698
+ production:
699
+ adapter: postgresql
700
+ statement_limit: 200
701
+ ```
702
+
703
+ 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.
704
+
659
705
  #### Configuring an SQLite3 Database for JRuby Platform
660
706
 
661
707
  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 +767,47 @@ Rails will now prepend "/app1" when generating links.
721
767
 
722
768
  #### Using Passenger
723
769
 
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).
770
+ 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
771
 
728
772
  #### Using a Reverse Proxy
729
773
 
730
- TODO
774
+ 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.
775
+
776
+ Many modern web servers can be used as a proxy server to balance third-party elements such as caching servers or application servers.
777
+
778
+ One such application server you can use is [Unicorn](http://unicorn.bogomips.org/) to run behind a reverse proxy.
779
+
780
+ 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.
781
+
782
+ 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.
783
+
784
+ 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:
785
+
786
+ ```
787
+ upstream application_server {
788
+ server 0.0.0.0:8080
789
+ }
790
+
791
+ server {
792
+ listen 80;
793
+ server_name localhost;
794
+
795
+ root /root/path/to/your_app/public;
796
+
797
+ try_files $uri/index.html $uri.html @app;
798
+
799
+ location @app {
800
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
801
+ proxy_set_header Host $http_host;
802
+ proxy_redirect off;
803
+ proxy_pass http://application_server;
804
+ }
805
+
806
+ # some other configuration
807
+ }
808
+ ```
809
+
810
+ Be sure to read the [NGINX documentation](http://nginx.org/en/docs/) for the most up-to-date information.
731
811
 
732
812
  #### Considerations when deploying to a subdirectory
733
813
 
@@ -939,4 +1019,52 @@ ActiveRecord::ConnectionTimeoutError - could not obtain a database connection wi
939
1019
  If you get the above error, you might want to increase the size of connection
940
1020
  pool by incrementing the `pool` option in `database.yml`
941
1021
 
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.
1022
+ 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.
1023
+
1024
+
1025
+ Custom configuration
1026
+ --------------------
1027
+
1028
+ You can configure your own code through the Rails configuration object with custom configuration under the `config.x` property. It works like this:
1029
+
1030
+ ```ruby
1031
+ config.x.payment_processing.schedule = :daily
1032
+ config.x.payment_processing.retries = 3
1033
+ config.x.super_debugger = true
1034
+ ```
1035
+
1036
+ These configuration points are then available through the configuration object:
1037
+
1038
+ ```ruby
1039
+ Rails.configuration.x.payment_processing.schedule # => :daily
1040
+ Rails.configuration.x.payment_processing.retries # => 3
1041
+ Rails.configuration.x.super_debugger # => true
1042
+ Rails.configuration.x.super_debugger.not_set # => nil
1043
+ ```
1044
+
1045
+ You can also use Rails::Application.config_for to load whole configuration files:
1046
+
1047
+ ```ruby
1048
+ # config/payment.yml:
1049
+ production:
1050
+ environment: production
1051
+ merchant_id: production_merchant_id
1052
+ public_key: production_public_key
1053
+ private_key: production_private_key
1054
+ development:
1055
+ environment: sandbox
1056
+ merchant_id: development_merchant_id
1057
+ public_key: development_public_key
1058
+ private_key: development_private_key
1059
+
1060
+ # config/application.rb
1061
+ module MyApp
1062
+ class Application < Rails::Application
1063
+ config.x.payment = config_for(:payment)
1064
+ end
1065
+ end
1066
+ ```
1067
+
1068
+ ```ruby
1069
+ Rails.configuration.x.payment['merchant_id'] # => production_merchant_id or development_merchant_id
1070
+ ```