I am using the gem savon to read a xml, brought the results correctly. When I show in my view all fields of xml it shows correctly, but when I want to show only one of these fields it of the error. "" I put down my code.
class Code < ActiveRecord::Base
attr_accessor :strDataInicial, :strDataFinal
def initialize(strDataInicial)
@strDataInicial = strDataInicial
end
def data
if response.success?
return document(response)
else
raise "Error Message"
end
end
private
def document(response)
data = response.to_hash[:ocupacao_por_segmento_response][:ocupacao_por_segmento_result][:ocupacao_por_segmento]
if data
data
else
nil
end
end
def response
client.call(
:ocupacao_por_segmento,
message: {
strDataInicial: @strDataInicial,
strDataFinal: "03/25/2015",
blnConsideraReservasDayUse: true,
strGrupo1: "S",
strGrupo2: "S",
exibeValoresContaAvulsa: true,
strPool: "S",
hotelId: "1"
}
)
end
def client
Savon.client(
wsdl: "http://ift.tt/1Ql5onK",
endpoint: "http://ift.tt/1Ql5onK",
ssl_verify_mode: :none
)
end
end
class CodesController < ApplicationController
def index
@code = Code.new(params[:strDataInicial])
@code = @code.data
end
end
<%= form_tag root_url, method: :get do %>
<p>
<%= text_field_tag :strDataInicial, params[:strDataInicial] %>
<%= text_field_tag :strDataFinal, params[:strDataFinal] %>
<%= submit_tag "Enviar" %>
</p>
<% end %>
<% if @code %>
<dl id ="zip_info">
<dt>Diaria Media:</dt>
<dd><%= @code[:diariamedia] %></dd>
</dl>
<% end %>
Aucun commentaire:
Enregistrer un commentaire