从外部表格接收POST

nee*_*zer 10 forms post ruby-on-rails external

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

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

谢谢您的帮助!

Sim*_*tti 19

您无法从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
Run Code Online (Sandbox Code Playgroud)