I need to set cookies in my ApplicationController but I'm not sure how. I've tried using cookies - nothing, using ActionController::Cookies - nothing. I don't need anything more then setting and getting cookies but what I do need is to set them in ApplicationController.
EDIT:
Found the answer: request.cookies['help'] = 'yes'
In your Java server, you should call cookie. setPath("/") before adding it to response. Such cookie will match all request URIs.
Cookies are usually set by a web-server using the response Set-Cookie HTTP-header. Then, the browser automatically adds them to (almost) every request to the same domain using the Cookie HTTP-header.
What do you mean by setting cookie in application controller? You would set cookie in browser corresponding to some controller action. If you want to set the cookie for all actions then you may consider using a before filter and apply that filter to all your controller actions.
You can set and delete cookies as shown below:
cookies[:key] = { :value => 'a yummy cookie', :expires => 1.year.from_now, :domain => 'domain.com' } cookies.delete(:key, :domain => 'domain.com')
Please note that if you specify a :domain when setting a cookie, you must also specify the domain when deleting the cookie.
e.g. cookies[:user_name] = "david"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With