I have searched everywhere on this, but all that I could find are tutorials on "How To Sign In Your Users With Ajax Using Devise". What I want instead is the way on "How to properly update users with ajax using Devise".
So far, I already manage to update the users successfully via Ajax. But, if there are errors, those errors won't be showing. And this is where I need helps.
Here is how the form looks like right now:
And here are the files associated with this devise forms:
views/devise/registrations/edit.html.erb:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }, remote: true) do |f| %>
<%= devise_error_messages! %>
<% if @user.provider.blank? %>
<div class="row row-condensed space-4">
<label class="col-sm-3" for="user_first_name">
Current Password
</label>
<div class="col-sm-9 form-group">
<%= f.password_field :password, autocomplete: "off", class: "form-control" %>
</div>
</div>
<div class="row row-condensed space-4">
<label class="col-sm-3" for="user_first_name">
New Password
</label>
<div class="col-sm-9 form-group">
<%= f.password_field :password, autocomplete: "off", :class => "form-control", :required => true %>
</div>
</div>
<div class="row row-condensed space-4">
<label class="col-sm-3" for="user_first_name">
Re-type Password
</label>
<div class="col-sm-9 form-group">
<%= f.password_field :password_confirmation, autocomplete: "off", :class => "form-control", :required => true %>
</div>
</div>
<div class="actions">
<%= f.submit "Update", class: "btn btn-primary btn-md" %>
</div>
<% end %>
<% end %>
controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def create
super
end
def update
# For Rails 4
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# required for settings form to submit when password is left blank
if account_update_params[:password].blank?
account_update_params.delete("password")
account_update_params.delete("password_confirmation")
end
@user = User.find(current_user.id)
if @user.update_attributes(account_update_params)
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to edit_user_registration_path, notice: 'Your details was successfully updated.'
else
render "edit"
end
end
end
So my question is how could i modify these so that the flash message will be showing like the picture below via AJAX?