Skip to content

Instantly share code, notes, and snippets.

@dbarrionuevo
Created September 6, 2014 04:50
Show Gist options
  • Select an option

  • Save dbarrionuevo/7aa8e8210a68031c9950 to your computer and use it in GitHub Desktop.

Select an option

Save dbarrionuevo/7aa8e8210a68031c9950 to your computer and use it in GitHub Desktop.
# No tiene sentido hacer tan verbosa la acción, no usa bien el respond_with
def create
user = User.new(user_params)
if user.save
render json: user, status: 201, location: [:api, user]
else
render json: { errors: user.errors }, status: 422
end
end
# Se puede reescribir así! El respond_with se encarga de los status, y de devolver los errores
def create
user = User.new(user_params)
user.save
respond_with user, location: [:api, user]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment