如何在弹出窗口中获取设备错误消息

发布于 2024-12-08 12:49:03 字数 683 浏览 0 评论 0原文

我正在使用 jquery 将 devise 的注册表单作为弹出窗口加载。问题是我无法在弹出窗口中加载设备的错误消息。

如果我单击空注册表单,我将被重定向到另一个页面,在其中看到错误消息。

我已经浏览了 devise 的 github 帖子,但找不到我正在寻找的解决方案。

我在应用程序帮助程序中创建了一个方法,以便 <%= devise_error_messages! %> 表单助手中的代码工作正常。

应用程序帮助程序代码如下:-

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

我知道这有问题,但无法弄清楚是什么。谁能帮我解决这个问题吗?

更新

我认为,由于当我点击提交按钮时弹出框中没有显示错误,因此注册控制器的创建操作可能存在问题。将尝试覆盖设备注册控制器的默认创建操作。让我们看看它是否适用于这些更改。

更新2

进行了我在上面的更新中提到的更改,尽管它不起作用,但它给人一种感觉,我非常接近解决方案:)

仍在等待一些帮助。

谢谢,

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, msg) }.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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小墨 2024-12-15 12:49:03

您是否覆盖 RegistrationsController 的创建操作?如果resource.save失败,那应该可以解决问题,你可以

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

只将错误消息返回给你的jquery脚本。例如:

$('#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'); 
});

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'); 
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文