开发者

setting cookies directly in Rails2

开发者 https://www.devze.com 2023-03-28 14:04 出处:网络
Motivation: I\'m solving problems that are caused by strange/mutated/odd/perverse cookies in ruby-on-rails. I have captured some of these evil cookies and I can use cookie manager on firefox to recrea

Motivation: I'm solving problems that are caused by strange/mutated/odd/perverse cookies in ruby-on-rails. I have captured some of these evil cookies and I can use cookie manager on firefox to recreate the cookie state to replicate the problems. I want to write a rails page that will automate the task of setting these cookies.

Problem: If I change or delete the _myapp_session cookie in a rails controller, it issues me a new one. For example the following change to _myapp_session will never be seen by the user.

cookies[:_m开发者_开发问答yapp_session] = 'abcedf'

I want to recreate the exact cookies for my domain that a user has including invalid or corrupted cookies. How can I get this low level with rails2?


It shouldn't create a new one. Are the cookies of a different domain than the source domain of the page? If so, you can set the domain on the cookies by passing a block to the cookie -setter method.

cookies[cookie_name] = {
    :value => 'your value',
    :expires => 1.week.from_now,
    :domain => 'sub.yourdomain.com'
}
0

精彩评论

暂无评论...
验证码 换一张
取 消