使用Httparty将表单数据发送到远程Rails应用程序 [英] Sending Form data to remote rails application using Httparty

查看:86
本文介绍了使用Httparty将表单数据发送到远程Rails应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Httparty的新手.我有一个简单的Rails应用程序,其默认方法为new,用于创建新的Model对象.因此,基本上,如果您以商品控制器为例.第一个新方法通过Model.new实例化Model,然后调用部分表单,该表单要求用户提供数据,并在提交时调用控制器create方法.但是我的问题是我想使用Httparty从不同的Rails应用程序远程调用这些方法.因此,我首先调用新方法,然后实例化远程模型并将其返回到远程应用程序.在远程应用程序中,我将实例获取为json,而无法将其获取为对象模型.因此,当我调用form_for时,它给了我错误,因为它接受对我来说是远程应用程序上的对象模型,而该对象模型不是本地的.有什么办法吗?提前非常感谢.

I am new to Httparty. I have a simple rails application with its default methods, new, create for creating a new Model object. So basically if you consider the article controller as an example. First new method instantiates the Model by Model.new and then the partial form is called which asks user for data and upon submit it calls the controller create method. But my problem is that I want to call these methods remotely from the different rails application using Httparty. So I first call the new method, it then instantiates the remote model and returns it to the remote app. In the remote app I get the instance as json and I am not able to get it as Object model. So when I call the form_for there it gives me error as it accepts object model which is on a remote application for me and which is not local. Any solutions? Thanks a lot in advance.

推荐答案

好吧,我使用Httparty本身解决了它.困扰我的一件事是form_for,它受限于rails模型.因此,我使用了另一种形式,然后仅使用Httparty发布了数据,并且在远程应用程序(服务器端)上,我刚刚检索了每个字段并将其保留.很简单.现在我是Httparty的粉丝!

Okay I resolved it using Httparty itself. One thing which was making problems for me was form_for which is bounded to the rails model. So I used another form then just posted data using Httparty and on the remote app (Server side) I just retrieved each field and persist it. Very simple. Now I am a fan of Httparty!

这篇关于使用Httparty将表单数据发送到远程Rails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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