foodsoft/config/initializers/session_store.rb
Patrick Gansterer ba052efe5e Set the path of the _foodsoft_session cookie to the slug
This allows the usage of different foodcoops at the same time.
2017-09-29 00:47:00 +02:00

27 lines
975 B
Ruby

# Be sure to restart your server when you modify this file.
module ActionDispatch
module Session
class SlugCookieStore < CookieStore
alias_method :orig_set_cookie, :set_cookie
def set_cookie(env, session_id, cookie)
if script_name = FoodsoftConfig[:script_name]
request = ActionDispatch::Request.new env
path = request.original_fullpath[script_name.size..-1]
slug = path.split('/', 2).first
return if slug.blank?
cookie[:path] = script_name + slug
end
orig_set_cookie env, session_id, cookie
end
end
end
end
Foodsoft::Application.config.session_store :slug_cookie_store, key: '_foodsoft_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# Foodsoft::Application.config.session_store :active_record_store