HHH v4

render different view on mobile/tablet

Edit
equivalent Web Development
Public
Rails
# a/c/concerns/detect_device.rb
module DetectDevice
  extend ActiveSupport::Concern

  included do
    before_action :set_variant
  end

  def set_variant
    case request.user_agent
    when /iPhone/
      request.variant = :phone
    when /iPad/
      request.variant = :tablet
    end
  end
end


..or ther is browser gem that better handles different devices

    browser = Browser.new(request.user_agent)
    if browser.mobile?
      request.variant = :phone
    elsif browser.tablet?
      request.variant = :tablet
    end




class ApplicationController < ActionController::Base
   include DetectDevice
   #...

views


then you need two partials


when variant is set RAILS renders different partial


controller side


       if @post.save
         format.html.phone { redirect_to @post, notice: "Post was successfully created ON PHONE." }
         format.html { redirect_to @post, notice: "Post was successfully created." }
         format.json { render :show, status: :created, location: @post }
       else
         format.html { render :new, status: :unprocessable_entity }
         format.json { render json: @post.errors, status: :unprocessable_entity }
       end