在我的域服务器上使用 Ruby on Rails 应用程序
我在我的网站域上运行 Rails 版本 2.3.2,但我在理解其工作原理时遇到了一个巨大的问题:
我的网站在我的域开发服务器上运行 RoR 应用程序。它只是一个示例脚手架,允许您输入您的姓名、邮政编码、州等。我使用的是 ruby 1.8.2,并且也有一个 mysql 服务器。
我想通过 SOAP 将这些数据消耗到我的 Windows Phone 7 中(我不知道我是否有一个),但这就是我遇到问题的地方。
在使用 Visual Studio 时,当我将其定向到我的网址时,它无法找到我的服务器。它给出错误,指出没有任何格式正确的内容。
也许我没有运行服务器?我希望将数据解析为 XML 供手机使用,但我不知道如何设置!
基本上,我有域名和电话,但不了解其间的步骤。
任何人都可以帮助我启动并运行它吗?
I am running rails version 2.3.2 on my website domain and I am having a huge problem with wrapping my head around how this works:
I have my website running a RoR app on my domain development server. It is just a sample scaffold that allows you to type in your name, zip, state, etc. I am using ruby 1.8.2, and have a mysql server also.
I want to consume this data into my windows phone 7 through SOAP (I don't know if I even have one to begin with), but here is where I have problems.
In using visual studio, it cannot locate my server when i direct it over to my url. It gives the error saying that there was nothing in the correct format.
Maybe I don't have a server running? I want to have the data be parsed out into XML for the phone to consume, but I have no idea how to set this up!
Basically, I have the domain, and the phone, but no knowledge of the steps inbetween.
Can anyone help me get this up and running?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要尝试一些事情:
首先 - 您是否真正启动了服务器?例如通过运行“脚本/服务器”?
您可以使用“curl”(谷歌安装/下载)来测试服务器是否已启动并运行,这是一个非常简单(并且非常常用)的应用程序,可以轻松测试这些东西。
如果您运行curl并输入您将通过 Windows 手机访问该 url...并且它会响应一些内容(可能是 html),然后您可以稍后使用 CURL 来测试它是否也响应 xml 请求
。看看控制器里有没有。例如:
“respond_to”和“xml”位很重要,如果您想让系统使用 xml,它们应该出现在控制器的每个操作中,如果没有,您将必须进行研究。如何为您的代码执行此操作 - 或者,使用更高版本的 Rails 将允许您使用应包含这些标准的最新脚手架生成器
第三:您的 Windows Phone 应用程序可能只是不请求xml格式的资源等等Rails 返回 html(您的 SOAP 解析器无法理解)。我不知道如何检查这一点,但是 Rails 需要的是 HTML 标头:“Accept”设置为“application/xml”或“text/xml”
您还可以使用以下命令对任何给定的 URL 进行测试:使用例如“curl -H 'Accept: text/xml' 127.0.0.1/myapp”进行卷曲 - 如果它继续吐出 html(而不是 xml),那么显然它不会为该 URL 生成 xml。
A few things to try:
First - have you actually started the server? eg by running "script/server" ?
You can test that the server is up and running by using "curl" (google for it to install/download" which is a very simple (and very commonly used) application for testing this stuff easily.
if you run curl and type in the url that you'd be accessing via your windows phone... and it responds with something (probably html), then the server is up and running. You can later use CURL to test if it responds to an xml request too.
Second: go look in the controller. See if it has a section such as:
it's the "respond_to" and "xml" bits that matter if you are going to get your system to consume xml. They should be present in every action in your controller. If not - you will have to go a research how to do this for your code - alternatively, using a later version of rails will let you use the up-to-date scaffold generators that should include these as standard.
Third: it is possible that your Windows phone app is just not requesting the resources in xml format and so Rails is returning html (which your SOAP parser won't understand). I don't know how you can check this, but what rails requires is for the HTML-header: "Accept" to be set to "application/xml" or "text/xml"
You can also test this for any given URL with curl by using eg: "curl -H 'Accept: text/xml' 127.0.0.1/myapp" - if it continues to spit out html (and not xml) then obviously it's not producing xml for that URL.
最简单的方法是简单地发出 JSON 并在您的移动应用程序上使用它。一般来说,您只需要在对象上调用
.to_json
就完成了一半。 SOAP 需要大量的 XML 开销,这通常是不值得的,除非您已经陷入了一个充斥着 XML 开销的企业应用程序中。强烈鼓励将 Rails 堆栈更新到 2.3.11 和 Ruby 1.8.7,因为旧版本的 Rails 与任何应用程序一样都存在漏洞。 Ruby 1.8.2 是 2005 年左右发布的,实际上已经很古老了。
The easiest way to go about this is to simply emit JSON and consume that on your mobile application. Generally you just need to call
.to_json
on an object and you're half done. SOAP requires a ton of XML overhead that's usually not worth it unless you're already neck-deep in an enterprise application that's overflowing with it.Updating your Rails stack to 2.3.11 and Ruby 1.8.7 is strongly encouraged as older versions of Rails, as with any application, have vulnerabilities. Ruby 1.8.2 is from around 2005 and is effectively ancient.