R
R
rusrich2019-03-27 13:00:59
Ruby on Rails
rusrich, 2019-03-27 13:00:59

How to use the podigee/device_detector gem in a Ruby on Rails project?

Good afternoon.
Through IRB in the terminal, the developer's example works fine.
But I can not figure out how to use it in the application.
In models, controller or view?
The task is this:
You need to load different scripts for different devices.
Please tell me how to implement.
request.headers['User-Agent'] - only works in a view. How to write the same in the model?
I understand the logic

def user_agent
  user_agent = request.headers['User-Agent']
  client = DeviceDetector.new(user_agent)
end

And further through the condition
if client.device_type ==  'smartphone'
...
else
...
end

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question