I am learning how to style a Rails application for use on mobile devices.
The idea is widespread using one set of styles for mobile browsers and another set for traditional ones.
From what I can say, there are two main ways to do this in Rails:
Using a helper method to discover the user agent, and then provision the switch.
application_controller.rb
private def mobile? request.user_agent =~ /Mobile|webOS/ end helper_method :mobile?
application.html.erb
<% unless mobile? %> <%= stylesheet_link_tag "core" %> <%else%> <%= stylesheet_link_tag "mobile" %> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> <% end%>
Or using media queries in style sheets
body { // basic styles } @media all and (max-width: 600px) { body { // extra styles for mobile } } @media all and (min-width: 600px) { body { // extra styles for desktop } }
My question is, what is a compromise? Is one method generally better or are there good use cases for both.
Thanks in advance
Chris tosswill
source share