Is it possible to store a User's Cookie or Session in Controller and Get the cookie by accessing it from JS or Jquery?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Multiple Django sites on the same domain - CSRF fa
- Is there a way to remove IDV Tags from an AIFF fil
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
Session values are available on the server.
You can set them like this in your controller:
If you want to access that value later in javascript, you'll probably want to do something like this in a view:
Cookies are managed by the browser, so accessed differently.
To set one in your controller:
(You can also specify the path, expiration, etc. for the cookie using options.)
It can then be accessed using jQuery:
Note: you can also access the cookie using pure javascript (not jQuery) by parsing
document.cookie
, but it is much easier to let jQuery do it for you (if you're already using that library).