Last active
March 4, 2016 14:57
-
-
Save sonianand11/633e0bf11081e8e8bb3e 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
#View original : https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb | |
class Users::RegistrationsController < Devise::RegistrationsController | |
respond_to :json | |
# POST /resource | |
def create | |
build_resource(sign_up_params) | |
resource.save | |
yield resource if block_given? | |
if resource.persisted? | |
if resource.active_for_authentication? | |
set_flash_message :notice, :signed_up if is_flashing_format? | |
#find_message is devise method. We used for json response | |
msg = find_message(:signed_up, {}) | |
sign_up(resource_name, resource) | |
respond_with(resource) do |format| | |
format.json { render json: {url: after_sign_up_path_for(resource)}, status: 200 } | |
end | |
else | |
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? | |
#find_message is devise method. We used for json response | |
msg = find_message(:"signed_up_but_#{resource.inactive_message}", {}) | |
expire_data_after_sign_in! | |
respond_with(resource) do |format| | |
format.json { render json: {message: msg,url: after_inactive_sign_up_path_for(resource)}, status: 200 } | |
end | |
end | |
else | |
clean_up_passwords resource | |
#passing block to handle error in signup for json | |
#http://edgeapi.rubyonrails.org/classes/ActionController/Responder.html | |
respond_with(resource) do |format| | |
msg = resource.errors.full_messages.join("<br>").html_safe | |
format.json { render json: {message: msg}, status: 401 } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment