David Morales
David Morales

Reputation: 18064

How do I get a signed cookie from the request?

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

Answers (1)

David Morales
David Morales

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

Related Questions