Ruby on Rails:如何设置Cookie?

时间:2011-10-04 07:07:17

标签: ruby-on-rails cookies

  

可能重复:
  Rails cookies, set start date and expire date

如何在Rails中设置cookie?我需要相当于这个PHP代码:

<?php

setcookie("AFID", $_REQUEST['AFID'], time() + (60*60*24*365));
setcookie("SID", $_REQUEST['SID'], time() + (60*60*24*365));

?>

1 个答案:

答案 0 :(得分:4)

这很直接:

cookies['AFID'] = {
  :value => request.env['AFID'],
  :expires => 1.year.from_now
}