Skip to content

Instantly share code, notes, and snippets.

@hchood
Last active March 15, 2016 12:27
Show Gist options
  • Save hchood/fb5b01776d0819ba6ee0 to your computer and use it in GitHub Desktop.
Save hchood/fb5b01776d0819ba6ee0 to your computer and use it in GitHub Desktop.
# app/services/sign_up_user.rb
def sign_up_user
user.tap do |user|
user.reset_token!
user.save! # raise error if validation fails
end
end
# app/controllers/v1/users_controller.rb
def create
user = SignUpUser.perform(user_params)
render json: user, serializer: AuthenticationSerializer, root: :user
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
# ...
rescue_from ActiveRecord::RecordInvalid do |exception|
render json: { errors: exception.message }, status: :unprocessable_entity
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment