在应用中使用(Gemfile):
gem "devise", ">= 2.1.2"
gem 'rails', '3.2.8'
gem 'jquery_mobile_rails'
在添加jquery-mobile之前,一切正常,当输入invalidad数据时,我得到了带有错误消息和日志的页面:
Started POST "/users/sign_in" for 127.0.0.1 at 2012-11-28 12:01:13 -0500
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"jLtHS2q0wO+tgswm9VM2/EiuTiq7J9Wwp8d65t/RSGE=", "user"=>{"email"=>"", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 0ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"jLtHS2q0wO+tgswm9VM2/EiuTiq7J9Wwp8d65t/RSGE=", "user"=>{"email"=>"", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/shared/_links.html.erb (0.8ms)
Rendered devise/sessions/new.html.erb within layouts/application (3.2ms)
Rendered layouts/_navigation.html.erb (0.5ms)
Rendered layouts/_messages.html.erb (0.0ms)
Completed 200 OK in 29ms (Views: 28.9ms)
添加jquery-mobile后,当使用正确的数据登录工作正常,但是使用无效数据时我得到401并且不会重定向注意。在http响应中(使用firebug查看)只显示错误消息,如“无效电子邮件”(不是html代码,也不是json)和jquery-mobile显示“错误加载页面”。
Started POST "/users/sign_in" for 127.0.0.1 at 2012-11-27 21:32:45 -0500
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EYx56pui4v6trcuzmXQuhzY2BDHwqrADepKuySx9ub0=", "user"=>{"email"=>"test@test.net", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 0ms
我有默认的设计控制器和生成的默认视图。
如何使用jquery mobile处理设计错误消息?
答案 0 :(得分:1)
只有不使用jjery-mobile的ajax并默认设计。
在config/initializers/devise.rb
# If http headers should be returned for AJAX requests. True by default.
config.http_authenticatable_on_xhr = false
答案 1 :(得分:0)
另一种解决方案是添加
:html => {:data => {:ajax => 'false'}}
指向相关表单,以便jQM不会劫持它并将其转换为ajax请求。
相同问题的完整答案