Skip to content

Instantly share code, notes, and snippets.

@sonianand11
Last active March 4, 2016 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonianand11/633e0bf11081e8e8bb3e to your computer and use it in GitHub Desktop.
Save sonianand11/633e0bf11081e8e8bb3e to your computer and use it in GitHub Desktop.
#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