Reputation: 195
I am having some problemss knowing the correct (Rails 4) way of using cookies. There is not too much info about it. I've read these 2 websites:
http://api.rubyonrails.org/classes/ActionDispatch/Session/CookieStore.html
Rails 4 not encrypting cookie contents
By using the 'encrypted' method of the object 'cookies' you can encrypt it. But I don't know how to get it back decrypted. Another thing: Isn't there a way to encrypt all the cookies with one call? Or should I do it for each one of them?
Example take from the second website.
cookies.encrypted[:discount] = 45
Although I found this:
https://cowbell-labs.com/2013-04-10-decrypt-rails-4-session.html
Should I use this one? Or there is a common way?
Thanks in advance.
Upvotes: 1
Views: 1626
Reputation: 671
Why you can't simply use the session
instead of custom cookies? Would be simpler in my opinion...
session[:discount] = 45
User will not be able to see this information, because it is stored in the server memory.
This way, you can use just the built-in, easy-to-use session cookie
that rails automatically gives you.
Upvotes: 1