Skip to content

Instantly share code, notes, and snippets.

@sebyx07
Last active August 29, 2015 14:03
Show Gist options
  • Save sebyx07/c7a6ef2d3e0431521876 to your computer and use it in GitHub Desktop.
Save sebyx07/c7a6ef2d3e0431521876 to your computer and use it in GitHub Desktop.
def render_error(options={})
errors = options[:error] || ''
message = options[:message] || ''
action = options[:action] || ''
render json: {errors:{ errors: errors, message: message, action: action}}, status: 422
end
def render_success(options={})
action = options[:action] || ''
render json: {action: action}
end
def require_login
unless signed_in?
render_error(message: 'not logged in')
end
end
#error response: {"errors":{"errors":"","message":"not logged in","action":""}}
#success response: {"action":"created"}
@fivetwentysix
Copy link

looks good

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