Skip to content

Instantly share code, notes, and snippets.

@TranBaVinhSon
Created March 4, 2018 07:55
Show Gist options
  • Save TranBaVinhSon/fe0b59768e312eb74ca630de655df1f5 to your computer and use it in GitHub Desktop.
Save TranBaVinhSon/fe0b59768e312eb74ca630de655df1f5 to your computer and use it in GitHub Desktop.
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