Reputation: 6346
I'm trying to conditionally render/hide some html in one of my views for tablets and mobile devices such as android phones & tablets, iPhone, iPad, etc. So far I have this setup:
def mobile_agent?
request.user_agent =~ /Mobile|webOS/
end
This seems to work good, but currently it only supports mobile devices and not tablets. I know mobile_fu groups both mobile devices and tablets under the mobile device category, however it also changes the request format which I don't want. My web application is utilizing a responsive theme so views are meant to work under any device with the exception of an embeded Unity webplayer which I wish to hide in a single view.
Is there any way I can extend the above method to include tablets as well as mobile devices?
Upvotes: 2
Views: 1249
Reputation: 4409
Try this: https://github.com/neighborland/mobu
Mobu provides a Rails controller concern called DetectMobile. Mobu does server-side User Agent detection to categorize requests as mobile, tablet, or default.
Mobu modifies your rails view paths based on the request type. It does not require custom MIME types or separate subdomains.
Upvotes: 1
Reputation: 14943
I use this one
def mobile_agent?
request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPad|iPod|BlackBerry|Android)/]
end
Upvotes: 7