Reputation: 18064
I need to restrict access to a route that communicates with a gem directly, and I cannot use a method of my ApplicationController
.
Since I don't use an authentication gem like Devise, I don't have access to authenticate
helpers in the routes file.
How do I access my signed cookies?
Upvotes: 4
Views: 1031
Reputation: 18064
Implement a constraint as indicated in the Ruby on Rails guide, and use this to access your cookies:
cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
You can now access your signed or encrypted cookies as usual:
cookies.signed[:user_id]
Upvotes: 7