Ruby on rails 移动错误的Ruby on Rails mime类型
我正在尝试检测带有Rails的移动设备。当我尝试访问索引页时,出现以下错误:Ruby on rails 移动错误的Ruby on Rails mime类型,ruby-on-rails,mobile,Ruby On Rails,Mobile,我正在尝试检测带有Rails的移动设备。当我尝试访问索引页时,出现以下错误:未初始化常量Mime::MOBILE mime_types.rb: Mime::Type.register_alias "text/html", :mobile 应用程序\u controller.rb class ApplicationController < ActionController::Base protect_from_forgery private def mobile_device?
未初始化常量Mime::MOBILE
mime_types.rb:
Mime::Type.register_alias "text/html", :mobile
应用程序\u controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
private
def mobile_device?
if request.user_agent =~ /Mobile|webOS/
request.format = :mobile
return true
end
end
helper_method :mobile_device?
end
class ApplicationController
我还创建了index.mobile.erb文件,以便将用户重定向到此格式。您必须确保在将别名添加到
mime\u types.rb之前启动了rails服务器。通常情况下,一个用于立即查看开发环境的更改,但在本例中,更改是在初始化过程中进行的。我无法在Rails 3.2上重现错误。您使用的是哪个版本?我更新到Rails 3.2.0。我还更新了我的一些宝石。它现在的工作方式应该是这样的。谢谢!你知道是什么导致了这个错误吗?不,很遗憾我不知道。我在发行说明中没有看到任何关于mime类型的内容。可能只是一个被修复的突出错误:)