Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supporting Mobile Devices in Ruby on Rails

What is the best way to develop a rails application that has special views for different mobile devices? Basically I'm looking for something like this ASP.NET MVC solution: http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx

like image 347
Eran Kampf Avatar asked Jul 21 '09 16:07

Eran Kampf


3 Answers

You might be looking for mobile_fu. It's a plugin that automatically changes the Rails format from :html to :mobile for Nokia, Blackberry, iPhone and Palm users. You can then just provide an {action}.mobile.erb to complement {action}.html.erb and it will render the mobile view. If you need something more fine-grained, it allows you to do:

is_mobile_device?

and there's various other helper methods

like image 67
ideasasylum Avatar answered Nov 04 '22 03:11

ideasasylum


Two articles that use the iPhone as an example of serving up a different view based on a mobile sub-domain or a by detecting the user-agent. Essentially you'll create a different view using something like viewname.iphone.erb or viewname.mobile.erb and set the request.format variable to iphone or mobile respectively.

iPhone subdomains with Rails

iPhone on Rails - Creating an iPhone optimised version of your Rails site using iUI and Rails 2

like image 13
Michael Glenn Avatar answered Nov 04 '22 03:11

Michael Glenn


I found this railscast extremely helpful for this situation: http://railscasts.com/episodes/199-mobile-devices

Hope it helps somebody out.

like image 6
Gowiem Avatar answered Nov 04 '22 02:11

Gowiem