0

我的一个小问题是让我的用户代理检测工作。每当我尝试它在生产它不工作..我有这个在我的应用程序控制器如何使用rails自动检测用户代理

before_filter :prepare_for_mobile 

private 

def mobile_device? 
    if session[:mobile_param] 
    session[:mobile_param] == "1" 
    else 
    request.user_agent =~ /Mobile|webOS/ 
    end 
end 
helper_method :mobile_device? 

def prepare_for_mobile 
    session[:mobile_param] = params[:mobile] if params[:mobile] 
    request.format = :mobile if mobile_device? 
end 

但是当我在生产模式下,它不工作..所以我也想知道如何设置黑莓Andriod,iphone,nokias3,bada和windows操作系统的用户代理。谢谢

回答

0

你可以发布你的config/environments/production.rb文件的副本吗?

侧面说明: 你可能要添加这样的事情,如果你不想要打破XML或JSON输出,(与responds_to块):

def prepare_for_mobile 
    if request.format == 'text/html' 
    session[:mobile_param] = params[:mobile] if params[:mobile] 
    request.format = :mobile if mobile_device? 
    end 
end