我试图找出如何移动用户重定向到我的Rails应用程序等的意见,但我失去了一些东西,因为它不是从我的设备加载移动视图创建Rails应用程序的移动版本
在application_controller.rb,我说:
def check_for_mobile
session[:mobile_override] = params[:mobile] if params[:mobile]
prepare_for_mobile if mobile_device?
end
def prepare_for_mobile
prepend_view_path Rails.root + 'app' + 'views_mobile'
end
def mobile_device?
if session[:mobile_override]
session[:mobile_override] == "1"
else
# Season this regexp to taste. I prefer to treat iPad as non-mobile.
(request.user_agent =~ /(iPhone|iPod|Android|webOS|Mobile)/) && (request.user_agent !~ /iPad/)
end
end
helper_method :mobile_device?
然后我有一个文件的应用程序/视图/ views_mobile /准则/ index.html.erb
当我去到索引页面上我的iPhone它不加载移动索引视图 - 我不确定我丢失了哪部分...
MIME类型有效,但会使缓存复杂化,并且如果缺少视图,它将不会优雅地回落。 –
如果你为分段缓存区块提供了正确的密钥(或者更好的是只使用正在被折叠到Rails 4中的cache_digest gem),那么我认为缓存不会是一个问题。 – jshkol
这就解决了问题,谢谢 – tessad