Designer
Designer

Reputation: 1111

Disabling access to some pages for mobile devices with Rails5

How can I block access to Post/New page for mobile devices with Rails? Do I need some sort of JS redirection?

Thank you

Upvotes: 1

Views: 156

Answers (2)

Niklas
Niklas

Reputation: 298

There is no truly safe way to block all mobile devices! You can check for the User-Agent in your controller and test if it's a mobile browser issuing the request. Check https://developer.mozilla.org/de/docs/Web/HTTP/Headers/User-Agent for a list of UAs.

def is_mobile?
   request.user_agent == "mobile-ua-string"
end

Upvotes: 0

Rubyrider
Rubyrider

Reputation: 3587

You can check your client type from your header of the request. Moreover if you don't want to do that manually you can check this gem

Upvotes: 1

Related Questions