在rails3应用程序中获取xml时出现问题

发布于 2024-10-04 01:39:48 字数 1377 浏览 1 评论 0原文

我遇到了一个非常奇怪的问题:在 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

以及完整跟踪的某些部分:

alt text

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 :

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-10-11 01:39:48

在以下行中出现相同的错误:

respond_with Article.all.comments

这在控制台中有效,但在我的 xml 响应中无效。

我通过更改

respond_with Article.all.comments.all

在控制台中给出相同响应的那一行来解决它。

所以也许你可以尝试类似的事情

render :xml => @groceries.all

Got the same error in the following line:

respond_with Article.all.comments

this works in console but not in my xml response.

I solved it by changing that line to

respond_with Article.all.comments.all

which gives the same response in the console though.

So maybe you could try something like

render :xml => @groceries.all

instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文