aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJorge Bejar <jorge@wyeworks.com>2015-07-20 16:37:19 -0300
committerJorge Bejar <jorge@wyeworks.com>2015-12-09 10:53:45 -0300
commit668d94fff644e87d49004e4f48143f5561e8c9a0 (patch)
treea38264d4c13a414c50f4093e100630583ed163c1 /railties
parent6fb2afed5284c7bc0157055609a0fde9ea4518d0 (diff)
downloadrails-668d94fff644e87d49004e4f48143f5561e8c9a0.tar.gz
rails-668d94fff644e87d49004e4f48143f5561e8c9a0.tar.bz2
rails-668d94fff644e87d49004e4f48143f5561e8c9a0.zip
Add debug_exception_response_format config to configure DebugException
behavior
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application/configuration.rb61
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt8
-rw-r--r--railties/test/generators/api_app_generator_test.rb4
3 files changed, 43 insertions, 30 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 91ed835bd6..bb5f0a21d8 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -19,40 +19,41 @@ module Rails
:beginning_of_week, :filter_redirect, :x
attr_writer :log_level
- attr_reader :encoding, :api_only, :static_cache_control
+ attr_reader :encoding, :api_only, :static_cache_control, :debug_exception_response_format
def initialize(*)
super
self.encoding = "utf-8"
- @allow_concurrency = nil
- @consider_all_requests_local = false
- @filter_parameters = []
- @filter_redirect = []
- @helpers_paths = []
- @public_file_server = ActiveSupport::OrderedOptions.new
- @public_file_server.enabled = true
- @public_file_server.index_name = "index"
- @force_ssl = false
- @ssl_options = {}
- @session_store = :cookie_store
- @session_options = {}
- @time_zone = "UTC"
- @beginning_of_week = :monday
- @log_level = nil
- @generators = app_generators
- @cache_store = [ :file_store, "#{root}/tmp/cache/" ]
- @railties_order = [:all]
- @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
- @reload_classes_only_on_change = true
- @file_watcher = file_update_checker
- @exceptions_app = nil
- @autoflush_log = true
- @log_formatter = ActiveSupport::Logger::SimpleFormatter.new
- @eager_load = nil
- @secret_token = nil
- @secret_key_base = nil
- @api_only = false
- @x = Custom.new
+ @allow_concurrency = nil
+ @consider_all_requests_local = false
+ @filter_parameters = []
+ @filter_redirect = []
+ @helpers_paths = []
+ @public_file_server = ActiveSupport::OrderedOptions.new
+ @public_file_server.enabled = true
+ @public_file_server.index_name = "index"
+ @force_ssl = false
+ @ssl_options = {}
+ @session_store = :cookie_store
+ @session_options = {}
+ @time_zone = "UTC"
+ @beginning_of_week = :monday
+ @log_level = nil
+ @generators = app_generators
+ @cache_store = [ :file_store, "#{root}/tmp/cache/" ]
+ @railties_order = [:all]
+ @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
+ @reload_classes_only_on_change = true
+ @file_watcher = file_update_checker
+ @exceptions_app = nil
+ @autoflush_log = true
+ @log_formatter = ActiveSupport::Logger::SimpleFormatter.new
+ @eager_load = nil
+ @secret_token = nil
+ @secret_key_base = nil
+ @api_only = false
+ @debug_exception_response_format = :default
+ @x = Custom.new
end
def static_cache_control=(value)
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 4dd20a9d2e..eaa885671b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -23,7 +23,15 @@ Rails.application.configure do
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
+ <%- if options[:api] -%>
+ # Return error responses in the format requested by the client
+ # or default to JSON format.
+ # This option is useful for Rails API only applications developers
+ # who prefer to render errors in the expected format instead of
+ # rendering a HTML page with debug info and web-console.
+ config.debug_exception_response_format = :api
+ <%- end -%>
<%- unless options.skip_action_mailer? -%>
# Don't care if the mailer can't send.
diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb
index b5980746bb..7273c67a4e 100644
--- a/railties/test/generators/api_app_generator_test.rb
+++ b/railties/test/generators/api_app_generator_test.rb
@@ -48,6 +48,10 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
assert_match(/config.api_only = true/, content)
end
+ assert_file "config/environments/development.rb" do |content|
+ assert_match(/config.debug_exception_response_format = :api/, content)
+ end
+
assert_file "config/initializers/cors.rb"
assert_file "config/initializers/wrap_parameters.rb"