Rails 3,设计授权和远程表单
我正在开发我的第一个 Rails 应用程序,它有可以评论的帖子。在帖子显示页面内有一个评论按钮,用于加载评论表单(来自 comments/new.js.erb),并且用户可以提交评论(使用 comments/creating.js.erb)。
任何人都可以看到帖子展示页面,但只有登录用户才能发表评论。当用户已经登录时一切正常,问题是当他没有登录时,因为 Ajax 调用返回 401。
我的问题是:在这种情况下如何请求设计登录表单,并在登录后重定向用户返回Post show页面并触发ajax操作?
我想在此页面上创建更多也需要登录才能执行的操作,例如评级,但我还找不到解决方案。
谢谢!
I'm developing my first Rails application and it has Posts that can be commented. Inside the Post show page there is a comment button that loads the comments form (from comments/new.js.erb) and the user can submit the comment (using comments/creating.js.erb).
Anyone can see the Post show page, but only logged users can comment. Everything works fine when the user is already logged in, the problem is when he is not, because the Ajax call returns a 401.
My question is: how can request the devise login form in that case and, after the login, redirect the user back to the Post show page and trigger the ajax action?
I want to create more actions on this page that also need login to be performed, such as rating, but I couldn't find a solution yet.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论