2013-07-15 44 views
0

我收到某種零的錯誤;這告訴我'name'上的電話號碼是nil,但它並不顯示我在哪裏。未定義的方法'名稱'爲零:NilClass

這裏是我的路線:

# Mobile api 
    map.namespace :mobile_api do |api| 
    api.resources :updates, :only => [ :index ] 
    api.resources :checkouts, :collection => { :reading_progress => :put } 
    end 

我使用郵遞員調試API調用。

這裏是我與郵差爲原料,JSON發送作爲PUT到url localhost:3000/mobile_api/checkouts/reading_progress數據:

{"title":"Awesome post!", "tags": ["blue", "jeans"] } 

當我刪除了JSON數據,並沒有數據的請求它通過對控制器。

class MobileApi::CheckoutsController < ApplicationController 
    def reading_progress 
    binding.pry 
    end 
end 

只要我的任何數據添加到郵遞員送,我得到這個錯誤:

|ruby-1.8.7-p371| ubuntu-francois in ~/sites/mds 
± |old-state ✗| → ./script/server 
=> Booting Mongrel 
=> Rails 2.3.17 application starting on http://0.0.0.0:3000 
/home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rubyzip2-2.0.2/lib/zip/version.rb:2: warning: already initialized constant VERSION 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
    SQL (0.1ms) SET NAMES 'utf8' 
    SQL (0.1ms) SET SQL_AUTO_IS_NULL=0 
Error occurred while parsing request parameters. 
Contents: 

{"title":"Awesome post!", "tags": ["blue", "jeans"] } 
/!\ FAILSAFE /!\ Mon Jul 15 17:26:37 +0200 2013 
    Status: 500 Internal Server Error 
    undefined method `name' for nil:NilClass 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/whiny_nil.rb:52:in `method_missing' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/xml_mini/rexml.rb:29:in `merge_element!' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/xml_mini/rexml.rb:18:in `parse' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/xml_mini.rb:12:in `__send__' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/xml_mini.rb:12:in `parse' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/core_ext/hash/conversions.rb:171:in `from_xml' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/params_parser.rb:34:in `parse_formatted_parameters' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/params_parser.rb:11:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/session/abstract_store.rb:177:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.17/lib/active_record/query_cache.rb:29:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.17/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.17/lib/active_record/query_cache.rb:9:in `cache' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.17/lib/active_record/query_cache.rb:28:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.17/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/failsafe.rb:26:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/lock.rb:11:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/lock.rb:11:in `synchronize' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/lock.rb:11:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/dispatcher.rb:114:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/reloader.rb:34:in `run' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.17/lib/action_controller/dispatcher.rb:108:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.17/lib/rails/rack/static.rb:31:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/urlmap.rb:47:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/urlmap.rb:41:in `each' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/urlmap.rb:41:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.17/lib/rails/rack/log_tailer.rb:17:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/content_length.rb:13:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/chunked.rb:15:in `call' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/handler/mongrel.rb:67:in `process' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.6/lib/rack/handler/mongrel.rb:38:in `run' 
    /home/francois/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.17/lib/commands/server.rb:111 
    ./script/server:3:in `require' 
    ./script/server:3 

希望你能幫忙。

+1

跳出來的奇怪之處在於,您傳遞的是JSON,但錯誤來自XML解析器。檢查您的標題的內容類型。 – jdl

+0

嘿傢伙,感謝您的回覆,我會盡快在我的網絡恢復時進行測試。哈哈,TX會讓你知道它是否有效。這聽起來像它可能工作。 – Francois

回答

1

的錯誤發生在這裏:

/home/francois/.rvm/gems/ruby-1.8.7-p371/gems/activesupport-2.3.17/lib/active_support/xml_mini/rexml.rb:29:in `merge_element!' 

堆棧跟蹤的頂部行積極支持努力幫助NilClass錯誤。

有趣的是,rexml被調用來解析json。您的JSON字符串可能無法正確設置請求標頭。確保標題設置爲:

Content-Type: application/json 
+0

tx for response,只要inet再次運行就會測試:) – Francois

+0

@Francois如果這個答案對你有幫助,那麼你會考慮升級它嗎?謝謝。 –

+0

酷豆豆,謝謝 – Francois

相關問題