Skip to content
A Ruby gem enables easy creation of a mobile supported rails app.
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Mobile Rails

Build Status

Mobile_rails is a gem designed for integrating cross-platform mobile web application with rails application.

What mobile_rails does:

  • Adding plubming for detecting mobile device browser
  • Setting up a mobile mime type as rails response format
  • Adding a session variable to allow user switch between mobile and web interfaces.

Mobile_rails can be used with mobile_rails_jqm which is a gem packaged jQuery Mobile 1.0 final with a mobile_rails layout generator.

How mobile_rails works:

1 Web request stays the same.

2 Mobile request comes in, mobile layout is selected and request mime format is set to .mobile.

3 User gets a mobile optimized view of your app.

4 A link/action can be used to set a session variable for viewing the full web version on mobile device.

Getting Started

Include the Gem

gem 'mobile_rails'

Run this:

$ bundle install
$ rails g mobile_rails:install

Add this in your app/controller/application_controller.rb


Remove require_tree . from both application.js and css.js in your app/assets directory to not load mobile.js and mobile.css.

You are almost done. Next step is to choose a javascript mobile framework you like, create a .erb) layout in your app/view/layout folder. Then in your controller allow respond_to mobile format and treat your mobile page like normal view but with a name like ''. Web request will render the html version and mobile request will look for the .mobile.haml file.

More Info

  • A 'mobile?' helper method is added to your controller and view to detect if the user is using a mobile devise.
  • 'session[:mobile_session]' is used to turn on and off mobile rendering. set to '1' for on and '0' for off.

i.e. If you want to give user a choice to view full web version on their mobile device:

add this to your view:

= link_to "Web Version", home_web_url, :rel => "external"

then in your home_controller:

  def web
    session[:mobile_session] = 0
    redirect_to root_url

If you want to use jQuery Mobile, please checkout mobile_rails_jqm.

Example of how this gem can be used: mobile_rails_example

Something went wrong with that request. Please try again.