Ruby on rails 为rails应用程序实现移动视图

Ruby on rails 为rails应用程序实现移动视图,ruby-on-rails,jquery-mobile,Ruby On Rails,Jquery Mobile,我想设置一种方式,当手机使用我的网站时,它将被重定向到带有“m”子域的url,但我将使用相同的控制器,但只是不同的视图。我只需要一个如何实现类似功能的一般路线图。为此,您需要在应用程序控制器中添加一个before过滤器,如 before_filter :detect_mobile_device #Checking against the user agent def detect_mobile_device if request.user_agent =~ /Mobile|

我想设置一种方式,当手机使用我的网站时,它将被重定向到带有“m”子域的url,但我将使用相同的控制器,但只是不同的视图。我只需要一个如何实现类似功能的一般路线图。

为此,您需要在应用程序控制器中添加一个before过滤器,如

before_filter :detect_mobile_device

#Checking against the user agent
def detect_mobile_device       
   if request.user_agent =~ /Mobile|webOS/
     redirect_to m.****.com
   end
end   
然后,您可以修改并利用它来渲染不同的视图,也可以使用

 def is_mobile_device?   
   return request.user_agent =~ /Mobile|webOS/
 end 
对于某些浏览器,它可能无法工作,因此您可以使用此gem

gem 'mobile-fu' 
也许有用。