Ruby on rails Rails应用程序中对Soap API的请求/响应
我需要从Rails 4应用程序中的SOAP API Web服务(XML)请求一些数据。用户输入他的电子邮件和确认号码,并收到一系列关于他的预订的信息 这在我创建的一个单独的应用程序中运行,没有指定正确的路由,也没有在索引视图中使用Ruby on rails Rails应用程序中对Soap API的请求/响应,ruby-on-rails,ruby,ruby-on-rails-4,soap,Ruby On Rails,Ruby,Ruby On Rails 4,Soap,我需要从Rails 4应用程序中的SOAP API Web服务(XML)请求一些数据。用户输入他的电子邮件和确认号码,并收到一系列关于他的预订的信息 这在我创建的一个单独的应用程序中运行,没有指定正确的路由,也没有在索引视图中使用:get)%>。完成的应用程序将需要一个适当的路由结构,但当我在新应用程序的视图中放置:get)%%>时,我无法从Soap API获得任何响应。(我只是得到一个空白屏幕,而旧版本运行良好) 目前,我正在使用硬编码字符串从索引路由到显示页面。我知道这可能不是最佳实践,但因
:get)%>
。完成的应用程序将需要一个适当的路由结构,但当我在新应用程序的视图中放置:get)%%>
时,我无法从Soap API获得任何响应。(我只是得到一个空白屏幕,而旧版本运行良好)
目前,我正在使用硬编码字符串从索引路由到显示页面。我知道这可能不是最佳实践,但因为这是从soapapi调用信息,所以Rails应用程序背后不需要数据库。(尽管我已经放了一个进去)
无论如何,提前谢谢你的帮助,这里是我的应用程序的所有部分,我认为现在是相关的。如果你需要更多信息,请告诉我
索引视图(/views/searches/Index.html.erb):
我认为您正在向
搜索/显示页面发出请求,但您没有相应的操作?您有一个索引操作,因此将表单更改为仅请求搜索
。这能解决问题吗?当路由到其他页面(如显示页面)时,似乎会出现问题。只要将搜索/索引设置为根并在视图中指定(root\u url,:method=>:get),就可以了。活动记录对它没有任何影响。当我尝试路由到另一个页面时,为什么soap请求不起作用?
<h1>Manage your Booking</h1>
<p>
<%= form_tag('searches/show', :method => :get ) %>
<%= label_tag 'Confirmation Number:' %>
<%= text_field_tag :confirmation_number %>
<%= label_tag 'Email:' %>
<%= text_field_tag :email %>
<%= submit_tag "Lookup", name: nil %>
</p>
<% if @search %>
<dl id ="reservation_info">
<dt>Test Text:</dt>
<dd><%= @search.reservation_id %></dd>
<dd><%= @search.dining_date_and_time %></dd>
<dd><%= @search.size %></dd>
<dd><%= @search.session_id %></dd>
<dd><%= @search.first_name %></dd>
<dd><%= @search.last_name %></dd>
<dd><%= @search.confirm_number %></dd>
<dd><%= @search.allowed_to_cancel_online %></dd>
<dd><%= @search.restaurant_phone_number %></dd>
<dd><%= @search.restaurant_id %></dd>
<dd><%= @search.restaurant_name %></dd>
<dd><%= @search.location_id %></dd>
<dd><%= @search.location_name %></dd>
</dl>
<% end %>
class SearchesController < ApplicationController
def index
if params[:confirmation_number] && params[:email]
@search = Search.new params[:confirmation_number], params[:email]
end
end
private
def search_params
params.require(:search).permit(:confirmation_number, :email)
end
end
Routes config file:
Rails.application.routes.draw do
resources :reservations do
end
resources :searches do
end
end
class Search < ActiveRecord::Base
attr_accessor :reservation_id, :dining_date_and_time, :size, :session_id, :first_name, :last_name, :confirm_number, :allowed_to_cancel_online, :restaurant_phone_number, :restaurant_id, :restaurant_name, :location_id, :location_name
def client
client = Savon.client(wsdl: "http://wsdl-example-url-placeholder?wsdl", follow_redirects: :follow_redirects)
end
def initialize(confirmation_number, email)
message = {'ConfirmationNumber' => confirm_number, 'EMail' => email }
response = client.call(:search_for_reservation, message: message)
if response.success?
data = response.to_array(:search_for_reservation_response, :reservation).first
if data
@reservation_id = data[:@id]
@dining_date_and_time = data[:dining_date_and_time]
@size = data[:size]
@session_id = data[:session_id]
@first_name = data[:first_name]
@last_name = data[:last_name]
@confirm_number = data[:confirmation_number]
@allowed_to_cancel_online = data[:allowed_to_cancel_online]
@restaurant_phone_number = data[:restaurant_phone_number]
data2 = response.to_hash[:search_for_reservation_response][:reservation][:restaurant]
if data2
@restaurant_id = data2[:@id]
@restaurant_name = data2[:name]
data3 = response.to_hash[:search_for_reservation_response][:reservation][:restaurant][:location]
if data3
@location_id = data3[:@id]
@location_name = data3[:name]
end
end
end
end
end
Started GET "/searches" for ::1 at 2015-07-08 14:39:56 +0100
ActiveRecord::SchemaMigration Load (1.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by SearchesController#index as HTML
Rendered searches/index.html.erb within layouts/application (2.9ms)
Completed 200 OK in 296ms (Views: 285.8ms | ActiveRecord: 0.0ms)
Started GET "/searches" for ::1 at 2015-07-08 14:39:56 +0100
Processing by SearchesController#index as HTML
Rendered searches/index.html.erb within layouts/application (0.3ms)
Completed 200 OK in 48ms (Views: 47.7ms | ActiveRecord: 0.0ms)
Started GET "/searches/show?utf8=%E2%9C%93&confirmation_number=ZANHJW5U&email=myemail%40email.com" for ::1 at 2015-07-08 14:40:06 +0100
Processing by SearchesController#show as HTML
Parameters: {"utf8"=>"✓", "confirmation_number"=>"ZANHJW5U", "email"=>"myemail@email.com", "id"=>"show"}
Rendered searches/show.html.erb within layouts/application (0.5ms)
Completed 200 OK in 49ms (Views: 48.2ms | ActiveRecord: 0.0ms