如何从Rails 3中的模型访问Cookie [英] How can I access cookies from a model in Rails 3

查看:230
本文介绍了如何从Rails 3中的模型访问Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Koala gem与Facebook API进行互动。为了连接到API,我需要将我的cookie传递给考拉。我想在模型中这样做,因为我想在模型中的before_create回调期间从Facebook数据添加额外的数据给用户。例如,如果用户具有活动的FB会话,则在创建其用户行时存储其Facebook UID。如何从模型中获取Cookie?

解决方案

模型不应该意识到他们在网络环境中操作。



您可能想要考虑的只是将FB UID存储在模型上,方法与任何其他属性一样,通过在创建期间在模型上设置它。 p>

I am using the Koala gem to interact with the Facebook API. In order to connect to the API, I need to pass my cookies to Koala. I want to do this in a model because I want to add additional data to the user from Facebook data during a before_create callback in the model. For instance, if a user has an active FB session, store their Facebook UID when creating their user row. How do I get at cookies from within a model?

解决方案

Models should not be aware they're operating in a web environment.

What you might want to consider instead is just storing the FB UID on the model the same way as any other property, by setting it on the model during creation.

这篇关于如何从Rails 3中的模型访问Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆