tadasajon
tadasajon

Reputation: 14866

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.

Upvotes: 9

Views: 6276

Answers (2)

sekrett
sekrett

Reputation: 1275

For a nicer output:

Rails.logger.debug(cookies.map { |cookie| cookie.join('=') }.join("\n"))

And watch your Rails log.

Upvotes: 4

Sean Huber
Sean Huber

Reputation: 3985

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.

Upvotes: 14

Related Questions