Module: Sinatra::UserAgentHelpers

Defined in:
lib/sinatra/support/useragenthelpers.rb

Overview

Usage

register Sinatra::UserAgentHelpers

Example

After you have registered the UserAgentHelpers, use the #browser helper to check for features:

<% if browser.ios? %>
  <p>Download our mobile app!</p>
<% end %>

Or use the #body_class method:

<body class="<%= browser.body_class %>">

The above line can have an output like so:

<body class="webkit safari mac">
<body class="windows ie ie6">

Helper

#browser -- provides the browser helper. Refer to the {UserAgent} class
for more info.

Instance Method Summary collapse

Instance Method Details

#browserObject



29
30
31
# File 'lib/sinatra/support/useragenthelpers.rb', line 29

def browser
  UserAgent.new(env['HTTP_USER_AGENT'] || '')
end