`
love~ruby+rails
  • 浏览: 849444 次
  • 性别: Icon_minigender_1
  • 来自: lanzhou
社区版块
存档分类
最新评论

Mobilize Your Rails Application with Mobile Fu

阅读更多

Let's face it, iPhone interfaces are awesome, but they can only cater to a fraction of the mobile market. What are you to do if you want to satisfy the rest of the mobile world? Mobile Fu helps to make this job much easier by automatically detecting mobile devices that access your Rails application. People can access your site from a Palm, Blackberry, iPhone, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile.

Learn Mobile Fu

First off, just install the Mobile Fu plugin into your Rails application.

  1. script/plugin install git://github.com/brendanlim/mobile-fu.git   

Start by adding this one line to your ApplicationController.

  1. class ApplicationController < ActionController::Base  
  2.   has_mobile_fu  
  3. end  

Once this is in place, any request that comes from a mobile device will be be set as :mobile format. It is up to you to determine how you want to handle these requests by creating the .mobile.erb versions of your views that are to be requested. Also, I recommend that you setup a before_filter that will redirect to a specific page depending on whether or not it is a mobile request. How can you check this?

  1. is_mobile_device? # => Returns true or false depending on the device  

You can also determine which format is currently set in by calling the method below.

  1. in_mobile_view? # => Returns true or false depending on current req. format  

If you want the ability to allow a user to switch between ‘mobile’ and ‘standard’ format (:html), you can just adjust the mobile_view session variable in a custom controller action.

  1. session[:mobile_view# => Set to true if request format is :mobile and false  
  2.                            if set to :html  

What About Custom Mobile Styling?

Different devices need different styling. Don’t worry though, we’ve got this baked in to Mobile Fu (thanks to Intridea's own Michael Bleigh, who created Browserized Styles for letting me modify his code). If you are including a css or sass file via stylesheet_link_tag, all you have to do is add _device to the name of one of your files to override your styling for a certain device. The stylesheet that is loaded is dependant on which device is making the request.

Supported stylesheet override device extensions at the moment are: blackberry, iphone, mobileexplorer, nokia, palm

  1. e.g., Accessing a page from a Blackberry.  
  2.   
  3.     
  4.   
  5. Ends up loading mobile.css, and mobile_blackberry.css if the file exists. 

分享到:
评论

相关推荐

    jQuery Mobile中文手册

    jQuery Mobile是专为移动web应用程序开发设计的框架。它具备跨平台的特性,意味着它可以在多种流行的智能手机和平板电脑上使用。利用HTML5和CSS3进行页面布局,jQuery Mobile通过最少的脚本实现了对移动设备的完美...

    Breaking the wireless barriers to mobilize 5G NR mmWave.pdf

    首先,【标题】中提到的“Breaking the wireless barriers to mobilize 5G NR mmWave.pdf”表明这份文件可能涉及如何通过解决无线通信中的难题来推进5G NR(New Radio,新无线)的毫米波技术。毫米波是5G技术的关键...

    jquery mobile 1.3中文API

    通过mobilize()函数,jQuery Mobile能够自动初始化页面上的所有jQuery部件。 ##### 7.6 无障碍支持 jQuery Mobile包括了WAI-ARIA无障碍支持,确保应用可以被诸如VoiceOver等语音辅助程序正常使用。 ##### 7.7 ...

    前端项目-mobilizejs.zip

    在移动互联网飞速发展的今天,优化网站的移动端体验变得至关重要,Mobilize.js就是为了满足这一需求而诞生的。 Mobilize.js的核心在于提供了一套简洁而强大的API,它能够自动检测用户访问设备的类型,并根据不同的...

    jQuery_Mobile中文手册

    ### jQuery Mobile 中文手册:开发入门 #### 概述 jQuery Mobile是一款强大的移动Web应用开发框架,它以“Write Less, Do More”为设计理念,旨在为开发者提供一套跨平台的移动Web应用解决方案。该框架支持多种...

    jQuery_Mobile中文手册.pdf

    ### jQuery Mobile 中文手册知识点概览 #### 一、概述 **jQuery Mobile** 是一个用于构建适应各种智能手机和平板电脑的高性能移动Web应用程序的开源框架。它基于jQuery库,为开发者提供了一种简单的方式来创建优雅...

    jQuery_Mobile中文API手册.pdf

    ### jQuery Mobile 中文 API 手册关键知识点解析 #### 概述 《jQuery Mobile中文API手册》是一份针对前端开发者的重要资源,它介绍了如何利用jQuery Mobile框架构建高性能、跨平台的移动Web应用。该手册发布于2011...

    jQuery+Mobile中文手册

    ### jQuery Mobile 中文手册知识点概览 #### 概述 jQuery Mobile是一款专为移动设备设计的用户界面框架,旨在提供跨平台的Web应用程序开发能力。它以“Write Less, Do More”为理念,实现了高度统一的UI设计,适用...

    ( jQuery_Mobile中文手册.pdf

    ### jQuery Mobile 开发入门知识点详解 #### 概述 jQuery Mobile 是一款用于构建适用于各种智能手机和平板电脑的 Web 应用程序的用户界面框架。它以其简洁高效的代码库著称,能够实现高度统一且品牌化的 Web 应用...

    Web.Service.APIs.and.Libraries.083891182X

    Application Programming Interfaces (APIs) are software tools that help different programs work together, and Michel shows readers how to integrate these into existing library websites as well as use ...

    Mobilize 360 Ranking-crx插件

    网站排名 找出您的网站如何免费获得Google评分! 支持语言:English

    Web Scraping in Python - Datacamp

    来自datacamp的Web Scraping in Pytho的第三章节: Learn CSS Locator syntax and begin playing with the idea of chaining together CSS Locators with XPath. We also introduce Response objects, which behave ...

    A game theory mechanism for thermal power plant to participate in wind power heating in electricity markets

    It is of great significance to mobilize the potential peak regulation capacity of thermal power plant, and to promote wind power clean heating and accommodation. For the wind power heating scheme ...

    code_library:对我们的技术堆栈有用SQL脚本,包括

    4. **Mobilize** - 在数据库上下文中,"Mobilize"可能指的是移动数据或使数据可以在不同设备之间流动。这可能涉及到移动应用的数据同步,或者在云端和本地存储之间迁移数据的策略。 这些脚本可能都是用JavaScript...

    动员自动注册:自动将联系人的TSV回复到动员美国事件

    自动将联系人的TSV(即来自EveryAction)的RSVP回复到Mobilize America事件。 使用PostgreSQL数据库存储与RSVP的联系人列表的队列。 Heroku设置 该设置将托管在Heroku上。 您可以使用下面的按钮进行部署,或者查看...

Global site tag (gtag.js) - Google Analytics