Skip to content

Instantly share code, notes, and snippets.

@jetrubyshared
Last active July 20, 2016 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jetrubyshared/0a29858da4ff3d68d78612253abab5ce to your computer and use it in GitHub Desktop.
Save jetrubyshared/0a29858da4ff3d68d78612253abab5ce to your computer and use it in GitHub Desktop.
###############
## WRONG ##
###############
class API::ArticlesController
def create
article = Article.new(article_params)
if article.save
render json: article
else
render json: { errors: article.errors.full_messages }
end
end
end
###############
## RIGHT ##
###############
class API::ArticlesController
def create
article = Article.new(article_params)
if article.save
render json: article, status: 201
else
render json: { errors: article.errors.full_messages }, status: 422
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment