使用Rails的omniauth成功登录oauth后,保存Comment对象 [英] Saving the Comment object after successfull oauth login with Rails' omniauth

查看:131
本文介绍了使用Rails的omniauth成功登录oauth后,保存Comment对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Rails在用户成功记录槽 omniauth 后更新或存储评论. Twitter,Facebook或OpenID).

I want rails to either update or store the Comment after a user did a successfull loging trough omniauth (Twitter, Facebook or OpenID).

  1. (未登录)用户填写评论表格.发表.
  2. 用户会看到一个omniauth页面,可以在其中选择登录方法:Twitter,Facebook或OpenID.
  3. 用户成功从oAuth返回后,我要存储(或发布)评论.

我正在使用会话变量来进行此工作,但这不是非常线程安全的:如果用户在同一会话中打开了多个注释选项卡,它将中断.

I have this working, using a session-variable, but that is not very thread-safe: it will break if a user has multiple comment-tabs open with the same session.

我应该以未发布状态将注释保存到数据库中,然后在返回后切换该注释吗?如果是这样,如何知道如何切换正确的评论?问题类似于上述会话问题.

Should I save the comment to the database in an unpublished state, and toggle that after returning? And if so, how to know how to toggle te correct comment? Problem is similar to abovementioned session-issue.

有什么方法可以简单地将注释对象与omniauth一起传递,并在用户成功登录后返回时将其接收回来?

Is there some way to simply pass the comment-object along with the omniauth and recieve it back when the user returns from a successfull sign-in?

还是我可以传递一些哈希字符串,以便在成功返回后提取出来?

Or can I pass some hash-string along that I can extract after a successfull return?

编辑:完成重写以简化和阐明问题.

complete rewrite to simplify and clarify the question.

推荐答案

在会话中存储帖子ID和评论文本.成功认证后,使用存储的ID查找帖子并为其构建注释对象.

Store post id along with comment text in session. On successful authentication, find the post using stored id and build the comment object for it.

更新-如果身份验证失败,请删除所有此类条目.

Update - In case authentication fails, delete all such entries.

这篇关于使用Rails的omniauth成功登录oauth后,保存Comment对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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