RailsでAPIを作るときにいちいちエラーのレスポンス作るのがだるい話
なんかアクションで
def index begin ... rescue => e render :json => e end end
みたいにしてんのがだるいので設定する。
ApplicationControllerで
class ApplicationController < ActionController::Base rescue_from Exception, :with => :error_render private def error_render exception = $! respond_to do | format | format.json { render :json => e } end end end
とか設定しておくと、raiseしたときに拾ってよしなに出してくれる。