How can I get the devise error messages in a pop up
I am using jquery to load the signup form of devise as a popup. The problem is the I am not able to load the error messages of the devise in the popup.
If I click on the empty signup form I am redirected to the another page where I see the error message.
I have gone through the github posts of devise but could not find the solution which I am looking for.
I have created a method in the application helper so that the <%= devise_error_messages! %>
code in the form helper works properly.
The application helper code is as follows :-
def devise_error_messages!
resource.errors.full_messages.map { |msg| content_tag(:li, ms开发者_开发百科g) }.join
end
I know that something is wrong with this but cannot figure out what. Can anyone please help me out with this one.
UPDATE
I think that since the errors are not showing in the pop up box when I hit the submit button, there might be an issue with the registration controller's create action. Will try to override the default create action of the registration controller of devise. Lets see if it works with these change.
UPDATE 2
Made the changes which I mentioned in the update above although it is not working it gives a feeler that I am very close to the solution :)
Still waiting for some help.
Thanks,
Are you overriding the create action of the RegistrationsController? That should do the trick if resource.save fails you could just
render :json => { :success => false, :data => resource.errors.full_messages }
that should hand just the error messages back to your jquery script. For example:
$('#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');
});
精彩评论