fnando/browser

500 error undefined method `mobile?' in production

esmyllyaho90 opened this issue · 2 comments

Description

Rails 7.0.1 - Ruby 3.1.2 - Browser - 5.3.1
I followed your docs and added gem "browser" to my gemfile (outside of dev grp). And in my view I added:

<% if browser.mobile? %>
<% else %>
<% end %>

Tested it out in development and it worked perfectly on all devices I tried. Now after pushing to production on heroku I'm getting this error:

ActionView::Template::Error: undefined method `mobile?' for #<Browser::Chrome:0x00007efdef5c9ee8 @ua="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36", @accept_language_raw="sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7">
app/views/pages/login_link_sent.html.erb:14
actionview (7.0.1) lib/action_view/base.rb:244:in `public_send'
actionview (7.0.1) lib/action_view/base.rb:244:in `_run'
actionview (7.0.1) lib/action_view/template.rb:157:in `block in render'

Hey! To use methods like browser.mobile?, you need to import the aliases support by using require "browser/aliases", as described on the readme. Alternatively, you can do browser.device.mobile? (no need to import aliases in this case).

Feel free to reopen this issue if you still face this issue after doing either of the above. :)

browser.device.mobile? worked like a charm. Thank u so much for the quick reply :)