2010-11-20 38 views
0

我有一個很奇怪的問題:在rails 3應用程序中使用xml格式請求數據在我的本地環境中工作,但在託管環境中,我得到一個NoMethod錯誤。更確切地說:在rails3應用程序中獲取xml的問題

未定義的方法`型」的零:NilClass

這是我講的方法:

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作爲網絡服務器。

謝謝!

編輯

一些精度:第一,數據「督促」設置是一樣的地方;第二,它是導致錯誤的行format.xml { render :xml => @groceries }

這裏是應用程序跟蹤的一部分:在getclosest 應用程序/控制器/ groceries_controller.rb在塊(2級)::

應用程序/控制器/ groceries_controller.rb:92 90:在getclosest

並全面跟蹤的某一部分:

alt text

+0

是您的prod中的數據集不同嗎?哪一行導致錯誤?你可以發佈堆棧跟蹤嗎? – johnmcaliley 2010-11-21 06:12:08

+0

數據集是一樣的。我編輯了信息來回答你的問題。讓我知道你是否需要更多的痕跡。謝謝 ! – Johanisma 2010-11-21 13:32:50

回答

0

得到了同樣的錯誤在下面一行:

respond_with Article.all.comments 

這可以在控制檯中使用,但不能在我的xml響應中使用。

我解決它通過改變線路

respond_with Article.all.comments.all 

這給在控制檯相同的反應,但。

因此,也許你可以嘗試像

render :xml => @groceries.all 

代替。