How can I get development error messages?

I am using jquery to load the registration form as a popup. The problem is that I cannot load error messages in a popup.

If I am in an empty registration form, I am redirected to another page where I see an error message.

I looked through github posts but couldn't find the solution I'm looking for.

I created a method in the application helper, so the code is <%= devise_error_messages! %> <%= devise_error_messages! %> in the form helper works correctly.

The auxiliary application code is as follows: -

  def devise_error_messages! resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join end 

I know that something is wrong with this, but I can’t understand what. Can someone please help me with this.

UPDATE

I think that since errors do not appear in the popup when I click the submit button, there may be a problem creating the registration controller action. Attempts to override the default action for the registration controller for development. Let's see if this works with these changes.

UPDATE 2

Made the changes that I mentioned in the above update, although it does not work, it gives the feeling that I am very close to the solution :)

Still waiting for some help.

Thanks,

+4
source share
1 answer

Are you overriding the create RegistrationsController action? This should do the trick if resource.save fails, just

 render :json => { :success => false, :data => resource.errors.full_messages } 

which should only pass error messages back to your jquery script. For instance:

 $('#sign_up_form').submit(function() { $.post(this.action, function(response) { if (response.success) { //... do a redirect or something cuz we're now registered } else { // do something with your errors $('#sign_up_form').prepend(response.data); } }, 'json'); }); 
+3
source

All Articles