从外部表格接收POST

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

  • 如何为外部表单生成有效的真实性令牌,以便我的Rails应用程序可以接受它?
  • 假设我可以回答上面的问题 – 我还需要做些什么特别的工作来完成这项工作吗? 除了真实性令牌,其余部分对我来说似乎很简单……

谢谢您的帮助!

您无法从Rails应用程序外部生成Autenticity令牌。 您可以做的是仅为此操作禁用令牌保护 ,并使用基于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 

您可以通过添加以下filter来删除检查:

 skip_before_filter :verify_authenticity_token, :only => :action_name