1
我有這個在我的Active Record模式:HTTParty - 參數的個數錯誤 - 活動記錄模式
class ItemImage < ActiveRecord::Base
belongs_to :item, :foreign_key => :upc, :primary_key => :upc
include HTTParty
format :xml
base_uri 'https://myapi.com/v2'
end
每當我試圖做這樣的事情在控制檯:ItemImage.first
時,Rails引發此錯誤:
ArgumentError: wrong number of arguments (0 for 1)
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/httparty-0.13.1/lib/httparty.rb:81:in `logger'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation/delegation.rb:37:in `block in method_missing'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation.rb:241:in `block in scoping'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/scoping.rb:98:in `with_scope'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation.rb:241:in `scoping'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation/delegation.rb:37:in `method_missing'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/explain.rb:26:in `logging_query_plan'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation.rb:159:in `to_a'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:380:in `find_first'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:122:in `first'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/querying.rb:5:in `first'
from (irb):1
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/name/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
我是新來的HHTParty,所以我真的不知道發生了什麼事情。我想知道這是否與我在活動記錄模型中使用HTTParty相關。我見過的大多數例子都是在ActiveRecord之外使用它的。任何幫助解決這個問題?提前致謝!
嗯......所以HTTParty不應該直接包含在Active Record模型中?也許我應該在一個lib類中包含HTTParty,然後在AR模型中使用響應? – settheline
我傾向於將HTTParty放置在Service對象中,或者只放置在模型中的普通舊ruby對象/ –