如何在rails应用程序之间传递参数? [英] How to pass parameters between rails applications?

查看:46
本文介绍了如何在rails应用程序之间传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在两个 Rails 应用程序之间传递参数.在一侧(发件人)我有一组哈希值.我有一个类似下面的代码来发送数据:

I have to pass parameters between two rails apps. In one side (sender) I have an array of hashes. I have a code like the following to send the data:

   http = Net::HTTP.new('localhost', '3030')
   result = http.post('/processar_lotes', my_array_of_hashes)

一些问题

  • 是否有任何(某种)序列化或类似的东西可以传递给其他应用程序?
  • 另一方面,我如何反序列化信息?
  • 我作为参数传递的内容的大小是否有限制?

推荐答案

回答您的问题:

  • 有很多方法可以序列化"数据.您可以使用自己的自定义格式,也可以使用标准格式.例如,您可以尝试使用 Rails to_xml 方法或 to_json 方法.您还可以使用 Ruby 的 Marshal 对象.
  • 根据您的选择,这可能是 from_jsonfrom_xmlMarshal.load 或您自己的自定义阅读器.
  • 通常,这对于 HTTP 帖子是无限制的,但根据您的服务器配置,它可能会更少.
  • There are many ways to 'serialize' the data. You can use your own custom format, or use a standard one. For example, you can try to use the Rails to_xml method, or the to_json method. You can also use Ruby's Marshal object.
  • Depending on your choice, this might be from_json, from_xml, Marshal.load, or your own custom reader.
  • Normally, this is unlimited for HTTP posts, but depending on your server configuration, it could be less.

这篇关于如何在rails应用程序之间传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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