我試圖用這個Ruby包裝器,https://github.com/mattetti/Pvwatts,但我有一個問題,我的控制器應用程序/控制器/ projects_controller.rb(相關摘錄)NameError(未初始化不斷薩翁::請求)
require 'rubygems'
require 'savon'
class ProjectsController < ApplicationController
<snip>
def annual_production
<snip>
client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL")
production_data = Pvwatts.new("<key>").yearly_production(:locationId => @locationId, :dc_rating => @dc_rating, :tilt => @tilt, :azimuth => @azimuth, :derate => @derate, :cost => @cost, :array_type => @array_type)
<snip>
respond_to do |format|
if @project.update_attributes(params[:project])
format.js
format.html
else
format.html { render :action => "update" }
format.json { render :json => @project.errors, :status => :unprocessable_entity }
end
end
end
end
class Pvwatts
Savon::Request.log = false
<snip>
def yearly_production(opts={})
<snip>
client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL")
<snip>
req = prep_request(@locationId, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost)
response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req }
<snip>
end
end
這是觸發SOAP請求
<input type=button id='pvwatt_update_button_id' value="Update from PVWatts" class='pvwatt_update_button_class'>
當點擊該按鈕的按鍵的定義,我得到這個「500內部服務器錯誤」
Started GET "/projects/annual_production?id=4&keys=8<key>&reference_state=California&reference_city=San+Francisco&locationId=23234&dc_rating=1&tilt=20&azimuth=180&derate=80&cost=0.1&array_type=0" for <server_ip_address> at Tue Nov 20 20:07:18 -0800 2012
Processing by ProjectsController#annual_production as */*
Parameters: {"array_type"=>"0", "azimuth"=>"180", "locationId"=>"23234", "dc_rating"=>"1", "reference_city"=>"San Francisco", "keys"=>"<key>", "id"=>"4", "derate"=>"80", "reference_state"=>"California", "cost"=>"0.1", "tilt"=>"20"}
Project Load (0.2ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT 1 [["id", "4"]]
Completed 500 Internal Server Error in 282ms
NameError (uninitialized constant Savon::Request):
app/controllers/projects_controller.rb:1697
app/controllers/projects_controller.rb:1628:in `annual_production'
Rendered /var/lib/gems/1.8/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
Rendered /var/lib/gems/1.8/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms)
Rendered /var/lib/gems/1.8/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (10.0ms)
任何人都知道我做錯了什麼?
這裏是我安裝的寶石列出
[email protected]:/home/user/myapp# gem list
*** LOCAL GEMS ***
actionmailer (3.2.9)
actionpack (3.2.9)
activemodel (3.2.9)
activerecord (3.2.9)
activeresource (3.2.9)
activesupport (3.2.9)
akami (1.2.0)
arel (3.0.2)
builder (3.0.4)
bundler (1.2.2, 1.2.1)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.4.0)
erubis (2.7.0)
execjs (1.4.0)
git (1.2.5)
gyoku (0.4.6)
hike (1.2.1)
httpi (1.1.1)
i18n (0.6.1)
jeweler (1.8.4)
journey (1.0.4)
jquery-rails (2.1.3)
json (1.7.5)
libv8 (3.3.10.4 x86-linux)
mail (2.4.4)
mime-types (1.19)
multi_json (1.3.7)
nokogiri (1.5.5)
nori (1.1.3)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.2)
rails (3.2.9)
railties (3.2.9)
rake (10.0.2, 10.0.1)
rdoc (3.12)
sass (3.2.3)
sass-rails (3.2.5)
savon (1.2.0)
sprockets (2.2.1)
sqlite3 (1.3.6)
therubyracer (0.10.2)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
tzinfo (0.3.35)
uglifier (1.3.0)
wasabi (2.5.1)
,這裏是我的Ruby和Rails版本
[email protected]:/home/user/myapp# gem -v
1.8.15
[email protected]:/home/user/myapp# ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
[email protected]:/home/user/myapp# rails -v
Rails 3.2.9
[email protected]:/home/user/myapp#
更新1
NoMethodError (undefined method `debug' for :logger:Symbol):
app/controllers/projects_controller.rb:1757:in `yearly_production'
app/controllers/projects_controller.rb:1638:in `annual_production'
更新2
NoMethodError (undefined method `get_pvwatts' for #<Savon::Client:0xb275c15c>):
app/controllers/projects_controller.rb:1737:in `yearly_production'
app/controllers/projects_controller.rb:1628:in `annual_production'
更新3
爲我工作的代碼如下:
Savon.configure do |c|
c.log = false
c.logger = Rails.logger
end
client = Savon::Client.new do
wsdl.document = "http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL"
end
response = client.request :wsdl, "get_pvwatts" do
soap.body = req
end
rdata = response.to_hash
感謝Steffen的迴應。我實施了您建議的更改,現在我正在獲取上面更新1中報告的錯誤。任何想法還有什麼問題?謝謝 – rh4games
我覺得我太快了,不能寫記錄器。如果你還沒有實現記錄器方法,只需註釋掉該行或指向Rails。記錄器',以防你在Rails下運行。在將它集成到Rails應用程序之前,我通常會嘗試運行一個小的代碼片段。 –
感謝Steffen的跟進。我重新編輯了我的問題,並添加了Update 3以及適用於我的代碼。非常感謝你的幫助。 – rh4games