###前提・実現したいこと
Ruby on Railsでアプリケーションを作成しています.
アクセスされた端末によってViewを切り替える機能をControllerに記述しました.
Viewを切り替えた後,モバイル端末のView用に作成したstylesheetを適用したいのですが,PCのViewにも適用されてしまいます.(PCのstylesheetは別に記述しています)
どうすれば,モバイル端末のViewのみにstylesheetを適用できますか.
product_controller.rb
1class ProductController < ApplicationController 2 3 before_action :detect_devise_variant 4 5 # アクセスされた端末を判定して,Viewのみを切り替える 6 private 7 def detect_devise_variant 8 ua = request.user_agent 9 if(ua.include?('Mobile') || ua.include?('Android')) 10 # モバイル端末ならば,index.html+mobile.erbを表示 11 # そうでなければ,index.html.erbを表示する 12 request.variant = :mobile 13 end 14 end 15end
###備考
assets.rb上でモバイル端末用stylesheet(product_sp.scss)をプリコンパイルしています.
assets.rb
1Rails.application.config.assets.precompile += %w( product_sp.css )
あなたの回答
tips
プレビュー