rails 4.1.4 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -10
- data/guides/CHANGELOG.md +15 -25
- data/guides/Rakefile +5 -3
- data/guides/assets/javascripts/guides.js +6 -0
- data/guides/assets/stylesheets/main.css +4 -1
- data/guides/bug_report_templates/action_controller_gem.rb +2 -2
- data/guides/bug_report_templates/action_controller_master.rb +3 -2
- data/guides/rails_guides/helpers.rb +1 -1
- data/guides/rails_guides/levenshtein.rb +29 -21
- data/guides/rails_guides/markdown/renderer.rb +1 -1
- data/guides/rails_guides/markdown.rb +11 -7
- data/guides/rails_guides.rb +2 -2
- data/guides/source/2_2_release_notes.md +1 -1
- data/guides/source/2_3_release_notes.md +4 -4
- data/guides/source/3_0_release_notes.md +8 -8
- data/guides/source/3_1_release_notes.md +5 -2
- data/guides/source/3_2_release_notes.md +6 -3
- data/guides/source/4_0_release_notes.md +6 -3
- data/guides/source/4_1_release_notes.md +10 -11
- data/guides/source/4_2_release_notes.md +850 -0
- data/guides/source/_license.html.erb +1 -1
- data/guides/source/_welcome.html.erb +2 -8
- data/guides/source/action_controller_overview.md +84 -10
- data/guides/source/action_mailer_basics.md +91 -28
- data/guides/source/action_view_overview.md +140 -130
- data/guides/source/active_job_basics.md +318 -0
- data/guides/source/active_model_basics.md +371 -17
- data/guides/source/active_record_basics.md +19 -18
- data/guides/source/active_record_callbacks.md +12 -9
- data/guides/source/{migrations.md → active_record_migrations.md} +135 -226
- data/guides/source/active_record_postgresql.md +433 -0
- data/guides/source/active_record_querying.md +269 -259
- data/guides/source/active_record_validations.md +21 -12
- data/guides/source/active_support_core_extensions.md +113 -73
- data/guides/source/active_support_instrumentation.md +10 -7
- data/guides/source/api_documentation_guidelines.md +62 -16
- data/guides/source/asset_pipeline.md +264 -67
- data/guides/source/association_basics.md +81 -74
- data/guides/source/caching_with_rails.md +32 -7
- data/guides/source/command_line.md +52 -30
- data/guides/source/configuring.md +132 -29
- data/guides/source/constant_autoloading_and_reloading.md +1297 -0
- data/guides/source/contributing_to_ruby_on_rails.md +192 -112
- data/guides/source/credits.html.erb +2 -2
- data/guides/source/debugging_rails_applications.md +448 -294
- data/guides/source/development_dependencies_install.md +47 -36
- data/guides/source/documents.yaml +19 -7
- data/guides/source/engines.md +210 -189
- data/guides/source/form_helpers.md +79 -56
- data/guides/source/generators.md +24 -11
- data/guides/source/getting_started.md +339 -201
- data/guides/source/i18n.md +111 -68
- data/guides/source/index.html.erb +1 -0
- data/guides/source/initialization.md +109 -62
- data/guides/source/layout.html.erb +1 -4
- data/guides/source/layouts_and_rendering.md +18 -17
- data/guides/source/maintenance_policy.md +26 -4
- data/guides/source/nested_model_forms.md +7 -4
- data/guides/source/plugins.md +27 -27
- data/guides/source/rails_application_templates.md +21 -3
- data/guides/source/rails_on_rack.md +12 -9
- data/guides/source/routing.md +100 -74
- data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
- data/guides/source/security.md +40 -34
- data/guides/source/testing.md +188 -117
- data/guides/source/upgrading_ruby_on_rails.md +284 -29
- data/guides/source/working_with_javascript_in_rails.md +18 -16
- data/guides/w3c_validator.rb +2 -0
- metadata +40 -94
- data/guides/code/getting_started/Gemfile +0 -40
- data/guides/code/getting_started/Gemfile.lock +0 -125
- data/guides/code/getting_started/README.rdoc +0 -28
- data/guides/code/getting_started/Rakefile +0 -6
- data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
- data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
- data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
- data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
- data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
- data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
- data/guides/code/getting_started/app/models/comment.rb +0 -3
- data/guides/code/getting_started/app/models/post.rb +0 -7
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
- data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
- data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
- data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
- data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
- data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
- data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
- data/guides/code/getting_started/bin/bundle +0 -4
- data/guides/code/getting_started/bin/rails +0 -4
- data/guides/code/getting_started/bin/rake +0 -4
- data/guides/code/getting_started/config/application.rb +0 -18
- data/guides/code/getting_started/config/boot.rb +0 -4
- data/guides/code/getting_started/config/database.yml +0 -25
- data/guides/code/getting_started/config/environment.rb +0 -5
- data/guides/code/getting_started/config/environments/development.rb +0 -30
- data/guides/code/getting_started/config/environments/production.rb +0 -80
- data/guides/code/getting_started/config/environments/test.rb +0 -36
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
- data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
- data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
- data/guides/code/getting_started/config/initializers/locale.rb +0 -9
- data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
- data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
- data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
- data/guides/code/getting_started/config/locales/en.yml +0 -23
- data/guides/code/getting_started/config/routes.rb +0 -7
- data/guides/code/getting_started/config.ru +0 -4
- data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
- data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
- data/guides/code/getting_started/db/schema.rb +0 -33
- data/guides/code/getting_started/db/seeds.rb +0 -7
- data/guides/code/getting_started/public/404.html +0 -60
- data/guides/code/getting_started/public/422.html +0 -60
- data/guides/code/getting_started/public/500.html +0 -59
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +0 -5
- data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
- data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
- data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
- data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
- data/guides/code/getting_started/test/models/comment_test.rb +0 -7
- data/guides/code/getting_started/test/models/post_test.rb +0 -7
- data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -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.
|
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
|
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
|
130
|
+
`rails generate controller CreditCards open debit credit close`
|
133
131
|
|
134
|
-
Credit card controller with URLs like /
|
135
|
-
Controller: app/controllers/
|
136
|
-
Test: test/controllers/
|
137
|
-
Views: app/views/
|
138
|
-
Helper: app/helpers/
|
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
|
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.
|
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.1
|
381
400
|
JavaScript Runtime Node.js (V8)
|
382
|
-
Active Record version 4.1.1
|
383
|
-
Action Pack version 4.1.1
|
384
|
-
Action View version 4.1.1
|
385
|
-
Action Mailer version 4.1.1
|
386
|
-
Active Support version 4.1.1
|
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
|
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`, `.
|
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/
|
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
|
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
|
|
@@ -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
|
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.
|
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.
|
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
|
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
|
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
|
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
|
-
* `
|
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.
|
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,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
|
-
|
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,7 +151,9 @@ 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.
|
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
|
+
|
156
|
+
* `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb` and `development.rb`.
|
155
157
|
|
156
158
|
* `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`.
|
157
159
|
|
@@ -212,7 +214,7 @@ Every Rails application comes with a standard set of middleware which it uses in
|
|
212
214
|
* `ActionDispatch::Flash` sets up the `flash` keys. Only available if `config.action_controller.session_store` is set to a value.
|
213
215
|
* `ActionDispatch::ParamsParser` parses out parameters from the request into `params`.
|
214
216
|
* `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
|
-
* `
|
217
|
+
* `Rack::Head` converts HEAD requests to GET requests and serves them as so.
|
216
218
|
|
217
219
|
Besides these usual middleware, you can add your own by using the `config.middleware.use` method:
|
218
220
|
|
@@ -223,13 +225,13 @@ config.middleware.use Magical::Unicorns
|
|
223
225
|
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
226
|
|
225
227
|
```ruby
|
226
|
-
config.middleware.insert_before
|
228
|
+
config.middleware.insert_before Rack::Head, Magical::Unicorns
|
227
229
|
```
|
228
230
|
|
229
231
|
There's also `insert_after` which will insert a middleware after another:
|
230
232
|
|
231
233
|
```ruby
|
232
|
-
config.middleware.insert_after
|
234
|
+
config.middleware.insert_after Rack::Head, Magical::Unicorns
|
233
235
|
```
|
234
236
|
|
235
237
|
Middlewares can also be completely swapped out and replaced with others:
|
@@ -288,8 +290,6 @@ All these configuration options are delegated to the `I18n` library.
|
|
288
290
|
|
289
291
|
* `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
292
|
|
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
293
|
* `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
294
|
|
295
295
|
* `config.active_record.dump_schema_after_migration` is a flag which
|
@@ -330,6 +330,8 @@ The schema dumper adds one additional configuration option:
|
|
330
330
|
|
331
331
|
* `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
332
|
|
333
|
+
* `config.action_controller.always_permitted_parameters` sets a list of whitelisted parameters that are permitted by default. The default values are `['controller', 'action']`.
|
334
|
+
|
333
335
|
### Configuring Action Dispatch
|
334
336
|
|
335
337
|
* `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 +364,30 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
|
|
362
364
|
method should be performed on the parameters. See [Security Guide](security.html#unsafe-query-generation)
|
363
365
|
for more information. It defaults to true.
|
364
366
|
|
367
|
+
* `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:
|
368
|
+
|
369
|
+
```ruby
|
370
|
+
config.action_dispatch.rescue_responses = {
|
371
|
+
'ActionController::RoutingError' => :not_found,
|
372
|
+
'AbstractController::ActionNotFound' => :not_found,
|
373
|
+
'ActionController::MethodNotAllowed' => :method_not_allowed,
|
374
|
+
'ActionController::UnknownHttpMethod' => :method_not_allowed,
|
375
|
+
'ActionController::NotImplemented' => :not_implemented,
|
376
|
+
'ActionController::UnknownFormat' => :not_acceptable,
|
377
|
+
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
|
378
|
+
'ActionController::InvalidCrossOriginRequest' => :unprocessable_entity,
|
379
|
+
'ActionDispatch::ParamsParser::ParseError' => :bad_request,
|
380
|
+
'ActionController::BadRequest' => :bad_request,
|
381
|
+
'ActionController::ParameterMissing' => :bad_request,
|
382
|
+
'ActiveRecord::RecordNotFound' => :not_found,
|
383
|
+
'ActiveRecord::StaleObjectError' => :conflict,
|
384
|
+
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
|
385
|
+
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
|
386
|
+
}
|
387
|
+
```
|
388
|
+
|
389
|
+
Any exceptions that are not configured will be mapped to 500 Internal Server Error.
|
390
|
+
|
365
391
|
* `ActionDispatch::Callbacks.before` takes a block of code to run before the request.
|
366
392
|
|
367
393
|
* `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 +414,13 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
|
|
388
414
|
|
389
415
|
* `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
416
|
|
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::
|
417
|
+
* `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
418
|
|
393
419
|
```erb
|
394
|
-
<%= render @
|
420
|
+
<%= render @article %>
|
395
421
|
```
|
396
422
|
|
397
|
-
The default setting is `true`, which uses the partial at `/admin/
|
423
|
+
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
424
|
|
399
425
|
* `config.action_view.raise_on_missing_translations` determines whether an error should be raised for missing translations
|
400
426
|
|
@@ -451,12 +477,26 @@ There are a number of settings available on `config.action_mailer`:
|
|
451
477
|
config.action_mailer.interceptors = ["MailInterceptor"]
|
452
478
|
```
|
453
479
|
|
480
|
+
* `config.action_mailer.preview_path` specifies the location of mailer previews.
|
481
|
+
|
482
|
+
```ruby
|
483
|
+
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
|
484
|
+
```
|
485
|
+
|
486
|
+
* `config.action_mailer.show_previews` enable or disable mailer previews. By default this is `true` in development.
|
487
|
+
|
488
|
+
```ruby
|
489
|
+
config.action_mailer.show_previews = false
|
490
|
+
```
|
491
|
+
|
454
492
|
### Configuring Active Support
|
455
493
|
|
456
494
|
There are a few configuration options available in Active Support:
|
457
495
|
|
458
496
|
* `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
497
|
|
498
|
+
* `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.
|
499
|
+
|
460
500
|
* `config.active_support.escape_html_entities_in_json` enables or disables the escaping of HTML entities in JSON serialization. Defaults to `false`.
|
461
501
|
|
462
502
|
* `config.active_support.use_standard_json_time_format` enables or disables serializing dates to ISO 8601 format. Defaults to `true`.
|
@@ -552,7 +592,7 @@ development:
|
|
552
592
|
$ echo $DATABASE_URL
|
553
593
|
postgresql://localhost/my_database
|
554
594
|
|
555
|
-
$ bin/rails runner 'puts ActiveRecord::Base.
|
595
|
+
$ bin/rails runner 'puts ActiveRecord::Base.configurations'
|
556
596
|
{"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database"}}
|
557
597
|
```
|
558
598
|
|
@@ -569,7 +609,7 @@ development:
|
|
569
609
|
$ echo $DATABASE_URL
|
570
610
|
postgresql://localhost/my_database
|
571
611
|
|
572
|
-
$ bin/rails runner 'puts ActiveRecord::Base.
|
612
|
+
$ bin/rails runner 'puts ActiveRecord::Base.configurations'
|
573
613
|
{"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database", "pool"=>5}}
|
574
614
|
```
|
575
615
|
|
@@ -585,7 +625,7 @@ development:
|
|
585
625
|
$ echo $DATABASE_URL
|
586
626
|
postgresql://localhost/my_database
|
587
627
|
|
588
|
-
$ bin/rails runner 'puts ActiveRecord::Base.
|
628
|
+
$ bin/rails runner 'puts ActiveRecord::Base.configurations'
|
589
629
|
{"development"=>{"adapter"=>"sqlite3", "database"=>"NOT_my_database"}}
|
590
630
|
```
|
591
631
|
|
@@ -644,11 +684,9 @@ development:
|
|
644
684
|
encoding: unicode
|
645
685
|
database: blog_development
|
646
686
|
pool: 5
|
647
|
-
username: blog
|
648
|
-
password:
|
649
687
|
```
|
650
688
|
|
651
|
-
Prepared Statements can be
|
689
|
+
Prepared Statements are enabled by default on PostgreSQL. You can be disable prepared statements by setting `prepared_statements` to `false`:
|
652
690
|
|
653
691
|
```yaml
|
654
692
|
production:
|
@@ -656,6 +694,16 @@ production:
|
|
656
694
|
prepared_statements: false
|
657
695
|
```
|
658
696
|
|
697
|
+
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:
|
698
|
+
|
699
|
+
```
|
700
|
+
production:
|
701
|
+
adapter: postgresql
|
702
|
+
statement_limit: 200
|
703
|
+
```
|
704
|
+
|
705
|
+
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.
|
706
|
+
|
659
707
|
#### Configuring an SQLite3 Database for JRuby Platform
|
660
708
|
|
661
709
|
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 +769,47 @@ Rails will now prepend "/app1" when generating links.
|
|
721
769
|
|
722
770
|
#### Using Passenger
|
723
771
|
|
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).
|
772
|
+
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
773
|
|
728
774
|
#### Using a Reverse Proxy
|
729
775
|
|
730
|
-
|
776
|
+
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.
|
777
|
+
|
778
|
+
Many modern web servers can be used as a proxy server to balance third-party elements such as caching servers or application servers.
|
779
|
+
|
780
|
+
One such application server you can use is [Unicorn](http://unicorn.bogomips.org/) to run behind a reverse proxy.
|
781
|
+
|
782
|
+
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.
|
783
|
+
|
784
|
+
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.
|
785
|
+
|
786
|
+
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:
|
787
|
+
|
788
|
+
```
|
789
|
+
upstream application_server {
|
790
|
+
server 0.0.0.0:8080
|
791
|
+
}
|
792
|
+
|
793
|
+
server {
|
794
|
+
listen 80;
|
795
|
+
server_name localhost;
|
796
|
+
|
797
|
+
root /root/path/to/your_app/public;
|
798
|
+
|
799
|
+
try_files $uri/index.html $uri.html @app;
|
800
|
+
|
801
|
+
location @app {
|
802
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
803
|
+
proxy_set_header Host $http_host;
|
804
|
+
proxy_redirect off;
|
805
|
+
proxy_pass http://application_server;
|
806
|
+
}
|
807
|
+
|
808
|
+
# some other configuration
|
809
|
+
}
|
810
|
+
```
|
811
|
+
|
812
|
+
Be sure to read the [NGINX documentation](http://nginx.org/en/docs/) for the most up-to-date information.
|
731
813
|
|
732
814
|
#### Considerations when deploying to a subdirectory
|
733
815
|
|
@@ -939,4 +1021,25 @@ ActiveRecord::ConnectionTimeoutError - could not obtain a database connection wi
|
|
939
1021
|
If you get the above error, you might want to increase the size of connection
|
940
1022
|
pool by incrementing the `pool` option in `database.yml`
|
941
1023
|
|
942
|
-
NOTE.
|
1024
|
+
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.
|
1025
|
+
|
1026
|
+
|
1027
|
+
Custom configuration
|
1028
|
+
--------------------
|
1029
|
+
|
1030
|
+
You can configure your own code through the Rails configuration object with custom configuration. It works like this:
|
1031
|
+
|
1032
|
+
```ruby
|
1033
|
+
config.x.payment_processing.schedule = :daily
|
1034
|
+
config.x.payment_processing.retries = 3
|
1035
|
+
config.x.super_debugger = true
|
1036
|
+
```
|
1037
|
+
|
1038
|
+
These configuration points are then available through the configuration object:
|
1039
|
+
|
1040
|
+
```ruby
|
1041
|
+
Rails.configuration.x.payment_processing.schedule # => :daily
|
1042
|
+
Rails.configuration.x.payment_processing.retries # => 3
|
1043
|
+
Rails.configuration.x.super_debugger # => true
|
1044
|
+
Rails.configuration.x.super_debugger.not_set # => nil
|
1045
|
+
```
|