Check out Rails Mobile
I developed this plugin a while ago. The idea of โโthis plugin is that you can redirect to different controllers or views based on the capabilities of your mobile device through the configuration file of the router.
At the end of routing.rb, add the following lines:
MobileDispatch::Categories.add do def mobile_classifier(device) "_mobile" end end
These lines define a new substring for all mobile devices that will be stored in the $ variable for each request in the rouging.rb file.
This way you can play with routing rules. For example, this line in routing.rb:
match '/ photo /: id' ,: to => "photo # index $" ,: classifier =>: mobile_classifier
for a regular user will be interpreted as:
match '/ photo /: id' ,: to => "photo # index" ,: classifier =>: mobile_classifier
and for the mobile user:
match '/ photo /: id' ,: to => "photo # index_mobile" ,: classifier =>: mobile_classifier
The strength here is in the mobile_classifier (device) method, where you can return a different classification based on the device object.
so let's say we modify the method to return "_iphone" for all iphone devices and "_android" for all Android mobile phones, then the specified routing line will be interpreted as:
match '/ photo /: id',: to => "photo # index_iphone" ,: classifier =>: mobile_classifier
match '/ photo /: id' ,: to => "photo # index_android" ,: classifier =>: mobile_classifier
If you add $ to the end of the overview section of each route (similar to what we did here), you will get different methods in your controller for each device category and different name names for each method (index_iphone.htm. Erb and index_android.ht.erb ) Thus, you have separate views / levels for each category of devices that you defined in your mobile_classifier method.