在rails3应用程序中获取xml时出现问题
我遇到了一个非常奇怪的问题:在 Rails 3 应用程序中请求 xml 格式的数据可以在我的本地环境中工作,但在我的托管环境中,我收到 NoMethod 错误。更准确地说:
nil:NilClass 的未定义方法`type'
这是我正在讨论的方法:
def getclosest
radius = params[:radius].gsub(",",".").to_d
origin = [params[:lat].gsub(",",".").to_d,params[:lng].gsub(",",".").to_d]
@groceries = Grocery.within(radius, :origin => origin)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @groceries }
end
end
当我转到 url 时调用此方法: http://www.mysite.com/groceriesclosest/myradius/mylat/mylng
.html 有效,但 .xml 无效,我收到上述错误。
但是,在我的本地环境中,当我转到 http://localhost:3000/groceriesclosest /radiues/lat/lng.xml 工作正常知道
我的托管版本出了什么问题吗?顺便说一句,我使用 Mongrel 作为网络服务器。
谢谢 !
编辑
一些精度:首先,“prod”中的数据集与本地相同,其次,它是行 format.xml { render :xml =>; @groceries }
导致错误。
以下是应用程序跟踪的一部分:
app/controllers/groceries_controller.rb:92:in block (2 level) in getclosest app/controllers/groceries_controller.rb:90:in getclosest
以及完整跟踪的某些部分:
I'm having a pretty weird problem : requesting data with xml format in a rails 3 app works on my local environment but on my hosted environment, I get a NoMethod Error. More precisely :
undefined method `type' for nil:NilClass
Here is the method I'm talking about :
def getclosest
radius = params[:radius].gsub(",",".").to_d
origin = [params[:lat].gsub(",",".").to_d,params[:lng].gsub(",",".").to_d]
@groceries = Grocery.within(radius, :origin => origin)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @groceries }
end
end
This method is called when I go to the url : http://www.mysite.com/groceriesclosest/myradius/mylat/mylng
The .html works but the .xml doesnt and I get the error described above.
However, in my local environment, when I go to http://localhost:3000/groceriesclosest/radiues/lat/lng.xml it works fine
Any idea what's going wrong on my hosted version ? Btw, I'm using Mongrel as webserver.
Thanks !
Edit
Some precisions : first, the data set in "prod" is the same as locally and second, it's the line format.xml { render :xml => @groceries }
that causes the error.
Here is part of the application trace :
app/controllers/groceries_controller.rb:92:in block (2 levels) in getclosest
app/controllers/groceries_controller.rb:90:in getclosest
And some part of the full trace :
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在以下行中出现相同的错误:
这在控制台中有效,但在我的 xml 响应中无效。
我通过更改
在控制台中给出相同响应的那一行来解决它。
所以也许你可以尝试类似的事情
。
Got the same error in the following line:
this works in console but not in my xml response.
I solved it by changing that line to
which gives the same response in the console though.
So maybe you could try something like
instead.