在API控制器中響應的最簡單/最短的方式是什麼?目前以下工作:Rails使用狀態呈現模板
respond_to do |format|
format.json { render 'client', status: :ok }
end
然而該控制器將只以JSON(respond_to代碼:JSON)迴應|格式,所以整個的respond_to做|事情似乎是不必要的代碼。
理想我只想做喜歡的事,很簡單:
render 'client', status: :ok
更新: 我忘了提及的是:「客戶」是不符合我的動作名稱的JBuilder的模板。
更好的方法是使用respond_with:http://apidock.com/rails/ActionController/MimeResponds/respond_with –
在上面的例子中,如何使用respond_with? – TrevTheDev