Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 83 lines (49 sloc) 2.426 kb
b366166 Yinghai Zhao add travis ci
authored
1 # Mobile Rails
2 [![Build Status](https://secure.travis-ci.org/hisea/mobile_rails.png)](https://secure.travis-ci.org/hisea/mobile_rails.png)
3
4
8a770bd Yinghai Zhao add readme
authored
5
f016454 Yinghai Zhao update readme
authored
6 Mobile_rails is a gem designed for integrating cross-platform mobile web application with rails application.
8a770bd Yinghai Zhao add readme
authored
7
8 What mobile_rails does:
9
10 * Adding plubming for detecting mobile device browser
11 * Setting up a mobile mime type as rails response format
12 * Adding a session variable to allow user switch between mobile and web interfaces.
13
14 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.
15
b366166 Yinghai Zhao add travis ci
authored
16 # How mobile_rails works:
17
8a770bd Yinghai Zhao add readme
authored
18
19 1 Web request stays the same.
3da0c79 Yinghai Zhao update readme
authored
20
8a770bd Yinghai Zhao add readme
authored
21 2 Mobile request comes in, mobile layout is selected and request mime format is set to .mobile.
3da0c79 Yinghai Zhao update readme
authored
22
8a770bd Yinghai Zhao add readme
authored
23 3 User gets a mobile optimized view of your app.
3da0c79 Yinghai Zhao update readme
authored
24
3bc6267 Yinghai Zhao update readme
authored
25 4 A link/action can be used to set a session variable for viewing the full web version on mobile device.
8a770bd Yinghai Zhao add readme
authored
26
b366166 Yinghai Zhao add travis ci
authored
27 # Getting Started
28
8a770bd Yinghai Zhao add readme
authored
29
30 Include the Gem
31
32 ```
33 gem 'mobile_rails'
34 ```
35
36 Run this:
37
38 ```
39 $ bundle install
40 $ rails g mobile_rails:install
41 ```
42
43 Add this in your app/controller/application_controller.rb
44
45 ```
46 has_mobile_rails
47 ```
48
7b75fdc Yinghai Zhao update readme
authored
49 Remove require_tree . from both application.js and css.js in your app/assets directory to not load mobile.js and mobile.css.
50
8a770bd Yinghai Zhao add readme
authored
51 You are almost done.
52 Next step is to choose a javascript mobile framework you like, create a mobile.mobile.haml(or .erb) layout in your app/view/layout folder.
53 Then in your controller allow respond_to mobile format and treat your mobile page like normal view but with a name like 'index.mobile.haml'. Web request will render the html version and mobile request will look for the .mobile.haml file.
54
b366166 Yinghai Zhao add travis ci
authored
55 # More Info
56
8a770bd Yinghai Zhao add readme
authored
57 * A 'mobile?' helper method is added to your controller and view to detect if the user is using a mobile devise.
58 * 'session[:mobile_session]' is used to turn on and off mobile rendering. set to '1' for on and '0' for off.
59
60 i.e.
61 If you want to give user a choice to view full web version on their mobile device:
62
63 add this to your view:
3da0c79 Yinghai Zhao update readme
authored
64
65 ```
8a770bd Yinghai Zhao add readme
authored
66 = link_to "Web Version", home_web_url, :rel => "external"
67 ```
68
69 then in your home_controller:
7b75fdc Yinghai Zhao update readme
authored
70
8a770bd Yinghai Zhao add readme
authored
71 ```ruby
72 def web
73 session[:mobile_session] = 0
74 redirect_to root_url
75 end
76 ```
77
78 If you want to use jQuery Mobile, please checkout [mobile_rails_jqm](https://github.com/hisea/mobile_rails_jqm).
79
f016454 Yinghai Zhao update readme
authored
80 Example of how this gem can be used: [mobile_rails_example](https://github.com/hisea/mobile_rails_example)
81
8a770bd Yinghai Zhao add readme
authored
82
Something went wrong with that request. Please try again.