我試圖驗證登錄過程中,在我登錄過程中如果用戶名&密碼正確,那麼用戶將登錄到他的儀表板,但如果用戶名爲&,密碼爲錯了,我得到一個XML響應。在rails中使用Nokogiri捕獲XML響應3.0.9
以下是session_controller代碼
{
require 'net/http'
require 'uri'
require 'open-uri'
require 'nokogiri'
class SessionsController < ApplicationController
def new
@title = "Sign in"
end
def create
redirect_to "http://<SERVER_IP>/billing/api/login?u=#{params[:session][:email]}&p=#{params[:session][:password]}"
a = "http://<SERVER_IP>/billing/api/login?u=#{params[:session][:email]}&p=#{params[:session][:password]}"
doc = Nokogiri::XML(open(a).read)
doc.css('status').each do |link|
# Create error message and re-render signin page
@b = link.content
end
end
def destroy
sign_out
redirect_to root_path
end
end
}
我得到這樣的XML響應從服務器
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<action>
<name>login</name>
<status>failed</status>
<status_message>Error description</status_message>
</action>
那些我得到這個反應我想使用上面的XML響應來刷新錯誤消息。
如果任何人有任何想法會拯救我的一天。