Rails curl语法 [英] Rails curl syntax

查看:169
本文介绍了Rails curl语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从我的rails应用程序运行以下命令:

I can run the following command from my rails app:

Hash.from_xml(%x{curl -d "admin=true" http://localhost:8888} ) rescue nil



现在我要替换 admin = true通过变量
如果我有x =admin = true
我怎么能写上面的命令?

now I want to replace the "admin=true" by a variable If I have x = "admin=true" how can I then write the above command?

谢谢很多

推荐答案

您可以直接在Ruby中使用curl,而不是依赖于命令和硬编码的参数 - 当前代码更难维护告诉你什么可能是错误的,如果发生了坏事。请参阅红宝石卷曲

You can use curl directly in Ruby instead depending on command and hardcoded parameters - current code is harder to maintain and doesn't tell you exactly what may be wrong if something bad happens. See ruby curl.

理想选项实际上将会删除使用卷曲,并使用 rest-client

The ideal option actually would be dropping use curl and use rest-client.

Hash.from_xml(RestClient.get('http://localhost:8888/', :admin=>true))

没有依赖关系 - 只是纯ruby。在任何情况下引发适当的异常。平凡参数指定。 POST动词可用。

No dependencies - just pure ruby. Proper exceptions raised in any case. Trivial parameter specing. POST verb available.

这篇关于Rails curl语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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