我們有一個Rails應用程序,我們通過Restful界面添加Workorders。Rails通過html響應寧靜的輸入
這是控制器代碼:
# POST /workorders
# POST /workorders.json
def create
@workorder = Workorder.new(params[:workorder])
respond_to do |format|
if @workorder.save
format.html { redirect_to @workorder, notice: 'Workorder was successfully created.' }
format.json { render json: @workorder, status: :created, location: @workorder }
else
format.html { render action: "new" }
format.json { render json: @workorder.errors, status: :unprocessable_entity }
end
end
end
在添加工作單,響應從該行代碼來:
format.html { redirect_to @workorder, notice: 'Workorder was successfully created.' }
什麼其他應用程序的回報得到的是:
<html><body>You are being <a href="http://ndeavor.ameipro.com/workorders/50">redirected</a>.</body></html>
50是新的workorder.id,但我們在解析時遇到了問題。
有沒有辦法將workorder.id放入返回的標題中?我們需要發送數據的應用程序知道新的workorder.id是什麼。
另外,有沒有辦法知道請求來自其他應用程序,而不是在Rails UI中創建的新工作順序。
感謝您的幫助!
更新1
請澄清一些關於REST我。如果寧靜的輸入是json,那麼控制器迴應json?如果輸入是html,那麼控制器可以使用json還是僅使用html?
當我使用RestClient進行測試時,有沒有辦法將這個url變成json輸入或添加一些要求json響應的東西?
http://localhost:5000/types?type[id]=318&type[typecode]=test4
什麼是你的「其他應用程序」做什麼?它是什麼編碼的,用例是什麼? – bdares 2013-04-23 03:43:59
我們正在使用Mule將數據從資產管理系統移至我們的新Rails應用程序。對於一些測試,我們使用Wiztools Restclient。 – Reddirt 2013-04-23 13:25:46