1 2 3 4 5 6 7 |
$('#submit-btn').on('click', function () { if ($('#new_user')[0].checkValidity()) { $('#new_user').submit(); $('.status-error').remove(); $('.add-error').removeClass('has-error'); } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$('form#new_user').bind('ajax:success', () => { animationSignUpForm(); setTimeout(() => window.location.replace('/'), 2000); }); $('form#new_user').bind('ajax:error', (evt, xhr) => { $('form#new_user').prepend( '<div class="alert alert-danger status-error">Please review the problems below:</div>', ); $('.form-group.email.user_email'); var errors = xhr.responseJSON.errors; for (key in errors) { var array = errors[key]; var element = `.form-group.${key}.user_${key}`; $(element).addClass('add-error has-error'); array.forEach(function(item){ $(element).append(`<span class="help-block status-error">${item}</span>`); }); } }); |
app/controllers/users/registrations_controller.rb
1 2 |
class Users::RegistrationsController < Devise::RegistrationsController respond_to :html, :json |
app/views/users/registrations/_sign_up.html.erb
1 2 3 |
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), remote: true, data: { type: :json }) do |f| %> |