我用JBuilder中創建我的API的觀點,但許多方法共享相同的JBuilder文件相同的模板:的Rails:respond_with兩種方法
module API
module V1
class DevicesController < ActionController::Base
respond_to :json
def create
...
respond_with @device, status: 201
end
def update
...
respond_with @device, status: 200
end
end
end
在本例中波紋管,create
和update
方法分享相同的觀點:device_response.json.jbuilder。我嘗試了respond_to :json
後添加template "devices/device_response"
,但我得到以下幾點:
undefined method `template' for API::V1::DevicesController:Class
我如何可以定義兩種方法獨特的JBuilder的模板迴應?
謝謝。
我想給'respond_with'方法應該是一個散列:'respond_with @device,狀態:200,模板: 「設備/ device_response」' – 2014-11-24 11:27:03
但我的文檔發現,'respond_with'不以模板作爲參數 – 2014-11-24 12:23:03