foodsoft/config/initializers/session_store.rb

28 lines
928 B
Ruby
Raw Normal View History

# 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
2020-09-04 12:57:19 +02:00
def set_cookie(request, session_id, cookie)
if script_name = FoodsoftConfig[:script_name]
path = request.original_fullpath[script_name.size..-1]
slug = path.split('/', 2).first
return if slug.blank?
cookie[:path] = script_name + slug
end
2020-09-04 12:57:19 +02:00
orig_set_cookie request, session_id, cookie
end
end
end
end
2020-09-04 12:57:19 +02:00
Rails.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