我用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