mr_muscle
mr_muscle

Reputation: 2920

Rails way to detect mobile or web device

I want to send an email to user to confirm their account. My app have only mobile version so I want to detect case when user will open email and click confirmation button using web browser. In such case I need to display instruction to go to the mobile app. But in case when it's opened by mobile the confirmation button should redirect to the app and confirmed whole account.

Is there any rails way to distinguish between these two cases? I'm using devise for all email mechanism.

Upvotes: 1

Views: 1708

Answers (1)

BTL
BTL

Reputation: 4666

In your controller you can access the request method.

You can create a helper method like this to get the user_agent :

def mobile_device?
  request.user_agent =~ /Mobile|webOS/
end

Upvotes: 1

Related Questions