Logic in views and controllers based on mobile or desktop visitor

Hi! I’m currently improving my site to be fully responsive and using media queries is a great help to change the styling for different screen sizes. But what if you want to make bigger differences in what you show to a mobile or desktop visitor? Is there a good way to do this in views and controllers? Something like:

if mobile_user?
  show something
else
  show something different
end

Hi @jarkelen,

Have a look at GitHub - tscolari/mobylette: Mobile request handling for Ruby on Rails

Rails 4.1 introduces ActionPack Variants. It allows you to specify a different layout entirely for mobile users and tablets.

I wrote a blog post about using it in a couple of months ago: Bob On Rails — More Responsive Layouts

The rails edge guide documentation: Ruby on Rails 4.1 Release Notes — Ruby on Rails Guides

Thanks both! As I am already on Rails 4.0.3 I go for the ActionPack Variant option by upgrading to 4.1.0 and check this out.