Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mobile-fu

> 编程语言
Open source

Automatically detect mobile requests from mobile devices in your Rails application.

699 stars0 likes2 views
WebsiteGitHub

About

Automatically detect mobile requests from mobile devices in your Rails application.

= Mobile Fu

Want to automatically detect mobile devices that access your Rails application? Mobile Fu allows you to do just that. People can access your site from a Palm, Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile.

== Rails 3 Compatibility

The master branch of this plugin is Rails 3 compatible.

To use the Rails 3 compatible version of this plugin, please install it like so:

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

== Rails 2 Compatibility

You will need to install this plugin from the 2.x branch.

To use the Rails 2 compatible version of this plugin, please install it like so:

script/plugin install git://github.com/brendanlim/mobile-fu.git -r 2.x

== Usage

Add this this one line to the controller.

class ApplicationController  Returns true or false depending on the device

You can also determine which format is currently set in by calling the following:

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

Also, 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.

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

So, different devices need different styling. Don't worry, we've got this baked in to Mobile Fu.

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.

e.g., Accessing a page from a Blackberry.

... stylesheet_link_tag 'mobile.css' ...

This loads mobile.css, and mobile_blackberry.css if the file exists.

Supported stylesheet override device extensions at the moment are:

blackberry iphone (iphone,ipod) ipad android mobileexplorer nokia palm

The stylesheet awesomeness was derived from Michael Bleigh's browserized styles: http://www.intridea.com/2007/12/9/announcing-browserized-styles

Inspiration for Mobile Fu came from Noel Rappin's rails_iui: http://blogs.pathf.com/agileajax/2008/05/rails-developme.html

Hopefully this should help you create some awesome mobile applications.

== Testing Mobile Interface

If you want to force the mobile interface for testing, you can either use a mobile device emulator, or you can pass 'true' to has_mobile_fu.

class ApplicationController < ActionController::Base has_mobile_fu(true) end

Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言