Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 - on the server, how do I list all the cookies and their values that have been sent from the client?

Ok, so I know that the client sends cookies to the server. I'm working on a legacy rails app and I just want to access a particular cookie if it exists. I need to do this in application_controller.rb. To start, how do I simply list each cookie that was sent along with it's value? Thanks much.

like image 363
tadasajon Avatar asked May 18 '16 21:05

tadasajon


People also ask

Where are cookies stored in Rails?

To identify a user's session information, Rails stores a special secure and tamper-proof cookie on the user's browser that contains their entire session hash (look for it in your developer tools, usually under the “Application” section) and it expires when the browser is closed.

What is cookie overflow?

During a recent project, two teammates of mine came across one of my favorite error messages. “Your Cookies are OverFlowing” The error is the result of storing too much data in a session; in the case of Rails, 4K. It is documented in the ActionDispatch::Cookies.

What does controller do in Rails?

The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. It is responsible for routing external requests to internal actions.


1 Answers

In your controller try the following:

cookies.each do |cookie|
  puts cookie
end

cookie[0] will be the name and cookie[1] will be the value.

like image 139
Sean Huber Avatar answered Sep 27 '22 19:09

Sean Huber