Skip to content

Instantly share code, notes, and snippets.

@fcy
Forked from rodrigopinto/refactory.rb
Created January 13, 2012 20:03
Show Gist options
  • Select an option

  • Save fcy/1608422 to your computer and use it in GitHub Desktop.

Select an option

Save fcy/1608422 to your computer and use it in GitHub Desktop.
# 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
Copy link
Copy Markdown

@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
Copy link
Copy Markdown
Author

fcy commented Jan 17, 2012 via email

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