【发布时间】:2015-03-05 20:49:47
【问题描述】:
我的应用程序控制器中有这个:
class ApplicationController < ActionController::Base
helper_method :mobile_device?
before_filter :prepare_for_mobile
private
def mobile_device?
request.user_agent=~ /Mobile|webOS/
end
def prepare_for_mobile
request.format = :mobile if mobile_device?
end
end
我正在关注这个 railscast 视频:http://railscasts.com/episodes/199-mobile-devices
问题是: 当我第一次加载页面时,它会检测到移动浏览器并以 MOBILE 格式获取请求。但是,如果我转到我网站上的任何其他页面,它会呈现 HTML 格式而不是 MOBILE。如果我重新加载页面,它会再次检测到格式为 MOBILE。
这里有什么问题?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 before-filter