Jquery Mobile Rails&使用不正确的凭据登录时设计错误加载页面 [英] Jquery Mobile Rails & Devise Error loading page when logging in with incorrect credentials

查看:101
本文介绍了Jquery Mobile Rails&使用不正确的凭据登录时设计错误加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在掌握Rails 3,并制作了几个有用的应用程序。我是新手使用javascript或jquery与rails。我有一个工作的应用程序与rails 3.2,设计和cancan。然后我将其转换为使用Jquery Mobile。整个应用程序正在使用它,我没有区分桌面和移动。

I am getting the hang of Rails 3 and have made a couple of working apps. I am new to using javascript or jquery with rails. I have a working app with rails 3.2, devise and cancan. I then converted it to use Jquery Mobile. The whole app is using it, I made no distinction between desktop and mobile.

问题:

总的来说,一切都很好,除了一些小的的东西。一个是我可以使用正确的凭据成功登录,一旦登录闪存将显示我已登录。如果我使用不正确的凭据登录它只显示错误加载页面 (没有像正常的flash消息说无效的电子邮件或密码)。据我所知,所有其他flash消息都正确显示(黄色由JQM格式化)。

In general everything is working fine except for a few small things. One is that I can login successfully with correct credentials and once logged in the flash will display that I am signed in. If I login with incorrect credentials it just displays a Error loading page (no flash message like normal to say Invalid email or password). All other flash messages is displaying correctly as far as I can see (yellow formatted by JQM).

到目前为止我做了什么:

搜索类似的高低问题但没有快乐(最相似的是重定向或页面未找到错误)。
在Firebug中显示<​​code> 401 Unauthorized - Response - 无效的电子邮件或密码。

Searched high and low for similar problems but no joy (most similar are redirect or page not found errors). In Firebug it show 401 Unauthorized - Response - Invalid email or password.

我已经注释掉了所有的cancan东西(它们都在没有JQM的情况下工作) - 这没有任何区别 - 并不是它会重定向到其他地方没有许可等。

I have commented out all cancan stuff (it is all working without the JQM) - and that makes no difference - it is not that it is redirecting somewhere else where there are no permission ect.

我不熟悉javascript / ajax如何改变正常的rails行为,但任何指针都会受到赞赏。

I am not that familiar with how javascript/ajax changes normal rails behavior but any pointers would be appreciated.

推荐答案

简答



解决此问题的最快方法是使用 rails g devise :views 将设计视图复制到项目中,以便编辑它们。然后,您需要在<$ c $中:url 之后的 form_for 行中添加以下内容c> new.html 会话控制器的模板:

Short Answer

The quickest way to solve this is to use rails g devise:views to copy the views for devise into your project so you can edit them. Then you'll want to add the following to the form_for line right after the :url in the new.html template for the session controller:

:html => {:data => {:ajax => 'false'}}

这将告诉jQuery Mobile这个表单不应该被劫持并制成一个ajax请求。

This will tell jQuery Mobile that this form should not be hijacked and made into an ajax request.

jQuery Mobile将劫持所有表单和链接,将其转换为ajax请求。除非您在控制器中设置 respond_to 块,否则Rails仍将呈现您设置的任何模板。这通常不是问题,因为jQM只是解析必要的页面div。但是,Devise的控制器根据请求做出不同的响应,并且您正在接收jQM不知道如何处理的ajax响应。这就是为什么上面最简单的解决方案是让jQM不将登录表单转换为ajax请求。其他可能的解决方案包括修改会话控制器或添加代码默认的ajax成功处理程序,以检查非状态200返回响应并正确处理它们。

jQuery Mobile will hijack all forms and links to turn them into ajax requests. Unless you setup a respond_to block in your controllers Rails will still render whatever template you have set. This normally isn't a problem as jQM just parses out the necessary page div. However, Devise's controllers will respond differently based on the request and you are receiving an ajax response that jQM doesn't know how to handle. This is why the easiest solution above is to make jQM not turn the signin form into an ajax request. Other potential solutions include modifying the session controller or adding code a default the ajax success handler to check for non status 200 returning responses and handle them appropriately.

这篇关于Jquery Mobile Rails&amp;使用不正确的凭据登录时设计错误加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆