Skip to content

Commit

Permalink
Merge pull request #63 from zyuanhong/add_sth
Browse files Browse the repository at this point in the history
[Fix] Add missing code in 8.18
  • Loading branch information
AndorChen committed May 1, 2013
2 parents e3e95d1 + 27859ef commit 63e811d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chapter8.md
Expand Up @@ -791,6 +791,7 @@ class User < ActiveRecord::Base
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
```

顺便说一下,我们为 `create_remember_token` 方法增加了一层缩进,这样可以更好的突出这些方法是在 `private` 之后定义的。
Expand Down Expand Up @@ -821,7 +822,7 @@ end
上述代码中用到的 `cookies` 方法是由 Rails 提供的,我们可以把它看成 Hash,其中每个元素又都是一个 Hash,包含两个元素,`value` 指定 cookie 的文本,`expires` 指定 cookie 的失效日期。例如,我们可以使用下述代码实现登录功能,把 cookie 的值设为用户的记忆权标,失效日期设为 20 年之后:

```ruby
cookies[:remember_token] = { value: user.remember_token,
cookies[:remember_token] = { value: user.remember_token,
expires: 20.years.from_now.utc }
```

Expand Down

0 comments on commit 63e811d

Please sign in to comment.