New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fork_mobu

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fork_mobu

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Mobu

Gem Version Build Status Code Climate Coverage Status

Mobu provides a Rails controller concern called DetectMobile. Mobu does server-side User Agent detection to categorize requests as mobile, tablet, or default.

Mobu modifies your rails view paths based on the request type. It does not require custom MIME types or separate subdomains.

Disclaimer: It is rarely a good idea to use User Agent detection to render different HTML content. Please read this first:

https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent

Install

Add this line to your Gemfile:

gem 'mobu'

Include the module in your ApplicationController:

class ApplicationController
  include Mobu::DetectMobile

Create directories for views_mobile and views_tablet:

mkdir app/views_mobile
mkdir app/views_tablet

Usage

Put the view/partial files that you want to override in the appropriate directories.

When you receive a mobile request, your app will first look for view files in app/views_mobile directory, then in app/views.

Alternately, you can switch your rendering logic using the mobile_request? and tablet_request? helper methods in your view files or helpers:

- if mobile_request?
  .small-thing Short Text
- else
  .regular-thing Much Longer Text

To allow mobile users to switch to the full site view, add a link to a mobile view. For example:

app/views_mobile/_footer.haml
= link_to("View Full Site", prefer_full_site_url)

To allow full site users to switch to the mobile view, add a link to a default view. For example:

app/views_mobile/_footer.haml
- if mobile_browser?
  = link_to("View Mobile Site", prefer_mobile_site_url)

Credits

The view path modification technique was taken from this post by Scott W. Bradley.

The user agent regex came from a similar project, Brendan Lim's mobile-fu.

FAQs

Package last updated on 04 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc