从外部表单接收POST [英] Receive POST from External Form

查看:162
本文介绍了从外部表单接收POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个网站(使用不同的后端)上有一个表单,我希望能够发布到我的Rails应用程序(在不同的域中)。


  • 如何为外部表单生成有效的真实性标记,以便我的Rails应用程序可以接受它? - 我还需要做些什么才能做到这一点?除了真实性标记之外,其余部分对我来说似乎很简单......



感谢您的帮助!

解决方案

您无法从Rails应用程序外部生成真实标记。
您可以做的是禁用令牌保护功能
a>仅用于此操作,并使用基于before_filter的自定义实现。

  skip_before_filter:verify_authenticity_token,:only => :my_action 
before_filter:verify_custom_authenticity_token,:only => :my_action
$ b def verify_custom_authenticity_token
#检查请求是否来自信任源
结束


I have a form on another website (using a different backend) that I want to be able to POST to my Rails application (on a different domain).

  • How do I generate a valid authenticity token for the external form so that my Rails app will accept it?
  • Assuming I can do the answer to the above question--is there anything else special I need to do to make this work? Apart from the authenticity token, the rest of it seems pretty straightforward to me...

Thanks for the help!

解决方案

You can't generate an autenticity token from outside your Rails app. What you can do, is to disable the token protection only for this action and use a custom implementation based on a before_filter.

skip_before_filter :verify_authenticity_token, :only => :my_action
before_filter :verify_custom_authenticity_token, :only => :my_action

def verify_custom_authenticity_token
  # checks whether the request comes from a trusted source
end

这篇关于从外部表单接收POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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