Repository is archived
No commit activity in last 3 years
No release in over 3 years
This Rails plugin allows for rendering special templates for mobile devices, using the existing views and partials as a fallback.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

has_mobile_views

has_mobile_views allows for rendering special versions of views and partials for mobile devices. It'll detect those devices using the browser's HTTP_USER_AGENT string. The nice thing is that it falls back to the standard views/partials if there's no dedicated mobile version available.

Installation

As a gem

Add the following line to your config/environment.rb file: config.gem 'has_mobile_views'

As a plugin

script/plugin install git://github.com/openSUSE/has_mobile_views.git

Usage

Just call the has_mobile_views class method in the ApplicationController:

class ApplicationController < ActionController::Base
  has_mobile_views
  ...
end

and create a app/mobile_views directory.

Mobile devices will then be served the views from app/mobile_views if available, e.g.

app/mobile_views/layouts/application.html.haml

will have precedence over

app/views/layouts/application.html.haml

Helpers

has_mobile_views adds a switch_view_mode_link helper which will render the appropriate link to switch to either the normal or the mobile version of your site, depending on the mode you're currently in.

TODO

  • Test/fix Rails3 support

Credits

has_mobile_views was created by Andre Duffeck and Thomas Schmidt.

Copyright (c) 2011 Andre Duffeck, released under the MIT license