From e9e94c1d1540ebca77125f0f6beb6fdec2201242 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 20 Apr 2015 12:35:08 -0400 Subject: [PATCH] Add config.api_only = true to config/application.rb when using rails new --api --- .../generators/rails/app/templates/config/application.rb | 7 +++++++ railties/test/generators/api_app_generator_test.rb | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index a2661bfb51..6b7d7abd0b 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -32,5 +32,12 @@ module <%= app_const_base %> # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de +<%- if options[:api] -%> + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true +<%- end -%> end end diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 1aa3884466..ff70729110 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -39,6 +39,10 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_no_match(/gem 'sass-rails'/, content) end + assert_file "config/application.rb" do |content| + assert_match(/config.api_only = true/, content) + end + assert_file "config/initializers/wrap_parameters.rb" do |content| assert_no_match(/wrap_parameters/, content) end