I’m looking to do some mobile-specific layouts in my app, and have been researching ways to detect mobile browsers and serve mobile specific layouts.
I came across this: http://www.arctickiwi.com/blog/mobile-enable-your-ruby-on-rails-site-for-small-screens
But using an array of keywords seems a little fragile to me. What if the keywords change? Anyone come across any gems or plugins or any more future proof strategies?
There is actually a much simpler regular expression you can use. The approach is outlined in this Railscast and allows you to load different JS and define different page interactions for mobile devices.
Essentially you end up with a function that simply checks that the user-agent contains ‘Mobile’ or ‘webOS’: