← Back to Upcase

Logic in views and controllers based on mobile or desktop visitor

(John van Arkelen) #1

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
  show something different

(Manish Valechha) #2

Hi @jarkelen,

Have a look at https://github.com/tscolari/mobylette

(Bob Firestone) #3

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: http://bobonrails.com/post/72213272339/more-responsive-layouts

The rails edge guide documentation: http://edgeguides.rubyonrails.org/4_1_release_notes.html#action-pack-variants

(John van Arkelen) #4

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.