From e5a6f7ee9e951dbe0e4e9ea2c0743b4dfb135c57 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 17 Jul 2016 19:38:54 +0530 Subject: Setup default session store internally, no longer through an application initializer - By default the session store will be set to cookie store with application name as session key. - Older apps are not affected as they will have the session store initializer generated by Rails in older versions, and Rails will not overwrite the session store if it is already set or disabled. - But new apps will not have the initializer, instead the session store will be set to cookie store by default. - Based on comment by DHH here - https://github.com/rails/rails/issues/25181#issuecomment-222312764. --- railties/lib/rails/application/configuration.rb | 2 -- railties/lib/rails/application/finisher.rb | 8 ++++++++ railties/lib/rails/generators/rails/app/app_generator.rb | 1 - .../rails/app/templates/config/initializers/session_store.rb.tt | 3 --- 4 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt (limited to 'railties/lib') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9b93415c83..a92e7ea897 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -34,8 +34,6 @@ module Rails @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 diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index daf3a24b16..64de10a5c7 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -33,6 +33,14 @@ module Rails end end + # Setup default session store if not already set in config/application.rb + initializer :setup_default_session_store, before: :build_middleware_stack do |app| + unless app.config.session_store? + app_name = app.class.name ? app.railtie_name.chomp('_application') : '' + app.config.session_store :cookie_store, key: "_#{app_name}_session" + end + end + initializer :build_middleware_stack do build_middleware_stack end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 2879be5fa2..0390457cdb 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -337,7 +337,6 @@ module Rails def delete_non_api_initializers_if_api_option if options[:api] - remove_file 'config/initializers/session_store.rb' remove_file 'config/initializers/cookies_serializer.rb' end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt deleted file mode 100644 index 2bb9b82c61..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ /dev/null @@ -1,3 +0,0 @@ -# Be sure to restart your server when you modify this file. - -Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %> -- cgit v1.2.3