Created
March 4, 2018 07:55
-
-
Save TranBaVinhSon/fe0b59768e312eb74ca630de655df1f5 to your computer and use it in GitHub Desktop.
This file contains 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
class Api::V1::RegistrationsController < Devise::RegistrationsController | |
before_action :ensure_params_exist, only: :create | |
# sign up | |
def create | |
user = User.new user_params | |
if user.save | |
render json: { | |
messages: "Sign Up Successfully", | |
is_success: true, | |
data: {user: user} | |
}, status: :ok | |
else | |
render json: { | |
messages: "Sign Up Failded", | |
is_success: false, | |
data: {} | |
}, status: :unprocessable_entity | |
end | |
end | |
private | |
def user_params | |
params.require(:user).permit(:email, :password, :password_confirmation) | |
end | |
def ensure_params_exist | |
return if params[:user].present? | |
render json: { | |
messages: "Missing Params", | |
is_success: false, | |
data: {} | |
}, status: :bad_request | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment