如何从Rails 3中的模型访问Cookie

编程入门 行业动态 更新时间:2024-10-17 09:48:27
本文介绍了如何从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

本文发布于:2023-11-17 12:31:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610012.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   Rails   Cookie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!