To note, I'm not interested in simply 'hiding' content for mobile devices, I want to filter out that content completely. I'm also not trying to address the issue by building a mobile specific interface (mob.example.com).

There was another question regarding something similar:

How do I prevent useless content load on the page in responsive design?

The solution, in that post, was to set a session during the initial request, and then use the session to filter content on subsequent requests.

I primarily develop in Rails, and I'm wondering if there are any gems or ruby-specific solutions to this problem?

1 Answer 1


by 'fiter out completely' do you mean that you just don't want to pass the content to client and hide them using CSS? if so, in your rails views why don't you take output decision based on the device? for example,

def mobile_device?
  true #put your device detection logic here

#view file (in haml)
- if mobile_device?
  Mobile content
- else 
  General content

instead of using your device detection logic, you can also use useragent gem

you can also render completely different view/partial depending on the browser/device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.