-
-
Save fcy/1608422 to your computer and use it in GitHub Desktop.
Revisions
-
fcy revised this gist
Jan 13, 2012 . 1 changed file with 17 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,24 @@ # 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 revised this gist
Jan 13, 2012 . 1 changed file with 5 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,9 @@ class OperationsController < ApplicationController respond_to :json def create app = App.find_by_app_key!(params[:app_key]) #aqui retorna um 404 operation = app.new_operation(params[:operation]) operation.save respond_with operation end end -
rodrigopinto created this gist
Jan 13, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ class OperationsController < ApplicationController def create app = App.find_by_app_key(params[:app_key]) if !app.nil? operation = app.new_operation(params[:operation]) if operation.save respond_to do |format| format.json { render json: operation, status: :created } end else respond_to do |format| format.json { render json: {errors: operation.errors}, status: :bad_request } end end else error = { request: request.path, message: 'No app found for that app_key' } respond_to do |format| format.json { render json: {error: error}, status: :not_found } end end end end