railties 3.1.12 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2292 -41
- data/README.rdoc +14 -5
- data/bin/rails +7 -0
- data/guides/code/getting_started/Gemfile +27 -0
- data/guides/code/getting_started/README.rdoc +261 -0
- data/guides/code/getting_started/Rakefile +7 -0
- data/guides/code/getting_started/app/assets/images/rails.png +0 -0
- data/guides/code/getting_started/app/assets/javascripts/application.js +9 -0
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/application.css +7 -0
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
- data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
- data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
- data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
- data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
- data/guides/code/getting_started/app/models/comment.rb +3 -0
- data/guides/code/getting_started/app/models/post.rb +11 -0
- data/guides/code/getting_started/app/models/tag.rb +3 -0
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
- data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
- data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
- data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
- data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
- data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
- data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
- data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
- data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
- data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
- data/guides/code/getting_started/config.ru +4 -0
- data/guides/code/getting_started/config/application.rb +53 -0
- data/guides/code/getting_started/config/boot.rb +6 -0
- data/guides/code/getting_started/config/database.yml +25 -0
- data/guides/code/getting_started/config/environment.rb +5 -0
- data/guides/code/getting_started/config/environments/development.rb +37 -0
- data/guides/code/getting_started/config/environments/production.rb +67 -0
- data/guides/code/getting_started/config/environments/test.rb +37 -0
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
- data/guides/code/getting_started/config/initializers/inflections.rb +10 -0
- data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
- data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
- data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
- data/guides/code/getting_started/config/locales/en.yml +5 -0
- data/guides/code/getting_started/config/routes.rb +64 -0
- data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
- data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
- data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
- data/guides/code/getting_started/db/schema.rb +43 -0
- data/guides/code/getting_started/db/seeds.rb +7 -0
- data/guides/code/getting_started/doc/README_FOR_APP +2 -0
- data/guides/code/getting_started/public/404.html +26 -0
- data/guides/code/getting_started/public/422.html +26 -0
- data/guides/code/getting_started/public/500.html +26 -0
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +5 -0
- data/guides/code/getting_started/script/rails +6 -0
- data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
- data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
- data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
- data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
- data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
- data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
- data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
- data/guides/code/getting_started/test/test_helper.rb +13 -0
- data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
- data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/post_test.rb +7 -0
- data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
- data/guides/rails_guides/generator.rb +2 -1
- data/guides/source/3_0_release_notes.textile +2 -2
- data/guides/source/3_1_release_notes.textile +3 -110
- data/guides/source/action_controller_overview.textile +11 -13
- data/guides/source/action_mailer_basics.textile +7 -18
- data/guides/source/action_view_overview.textile +78 -9
- data/guides/source/active_model_basics.textile +205 -0
- data/guides/source/active_record_basics.textile +31 -31
- data/guides/source/active_record_querying.textile +288 -67
- data/guides/source/active_record_validations_callbacks.textile +69 -75
- data/guides/source/active_resource_basics.textile +48 -2
- data/guides/source/active_support_core_extensions.textile +145 -24
- data/guides/source/ajax_on_rails.textile +65 -7
- data/guides/source/api_documentation_guidelines.textile +0 -6
- data/guides/source/asset_pipeline.textile +2 -2
- data/guides/source/association_basics.textile +25 -34
- data/guides/source/caching_with_rails.textile +12 -17
- data/guides/source/command_line.textile +29 -19
- data/guides/source/configuring.textile +40 -18
- data/guides/source/contributing_to_ruby_on_rails.textile +11 -18
- data/guides/source/debugging_rails_applications.textile +10 -21
- data/guides/source/engines.textile +618 -0
- data/guides/source/form_helpers.textile +1 -12
- data/guides/source/generators.textile +9 -11
- data/guides/source/getting_started.textile +152 -152
- data/guides/source/i18n.textile +4 -5
- data/guides/source/index.html.erb +0 -1
- data/guides/source/initialization.textile +26 -26
- data/guides/source/layouts_and_rendering.textile +97 -61
- data/guides/source/migrations.textile +380 -161
- data/guides/source/performance_testing.textile +4 -10
- data/guides/source/plugins.textile +11 -19
- data/guides/source/rails_application_templates.textile +12 -4
- data/guides/source/rails_on_rack.textile +25 -19
- data/guides/source/routing.textile +6 -13
- data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -5
- data/guides/source/security.textile +11 -15
- data/guides/source/testing.textile +1 -9
- data/lib/rails/application.rb +107 -42
- data/lib/rails/application/bootstrap.rb +12 -11
- data/lib/rails/application/configuration.rb +27 -21
- data/lib/rails/application/finisher.rb +40 -17
- data/lib/rails/application/route_inspector.rb +75 -0
- data/lib/rails/application/routes_reloader.rb +15 -4
- data/lib/rails/code_statistics.rb +16 -5
- data/lib/rails/commands.rb +6 -5
- data/lib/rails/commands/application.rb +8 -1
- data/lib/rails/commands/console.rb +2 -0
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +0 -2
- data/lib/rails/commands/generate.rb +3 -3
- data/lib/rails/commands/plugin.rb +161 -159
- data/lib/rails/commands/plugin_new.rb +3 -2
- data/lib/rails/commands/runner.rb +4 -0
- data/lib/rails/console/app.rb +26 -22
- data/lib/rails/console/helpers.rb +9 -5
- data/lib/rails/engine.rb +70 -34
- data/lib/rails/engine/commands.rb +39 -0
- data/lib/rails/engine/configuration.rb +1 -1
- data/lib/rails/generators.rb +3 -14
- data/lib/rails/generators/actions.rb +36 -9
- data/lib/rails/generators/app_base.rb +34 -38
- data/lib/rails/generators/base.rb +4 -4
- data/lib/rails/generators/generated_attribute.rb +1 -1
- data/lib/rails/generators/named_base.rb +1 -3
- data/lib/rails/generators/rails/app/USAGE +6 -0
- data/lib/rails/generators/rails/app/app_generator.rb +6 -2
- data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +9 -3
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +11 -5
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +11 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/public/500.html +0 -1
- data/lib/rails/generators/rails/app/templates/public/index.html +1 -1
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +17 -5
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +1 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +4 -3
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -3
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/rails/task/USAGE +9 -0
- data/lib/rails/generators/rails/task/task_generator.rb +12 -0
- data/lib/rails/generators/rails/task/templates/task.rb +8 -0
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -2
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -4
- data/lib/rails/paths.rb +11 -38
- data/lib/rails/rack/debugger.rb +3 -4
- data/lib/rails/rack/logger.rb +26 -12
- data/lib/rails/railtie.rb +6 -1
- data/lib/rails/railtie/configuration.rb +12 -5
- data/lib/rails/source_annotation_extractor.rb +12 -10
- data/lib/rails/tasks/documentation.rake +3 -1
- data/lib/rails/tasks/engine.rake +1 -0
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +3 -23
- data/lib/rails/test_help.rb +1 -2
- data/lib/rails/test_unit/testing.rake +8 -4
- data/lib/rails/version.rb +3 -3
- metadata +131 -61
- checksums.yaml +0 -7
- data/lib/rails/generators/rails/plugin/USAGE +0 -13
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -54
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +0 -20
- data/lib/rails/generators/rails/plugin/templates/README.tt +0 -13
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +0 -23
- data/lib/rails/generators/rails/plugin/templates/init.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/install.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -4
- data/lib/rails/generators/rails/plugin/templates/uninstall.rb +0 -1
@@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case.
|
|
207
207
|
|
208
208
|
h5. Metric Availability
|
209
209
|
|
210
|
-
h6. Benchmarking
|
210
|
+
h6(#benchmarking_1). Benchmarking
|
211
211
|
|
212
212
|
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|
213
213
|
|_.MRI | yes | yes | yes | no | yes | yes | yes | yes |
|
@@ -215,7 +215,7 @@ h6. Benchmarking
|
|
215
215
|
|_.Rubinius | yes | no | no | no | yes | yes | yes | yes |
|
216
216
|
|_.JRuby | yes | no | no | yes | yes | yes | yes | yes |
|
217
217
|
|
218
|
-
h6. Profiling
|
218
|
+
h6(#profiling_1). Profiling
|
219
219
|
|
220
220
|
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|
221
221
|
|_.MRI | yes | yes | no | no | yes | yes | yes | yes |
|
@@ -438,9 +438,9 @@ alias gcrails='~/rubygc/bin/rails'
|
|
438
438
|
|
439
439
|
Don't forget to use your aliases from now on.
|
440
440
|
|
441
|
-
h6. Install
|
441
|
+
h6. Install RubyGems (1.8 only!)
|
442
442
|
|
443
|
-
Download "
|
443
|
+
Download "RubyGems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above.
|
444
444
|
|
445
445
|
h4. Using Ruby-Prof on MRI and REE
|
446
446
|
|
@@ -595,9 +595,3 @@ Rails has been lucky to have a few companies dedicated to Rails-specific perform
|
|
595
595
|
|
596
596
|
* "New Relic":http://www.newrelic.com
|
597
597
|
* "Scout":http://scoutapp.com
|
598
|
-
|
599
|
-
h3. Changelog
|
600
|
-
|
601
|
-
* March 30, 2011: Documented the recent improvements (multiple interpreters, options, etc) and necessary adjustments. Other minor improvements. "Gonçalo Silva":http://goncalossilva.com.
|
602
|
-
* January 9, 2009: Complete rewrite by "Pratik":credits.html#lifo
|
603
|
-
* September 6, 2008: Initial version by Matthew Bergman
|
@@ -290,7 +290,7 @@ You can then return to the root directory (+cd ../..+) of your plugin and rerun
|
|
290
290
|
|
291
291
|
</shell>
|
292
292
|
|
293
|
-
Getting closer...
|
293
|
+
Getting closer... Now we will implement the code of the acts_as_yaffle method to make the tests pass.
|
294
294
|
|
295
295
|
<ruby>
|
296
296
|
# yaffle/lib/yaffle/acts_as_yaffle.rb
|
@@ -322,7 +322,7 @@ When you run +rake+ you should see the tests all pass:
|
|
322
322
|
|
323
323
|
h4. Add an Instance Method
|
324
324
|
|
325
|
-
This plugin will add a method named 'squawk' to any Active Record
|
325
|
+
This plugin will add a method named 'squawk' to any Active Record object that calls 'acts_as_yaffle'. The 'squawk'
|
326
326
|
method will simply set the value of one of the fields in the database.
|
327
327
|
|
328
328
|
To start out, write a failing test that shows the behavior you'd like:
|
@@ -347,7 +347,7 @@ class ActsAsYaffleTest < Test::Unit::TestCase
|
|
347
347
|
assert_equal "squawk! Hello World", hickwall.last_squawk
|
348
348
|
end
|
349
349
|
|
350
|
-
def
|
350
|
+
def test_wickwalls_squawk_should_populate_last_tweet
|
351
351
|
wickwall = Wickwall.new
|
352
352
|
wickwall.squawk("Hello World")
|
353
353
|
assert_equal "squawk! Hello World", wickwall.last_tweet
|
@@ -355,7 +355,7 @@ class ActsAsYaffleTest < Test::Unit::TestCase
|
|
355
355
|
end
|
356
356
|
</ruby>
|
357
357
|
|
358
|
-
Run the test to make sure the last two tests fail
|
358
|
+
Run the test to make sure the last two tests fail with an error that contains "NoMethodError: undefined method `squawk'",
|
359
359
|
then update 'acts_as_yaffle.rb' to look like this:
|
360
360
|
|
361
361
|
<ruby>
|
@@ -400,11 +400,11 @@ the creation of generators can be found in the "Generators Guide":generators.htm
|
|
400
400
|
|
401
401
|
h3. Publishing your Gem
|
402
402
|
|
403
|
-
Gem plugins in
|
404
|
-
commit the code to a Git repository (like Github) and add a line to the Gemfile of the
|
403
|
+
Gem plugins currently in development can easily be shared from any Git repository. To share the Yaffle gem with others, simply
|
404
|
+
commit the code to a Git repository (like Github) and add a line to the Gemfile of the application in question:
|
405
405
|
|
406
406
|
<ruby>
|
407
|
-
gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git'
|
407
|
+
gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git'
|
408
408
|
</ruby>
|
409
409
|
|
410
410
|
After running +bundle install+, your gem functionality will be available to the application.
|
@@ -426,12 +426,12 @@ require 'yaffle'
|
|
426
426
|
</ruby>
|
427
427
|
|
428
428
|
You can test this by changing to the Rails application that you added the plugin to and starting a rails console. Once in the
|
429
|
-
console we can check to see if the String has an instance method
|
429
|
+
console we can check to see if the String has an instance method to_squawk:
|
430
430
|
|
431
431
|
<shell>
|
432
432
|
$ cd my_app
|
433
433
|
$ rails console
|
434
|
-
$
|
434
|
+
$ "Rails plugins are easy!".to_squawk
|
435
435
|
</shell>
|
436
436
|
|
437
437
|
You can also remove the .gemspec, Gemfile and Gemfile.lock files as they will no longer be needed.
|
@@ -445,9 +445,9 @@ The first step is to update the README file with detailed information about how
|
|
445
445
|
* Your name
|
446
446
|
* How to install
|
447
447
|
* How to add the functionality to the app (several examples of common use cases)
|
448
|
-
*
|
448
|
+
* Warnings, gotchas or tips that might help users and save them time
|
449
449
|
|
450
|
-
Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not
|
450
|
+
Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not included in the public api.
|
451
451
|
|
452
452
|
Once your comments are good to go, navigate to your plugin directory and run:
|
453
453
|
|
@@ -462,11 +462,3 @@ h4. References
|
|
462
462
|
* "Gemspec Reference":http://docs.rubygems.org/read/chapter/20
|
463
463
|
* "GemPlugins":http://www.mbleigh.com/2008/06/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins
|
464
464
|
* "Keeping init.rb thin":http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html
|
465
|
-
|
466
|
-
h3. Changelog
|
467
|
-
|
468
|
-
* March 10, 2011: Minor formatting tweaks.
|
469
|
-
* February 13, 2011: Get guide in synch with Rails 3.0.3. Remove information not compatible with Rails 3. Send reader elsewhere
|
470
|
-
for information that is covered elsewhere.
|
471
|
-
* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
|
472
|
-
* November 17, 2008: Major revision by Jeff Dean
|
@@ -60,6 +60,18 @@ Please note that this will NOT install the gems for you and you will have to run
|
|
60
60
|
bundle install
|
61
61
|
</ruby>
|
62
62
|
|
63
|
+
h4. gem_group(*names, &block)
|
64
|
+
|
65
|
+
Wraps gem entries inside a group.
|
66
|
+
|
67
|
+
For example, if you want to load +rspec-rails+ only in +development+ and +test+ group:
|
68
|
+
|
69
|
+
<ruby>
|
70
|
+
gem_group :development, :test do
|
71
|
+
gem "rspec-rails"
|
72
|
+
end
|
73
|
+
</ruby>
|
74
|
+
|
63
75
|
h4. add_source(source, options = {})
|
64
76
|
|
65
77
|
Adds the given source to the generated application's +Gemfile+.
|
@@ -226,7 +238,3 @@ git :init
|
|
226
238
|
git :add => "."
|
227
239
|
git :commit => "-a -m 'Initial commit'"
|
228
240
|
</ruby>
|
229
|
-
|
230
|
-
h3. Changelog
|
231
|
-
|
232
|
-
* April 29, 2009: Initial version by "Pratik":credits.html#lifo
|
@@ -89,23 +89,33 @@ $ rake middleware
|
|
89
89
|
For a freshly generated Rails application, this might produce something like:
|
90
90
|
|
91
91
|
<ruby>
|
92
|
+
use ActionDispatch::Static
|
92
93
|
use Rack::Lock
|
93
|
-
use
|
94
|
-
use
|
95
|
-
use Rails::Rack::
|
96
|
-
use ActionDispatch::
|
97
|
-
use
|
98
|
-
use
|
99
|
-
use Rack::
|
94
|
+
use ActiveSupport::Cache::Strategy::LocalCache
|
95
|
+
use Rack::Runtime
|
96
|
+
use Rails::Rack::Logger
|
97
|
+
use ActionDispatch::ShowExceptions
|
98
|
+
use ActionDispatch::DebugExceptions
|
99
|
+
use ActionDispatch::RemoteIp
|
100
|
+
use Rack::Sendfile
|
101
|
+
use ActionDispatch::Callbacks
|
102
|
+
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
100
103
|
use ActiveRecord::QueryCache
|
101
|
-
|
104
|
+
use ActionDispatch::Cookies
|
105
|
+
use ActionDispatch::Session::CookieStore
|
106
|
+
use ActionDispatch::Flash
|
107
|
+
use ActionDispatch::ParamsParser
|
108
|
+
use Rack::MethodOverride
|
109
|
+
use ActionDispatch::Head
|
110
|
+
use ActionDispatch::BestStandardsSupport
|
111
|
+
run Blog::Application.routes
|
102
112
|
</ruby>
|
103
113
|
|
104
114
|
Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section.
|
105
115
|
|
106
116
|
h4. Configuring Middleware Stack
|
107
117
|
|
108
|
-
Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +
|
118
|
+
Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file <tt>environments/<environment>.rb</tt>.
|
109
119
|
|
110
120
|
h5. Adding a Middleware
|
111
121
|
|
@@ -118,7 +128,7 @@ You can add a new middleware to the middleware stack using any of the following
|
|
118
128
|
* <tt>config.middleware.insert_after(existing_middleware, new_middleware, args)</tt> - Adds the new middleware after the specified existing middleware in the middleware stack.
|
119
129
|
|
120
130
|
<ruby>
|
121
|
-
# config/
|
131
|
+
# config/application.rb
|
122
132
|
|
123
133
|
# Push Rack::BounceFavicon at the bottom
|
124
134
|
config.middleware.use Rack::BounceFavicon
|
@@ -133,7 +143,7 @@ h5. Swapping a Middleware
|
|
133
143
|
You can swap an existing middleware in the middleware stack using +config.middleware.swap+.
|
134
144
|
|
135
145
|
<ruby>
|
136
|
-
# config/
|
146
|
+
# config/application.rb
|
137
147
|
|
138
148
|
# Replace ActionController::Failsafe with Lifo::Failsafe
|
139
149
|
config.middleware.swap ActionController::Failsafe, Lifo::Failsafe
|
@@ -157,8 +167,9 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
|
|
157
167
|
|+Rack::Lock+|Sets <tt>env["rack.multithread"]</tt> flag to +true+ and wraps the application within a Mutex.|
|
158
168
|
|+ActionController::Failsafe+|Returns HTTP Status +500+ to the client if an exception gets raised while dispatching.|
|
159
169
|
|+ActiveRecord::QueryCache+|Enables the Active Record query cache.|
|
160
|
-
|+
|
161
|
-
|+
|
170
|
+
|+ActionDispatch::Session::CookieStore+|Uses the cookie based session store.|
|
171
|
+
|+ActionDispatch::Session::CacheStore+|Uses the Rails cache based session store.|
|
172
|
+
|+ActionDispatch::Session::MemCacheStore+|Uses the memcached based session store.|
|
162
173
|
|+ActiveRecord::SessionStore+|Uses the database based session store.|
|
163
174
|
|+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or <tt>env["HTTP_X_HTTP_METHOD_OVERRIDE"]</tt>.|
|
164
175
|
|+Rack::Head+|Discards the response body if the client sends a +HEAD+ request.|
|
@@ -198,7 +209,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp
|
|
198
209
|
<strong>Clear the existing Rails middleware stack</strong>
|
199
210
|
|
200
211
|
<ruby>
|
201
|
-
#
|
212
|
+
# config/application.rb
|
202
213
|
config.middleware.clear
|
203
214
|
</ruby>
|
204
215
|
|
@@ -223,8 +234,3 @@ h4. Learning Rack
|
|
223
234
|
h4. Understanding Middlewares
|
224
235
|
|
225
236
|
* "Railscast on Rack Middlewares":http://railscasts.com/episodes/151-rack-middleware
|
226
|
-
|
227
|
-
h3. Changelog
|
228
|
-
|
229
|
-
* February 7, 2009: Second version by "Pratik":credits.html#lifo
|
230
|
-
* January 11, 2009: First version by "Pratik":credits.html#lifo
|
@@ -596,6 +596,8 @@ match "/stories/:name" => redirect {|params| "/posts/#{params[:name].pluralize}"
|
|
596
596
|
match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" }
|
597
597
|
</ruby>
|
598
598
|
|
599
|
+
Please note that this redirection is a 301 "Moved Permanently" redirect. Keep in mind that some web browsers or proxy servers will cache this type of redirect, making the old page inaccessible.
|
600
|
+
|
599
601
|
In all of these cases, if you don't provide the leading host (+http://www.example.com+), Rails will take those details from the current request.
|
600
602
|
|
601
603
|
h4. Routing to Rack Applications
|
@@ -829,10 +831,10 @@ If you want a complete list of all of the available routes in your application,
|
|
829
831
|
For example, here's a small section of the +rake routes+ output for a RESTful route:
|
830
832
|
|
831
833
|
<pre>
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
834
|
+
users GET /users(.:format) users#index
|
835
|
+
POST /users(.:format) users#create
|
836
|
+
new_user GET /users/new(.:format) users#new
|
837
|
+
edit_user GET /users/:id/edit(.:format) users#edit
|
836
838
|
</pre>
|
837
839
|
|
838
840
|
You may restrict the listing to the routes that map to a particular controller setting the +CONTROLLER+ environment variable:
|
@@ -881,12 +883,3 @@ The +assert_routing+ assertion checks the route both ways: it tests that the pat
|
|
881
883
|
<ruby>
|
882
884
|
assert_routing({ :path => "photos", :method => :post }, { :controller => "photos", :action => "create" })
|
883
885
|
</ruby>
|
884
|
-
|
885
|
-
h3. Changelog
|
886
|
-
|
887
|
-
* April 10, 2010: Updated guide to remove outdated and superfluous information, and to provide information about new features, by "Yehuda Katz":http://www.yehudakatz.com
|
888
|
-
* April 2, 2010: Updated guide to match new Routing DSL in Rails 3, by "Rizwan Reza":http://www.rizwanreza.com/
|
889
|
-
* February 1, 2010: Modifies the routing documentation to match new routing DSL in Rails 3, by Prem Sichanugrist
|
890
|
-
* October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes, by "Mike Gunderloy":credits.html#mgunderloy
|
891
|
-
* September 23, 2008: Added section on namespaced controllers and routing, by "Mike Gunderloy":credits.html#mgunderloy
|
892
|
-
* September 10, 2008: initial version by "Mike Gunderloy":credits.html#mgunderloy
|
@@ -77,8 +77,3 @@ bundle exec rake validate_guides
|
|
77
77
|
</plain>
|
78
78
|
|
79
79
|
Particularly, titles get an ID generated from their content and this often leads to duplicates. Please set +WARNINGS=1+ when generating guides to detect them. The warning messages suggest a way to fix them.
|
80
|
-
|
81
|
-
h3. Changelog
|
82
|
-
|
83
|
-
* March 31, 2011: grammar tweaks by "Josiah Ivey":http://twitter.com/josiahivey
|
84
|
-
* October 5, 2010: ported from the docrails wiki and revised by "Xavier Noria":credits.html#fxn
|
@@ -82,9 +82,9 @@ This will also be a good idea, if you modify the structure of an object and old
|
|
82
82
|
|
83
83
|
h4. Session Storage
|
84
84
|
|
85
|
-
-- _Rails provides several storage mechanisms for the session hashes. The most important are SessionStore and CookieStore._
|
85
|
+
-- _Rails provides several storage mechanisms for the session hashes. The most important are ActiveRecord::SessionStore and ActionDispatch::Session::CookieStore._
|
86
86
|
|
87
|
-
There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose SessionStore (or one of its derivatives) over file storage due to performance and maintenance reasons. SessionStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.
|
87
|
+
There are a number of session storages, i.e. where Rails saves the session hash and session id. Most real-live applications choose ActiveRecord::SessionStore (or one of its derivatives) over file storage due to performance and maintenance reasons. ActiveRecord::SessionStore keeps the session id and hash in a database table and saves and retrieves the hash on every request.
|
88
88
|
|
89
89
|
Rails 2 introduced a new default session storage, CookieStore. CookieStore saves the session hash directly in a cookie on the client-side. The server retrieves the session hash from the cookie and eliminates the need for a session id. That will greatly increase the speed of the application, but it is a controversial storage option and you have to think about the security implications of it:
|
90
90
|
|
@@ -157,9 +157,9 @@ One possibility is to set the expiry time-stamp of the cookie with the session i
|
|
157
157
|
<ruby>
|
158
158
|
class Session < ActiveRecord::Base
|
159
159
|
def self.sweep(time = 1.hour)
|
160
|
-
|
161
|
-
count.to_i.send(unit)
|
162
|
-
|
160
|
+
if time.is_a?(String)
|
161
|
+
time = time.split.inject { |count, unit| count.to_i.send(unit) }
|
162
|
+
end
|
163
163
|
|
164
164
|
delete_all "updated_at < '#{time.ago.to_s(:db)}'"
|
165
165
|
end
|
@@ -474,7 +474,7 @@ h3. User Management
|
|
474
474
|
|
475
475
|
-- _Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure._
|
476
476
|
|
477
|
-
There are
|
477
|
+
There are a number of authentication plug-ins for Rails available. Good ones, such as the popular "devise":https://github.com/plataformatec/devise and "authlogic":https://github.com/binarylogic/authlogic, store only encrypted passwords, not plain-text passwords. In Rails 3.1 you can use the built-in +has_secure_password+ method which has similar features.
|
478
478
|
|
479
479
|
Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator):
|
480
480
|
|
@@ -648,7 +648,7 @@ h5(#sql-injection-introduction). Introduction
|
|
648
648
|
SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:
|
649
649
|
|
650
650
|
<ruby>
|
651
|
-
Project.
|
651
|
+
Project.where("name = '#{params[:name]}'")
|
652
652
|
</ruby>
|
653
653
|
|
654
654
|
This could be in a search action and the user may enter a project's name that he wants to find. If a malicious user enters ' OR 1 --, the resulting SQL query will be:
|
@@ -680,7 +680,7 @@ h5. Unauthorized Reading
|
|
680
680
|
The UNION statement connects two SQL queries and returns the data in one set. An attacker can use it to read arbitrary data from the database. Let's take the example from above:
|
681
681
|
|
682
682
|
<ruby>
|
683
|
-
Project.
|
683
|
+
Project.where("name = '#{params[:name]}'")
|
684
684
|
</ruby>
|
685
685
|
|
686
686
|
And now let's inject another query using the UNION statement:
|
@@ -702,18 +702,18 @@ Also, the second query renames some columns with the AS statement so that the we
|
|
702
702
|
|
703
703
|
h5(#sql-injection-countermeasures). Countermeasures
|
704
704
|
|
705
|
-
Ruby on Rails has a built-in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. <em class="highlight">Using +Model.find(id)+ or +Model.find_by_some thing(something)+ automatically applies this countermeasure</em>. But in SQL fragments, especially <em class="highlight">in conditions fragments (
|
705
|
+
Ruby on Rails has a built-in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. <em class="highlight">Using +Model.find(id)+ or +Model.find_by_some thing(something)+ automatically applies this countermeasure</em>. But in SQL fragments, especially <em class="highlight">in conditions fragments (+where("...")+), the +connection.execute()+ or +Model.find_by_sql()+ methods, it has to be applied manually</em>.
|
706
706
|
|
707
707
|
Instead of passing a string to the conditions option, you can pass an array to sanitize tainted strings like this:
|
708
708
|
|
709
709
|
<ruby>
|
710
|
-
Model.
|
710
|
+
Model.where("login = ? AND password = ?", entered_user_name, entered_password).first
|
711
711
|
</ruby>
|
712
712
|
|
713
713
|
As you can see, the first part of the array is an SQL fragment with question marks. The sanitized versions of the variables in the second part of the array replace the question marks. Or you can pass a hash for the same result:
|
714
714
|
|
715
715
|
<ruby>
|
716
|
-
Model.
|
716
|
+
Model.where(:login => entered_user_name, :password => entered_password).first
|
717
717
|
</ruby>
|
718
718
|
|
719
719
|
The array or hash form is only available in model instances. You can try +sanitize_sql()+ elsewhere. _(highlight)Make it a habit to think about the security consequences when using an external string in SQL_.
|
@@ -1002,7 +1002,3 @@ The security landscape shifts and it is important to keep up to date, because mi
|
|
1002
1002
|
* Subscribe to the Rails security "mailing list":http://groups.google.com/group/rubyonrails-security
|
1003
1003
|
* "Keep up to date on the other application layers":http://secunia.com/ (they have a weekly newsletter, too)
|
1004
1004
|
* A "good security blog":http://ha.ckers.org/blog/ including the "Cross-Site scripting Cheat Sheet":http://ha.ckers.org/xss.html
|
1005
|
-
|
1006
|
-
h3. Changelog
|
1007
|
-
|
1008
|
-
* November 1, 2008: First approved version by Heiko Webers
|
@@ -927,7 +927,7 @@ class UserControllerTest < ActionController::TestCase
|
|
927
927
|
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
|
928
928
|
post :invite_friend, :email => 'friend@example.com'
|
929
929
|
end
|
930
|
-
invite_email = ActionMailer::Base.deliveries.
|
930
|
+
invite_email = ActionMailer::Base.deliveries.last
|
931
931
|
|
932
932
|
assert_equal "You have been invited by me@example.com", invite_email.subject
|
933
933
|
assert_equal 'friend@example.com', invite_email.to[0]
|
@@ -945,11 +945,3 @@ The built-in +test/unit+ based testing is not the only way to test Rails applica
|
|
945
945
|
* "Machinist":https://github.com/notahat/machinist/tree/master, another replacement for fixtures.
|
946
946
|
* "Shoulda":http://www.thoughtbot.com/projects/shoulda, an extension to +test/unit+ with additional helpers, macros, and assertions.
|
947
947
|
* "RSpec":http://relishapp.com/rspec, a behavior-driven development framework
|
948
|
-
|
949
|
-
h3. Changelog
|
950
|
-
|
951
|
-
* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
|
952
|
-
* November 13, 2008: Revised based on feedback from Pratik Naik by "Akshay Surve":credits.html#asurve (not yet approved for publication)
|
953
|
-
* October 14, 2008: Edit and formatting pass by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
|
954
|
-
* October 12, 2008: First draft by "Akshay Surve":credits.html#asurve (not yet approved for publication)
|
955
|
-
|
data/lib/rails/application.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'active_support/core_ext/hash/reverse_merge'
|
2
|
-
require 'active_support/file_update_checker'
|
3
2
|
require 'fileutils'
|
4
3
|
require 'rails/plugin'
|
5
4
|
require 'rails/engine'
|
@@ -33,6 +32,25 @@ module Rails
|
|
33
32
|
#
|
34
33
|
# The Application is also responsible for building the middleware stack.
|
35
34
|
#
|
35
|
+
# == Booting process
|
36
|
+
#
|
37
|
+
# The application is also responsible for setting up and executing the booting
|
38
|
+
# process. From the moment you require "config/application.rb" in your app,
|
39
|
+
# the booting process goes like this:
|
40
|
+
#
|
41
|
+
# 1) require "config/boot.rb" to setup load paths
|
42
|
+
# 2) require railties and engines
|
43
|
+
# 3) Define Rails.application as "class MyApp::Application < Rails::Application"
|
44
|
+
# 4) Run config.before_configuration callbacks
|
45
|
+
# 5) Load config/environments/ENV.rb
|
46
|
+
# 6) Run config.before_initialize callbacks
|
47
|
+
# 7) Run Railtie#initializer defined by railties, engines and application.
|
48
|
+
# One by one, each engine sets up its load paths, routes and runs its config/initializers/* files.
|
49
|
+
# 9) Custom Railtie#initializers added by railties, engines and applications are executed
|
50
|
+
# 10) Build the middleware stack and run to_prepare callbacks
|
51
|
+
# 11) Run config.before_eager_load and eager_load if cache classes is true
|
52
|
+
# 12) Run config.after_initialize callbacks
|
53
|
+
#
|
36
54
|
class Application < Engine
|
37
55
|
autoload :Bootstrap, 'rails/application/bootstrap'
|
38
56
|
autoload :Configuration, 'rails/application/configuration'
|
@@ -52,12 +70,14 @@ module Rails
|
|
52
70
|
|
53
71
|
attr_accessor :assets, :sandbox
|
54
72
|
alias_method :sandbox?, :sandbox
|
73
|
+
attr_reader :reloaders
|
55
74
|
|
56
75
|
delegate :default_url_options, :default_url_options=, :to => :routes
|
57
76
|
|
58
77
|
def initialize
|
59
78
|
super
|
60
79
|
@initialized = false
|
80
|
+
@reloaders = []
|
61
81
|
end
|
62
82
|
|
63
83
|
# This method is called just after an application inherits from Rails::Application,
|
@@ -83,54 +103,107 @@ module Rails
|
|
83
103
|
require environment if environment
|
84
104
|
end
|
85
105
|
|
106
|
+
# Reload application routes regardless if they changed or not.
|
86
107
|
def reload_routes!
|
87
108
|
routes_reloader.reload!
|
88
109
|
end
|
89
110
|
|
90
|
-
def routes_reloader
|
111
|
+
def routes_reloader #:nodoc:
|
91
112
|
@routes_reloader ||= RoutesReloader.new
|
92
113
|
end
|
93
114
|
|
94
|
-
|
115
|
+
# Returns an array of file paths appended with a hash of directories-extensions
|
116
|
+
# suitable for ActiveSupport::FileUpdateChecker API.
|
117
|
+
def watchable_args
|
118
|
+
files = []
|
119
|
+
files.concat config.watchable_files
|
120
|
+
|
121
|
+
dirs = {}
|
122
|
+
dirs.merge! config.watchable_dirs
|
123
|
+
ActiveSupport::Dependencies.autoload_paths.each do |path|
|
124
|
+
dirs[path.to_s] = [:rb]
|
125
|
+
end
|
126
|
+
|
127
|
+
[files, dirs]
|
128
|
+
end
|
129
|
+
|
130
|
+
# Initialize the application passing the given group. By default, the
|
131
|
+
# group is :default but sprockets precompilation passes group equals
|
132
|
+
# to assets if initialize_on_precompile is false to avoid booting the
|
133
|
+
# whole app.
|
134
|
+
def initialize!(group=:default) #:nodoc:
|
95
135
|
raise "Application has been already initialized." if @initialized
|
96
136
|
run_initializers(group, self)
|
97
137
|
@initialized = true
|
98
138
|
self
|
99
139
|
end
|
100
140
|
|
141
|
+
# Load the application and its railties tasks and invoke the registered hooks.
|
142
|
+
# Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
|
101
143
|
def load_tasks(app=self)
|
102
144
|
initialize_tasks
|
103
145
|
super
|
104
146
|
self
|
105
147
|
end
|
106
148
|
|
107
|
-
|
108
|
-
|
109
|
-
super
|
110
|
-
self
|
111
|
-
end
|
112
|
-
|
149
|
+
# Load the application console and invoke the registered hooks.
|
150
|
+
# Check <tt>Rails::Railtie.console</tt> for more info.
|
113
151
|
def load_console(app=self)
|
114
152
|
initialize_console
|
115
153
|
super
|
116
154
|
self
|
117
155
|
end
|
118
156
|
|
157
|
+
# Rails.application.env_config stores some of the Rails initial environment parameters.
|
158
|
+
# Currently stores:
|
159
|
+
#
|
160
|
+
# * action_dispatch.parameter_filter" => config.filter_parameters,
|
161
|
+
# * action_dispatch.secret_token" => config.secret_token,
|
162
|
+
# * action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions
|
163
|
+
#
|
164
|
+
# These parameters will be used by middlewares and engines to configure themselves.
|
165
|
+
#
|
119
166
|
def env_config
|
120
167
|
@env_config ||= super.merge({
|
121
168
|
"action_dispatch.parameter_filter" => config.filter_parameters,
|
122
169
|
"action_dispatch.secret_token" => config.secret_token,
|
123
|
-
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions
|
170
|
+
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
|
171
|
+
"action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
|
172
|
+
"action_dispatch.logger" => Rails.logger,
|
173
|
+
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
|
124
174
|
})
|
125
175
|
end
|
126
176
|
|
127
|
-
|
177
|
+
# Returns the ordered railties for this application considering railties_order.
|
178
|
+
def ordered_railties #:nodoc:
|
179
|
+
@ordered_railties ||= begin
|
180
|
+
order = config.railties_order.map do |railtie|
|
181
|
+
if railtie == :main_app
|
182
|
+
self
|
183
|
+
elsif railtie.respond_to?(:instance)
|
184
|
+
railtie.instance
|
185
|
+
else
|
186
|
+
railtie
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
all = (railties.all - order)
|
191
|
+
all.push(self) unless all.include?(self)
|
192
|
+
order.push(:all) unless order.include?(:all)
|
193
|
+
|
194
|
+
index = order.index(:all)
|
195
|
+
order[index] = all
|
196
|
+
order.reverse.flatten
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def initializers #:nodoc:
|
128
201
|
Bootstrap.initializers_for(self) +
|
129
202
|
super +
|
130
203
|
Finisher.initializers_for(self)
|
131
204
|
end
|
132
205
|
|
133
|
-
def config
|
206
|
+
def config #:nodoc:
|
134
207
|
@config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
|
135
208
|
end
|
136
209
|
|
@@ -138,18 +211,19 @@ module Rails
|
|
138
211
|
self
|
139
212
|
end
|
140
213
|
|
141
|
-
def
|
142
|
-
|
143
|
-
super(env)
|
214
|
+
def helpers_paths #:nodoc:
|
215
|
+
config.helpers_paths
|
144
216
|
end
|
145
217
|
|
146
218
|
protected
|
147
219
|
|
148
220
|
alias :build_middleware_stack :app
|
149
221
|
|
150
|
-
def
|
151
|
-
|
222
|
+
def reload_dependencies?
|
223
|
+
config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
|
224
|
+
end
|
152
225
|
|
226
|
+
def default_middleware_stack
|
153
227
|
ActionDispatch::MiddlewareStack.new.tap do |middleware|
|
154
228
|
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
|
155
229
|
require "action_dispatch/http/rack_cache"
|
@@ -168,18 +242,25 @@ module Rails
|
|
168
242
|
middleware.use ::Rack::Lock unless config.allow_concurrency
|
169
243
|
middleware.use ::Rack::Runtime
|
170
244
|
middleware.use ::Rack::MethodOverride
|
171
|
-
middleware.use ::
|
172
|
-
middleware.use ::
|
245
|
+
middleware.use ::ActionDispatch::RequestId
|
246
|
+
middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods
|
247
|
+
middleware.use ::ActionDispatch::ShowExceptions, config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
|
248
|
+
middleware.use ::ActionDispatch::DebugExceptions
|
173
249
|
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
|
174
|
-
|
175
|
-
|
250
|
+
|
251
|
+
if config.action_dispatch.x_sendfile_header.present?
|
252
|
+
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
|
253
|
+
end
|
254
|
+
|
255
|
+
unless config.cache_classes
|
256
|
+
app = self
|
257
|
+
middleware.use ::ActionDispatch::Reloader, lambda { app.reload_dependencies? }
|
258
|
+
end
|
259
|
+
|
176
260
|
middleware.use ::ActionDispatch::Callbacks
|
177
261
|
middleware.use ::ActionDispatch::Cookies
|
178
262
|
|
179
263
|
if config.session_store
|
180
|
-
if config.force_ssl && !config.session_options.key?(:secure)
|
181
|
-
config.session_options[:secure] = true
|
182
|
-
end
|
183
264
|
middleware.use config.session_store, config.session_options
|
184
265
|
middleware.use ::ActionDispatch::Flash
|
185
266
|
end
|
@@ -195,7 +276,7 @@ module Rails
|
|
195
276
|
end
|
196
277
|
end
|
197
278
|
|
198
|
-
def initialize_tasks
|
279
|
+
def initialize_tasks #:nodoc:
|
199
280
|
self.class.rake_tasks do
|
200
281
|
require "rails/tasks"
|
201
282
|
task :environment do
|
@@ -205,26 +286,10 @@ module Rails
|
|
205
286
|
end
|
206
287
|
end
|
207
288
|
|
208
|
-
def
|
209
|
-
require "rails/generators"
|
210
|
-
end
|
211
|
-
|
212
|
-
def initialize_console
|
289
|
+
def initialize_console #:nodoc:
|
213
290
|
require "pp"
|
214
291
|
require "rails/console/app"
|
215
292
|
require "rails/console/helpers"
|
216
293
|
end
|
217
|
-
|
218
|
-
def build_original_fullpath(env)
|
219
|
-
path_info = env["PATH_INFO"]
|
220
|
-
query_string = env["QUERY_STRING"]
|
221
|
-
script_name = env["SCRIPT_NAME"]
|
222
|
-
|
223
|
-
if query_string.present?
|
224
|
-
"#{script_name}#{path_info}?#{query_string}"
|
225
|
-
else
|
226
|
-
"#{script_name}#{path_info}"
|
227
|
-
end
|
228
|
-
end
|
229
294
|
end
|
230
295
|
end
|