Skip to main content
 首页 » 编程设计

ruby-on-rails之设计 jQuery Mobile 和 Rails 的登录问题

2025年12月25日33shanyou

我正在尝试让设计登录,但由于缺少模板,我收到了 500 错误。任何的想法?为什么它试图渲染 devise/sessions/create ?

rails 3.1

我正在使用 mobylette gem:https://github.com/tscolari/mobylette
我的设计配置为:
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]Completed 500 Internal Server Error in 145msActionView::MissingTemplate (Missing template devise/sessions/create, application/create with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:mobile], :locale=>[:en, :en]}. Searched in: * "/Users/Armageddon/Projects/Business/jquerymobiletest/app/views" * "/Users/Armageddon/.rvm/gems/ruby-1.9.2-p180-patched@jquerymobiletest/gems/devise-1.4.9/app/views"): Rendered /Users/Armageddon/.rvm/gems/ruby-1.9.2-p180-patched@jquerymobiletest/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.5ms)

请您参考如下方法:

我必须进行以下更改才能使这项工作:

配置/初始化程序/devise.rb
config.http_authenticatable_on_xhr = false必须将其设为 false,否则 jQuery mobile 会发送 XHR 请求进行登录,并且您会收到 401 错误。
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
否则它不会识别格式。您会认为这会处理重定向,但实际上不会。你还需要做一件事。

这对我来说很糟糕,所以我将它添加到:
配置/初始化程序/devise_hack.rb
ActionController::Responder.class_eval do alias :to_mobile :to_html end
现在它起作用了。

还有一件事;在我的 application.rb 中,我有这个用于 mobylette 来设置我的移动设备:
respond_to_mobile_requests :skip_xhr_requests => false, :fall_back => :html Responder.class_eval之间和 :fall_back => :html你会认为这些没有必要。许多编写的配置似乎是同一件事或重复。但是,如果没有所有这些设置,它就不起作用。