本文介绍了从外部表单接收POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在另一个网站(使用不同的后端)上有一个表单,我希望能够发布到我的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
发布评论