seiya1121 / perfect_ror

0 stars 0 forks source link

variantsによるテンプレートの切り替え #2

Open seiya1121 opened 7 years ago

seiya1121 commented 7 years ago

variants: 条件によってテンプレートを切り分ける機構 接続してきた端末によって、PCとは別のテンプレートを表示した問いう場合に有効

class ApplicationController < ActionController::Base
  before_action :detect_mobile_variant
  ...
  private

  def detect_mobile_variant
    request.variant = :mobile if request.user_agent =~ /iphone/  
  end
end

mobile用のテンプレートには、 +mobile をつける 例: show.html+mobile.erb