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.
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.
Include the Gem
$ 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.
- 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 end
If you want to use jQuery Mobile, please checkout mobile_rails_jqm.
Example of how this gem can be used: mobile_rails_example