Last active
March 15, 2016 12:27
-
-
Save hchood/fb5b01776d0819ba6ee0 to your computer and use it in GitHub Desktop.
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 characters
# 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