Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# encoding: utf-8
class OperationsController < ApplicationController
respond_to :json
rescue_from ActiveRecord::RecordNotFound, :with => :not_found
def show
operation = Operation.find(params[:id])
respond_with operation
end
def create
app = App.find_by_app_key!(params[:app_key])
operation = app.new_operation(params[:operation])
operation.save
respond_with operation
end
private
def not_found(exception = nil)
response = {error: { :message => exception.message, :request => request.path }}
render json: response, status: :not_found
end
end
@rodrigopinto

This comment has been minimized.

Copy link

@rodrigopinto rodrigopinto commented Jan 17, 2012

@fmcypriano vi que você implementou um rescue_from para enviar um not_found diferente, eu entendi mas fiquei na dúvida se seria realmente necessário.

Sua API precisa realmente mandar uma resposta no json? E ve você trata-se o 404 status code, não resolveria da mesma forma e ainda estaria nos moldes restful?

dúvidas que surgiram!

Abraços e até mais!

@fcy

This comment has been minimized.

Copy link
Owner Author

@fcy fcy commented Jan 17, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment