Skip to content

Add config.action_dispatch.cookies_default_options #39827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

hugopeixoto
Copy link
Contributor

Right now, cookie attributes could be set on each individual cookie by using:

cookies[:commenter_name] = { value: "david", path: "/blog/" }

This PR allows these attributes to be set globally in an initializer:

Rails.application.config.action_dispatch.cookies_default_options = {
  path: "/admin/",
  expires: -> { 1.day.from_now }
}

It supports Proc objects to delay execution to run time (vs initialization time).

This was particularly helpful when hosting a Rails app under a subdirectory, to avoid cookie collisions with other apps in different paths.

This PR is a new version of #27439. I had deleted the original fork so I don't know how I can reuse the issue.

I have tried to address @gmcgibbon's review notes, but I don't know how to interpret this comment:

#27439 (comment)

Add an option to allow setting default values for cookie attributes
globally.
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
@rails-bot
Copy link

rails-bot bot commented Oct 13, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Oct 13, 2020
@rails-bot rails-bot bot closed this Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants