Rails 4.1变种:如何处理桌面版本"按键

时间:2014-08-29 19:35:03

标签: ruby-on-rails

我正在尝试添加我的rails 4.1网站的移动版本。

我在菜单中添加一个按钮"查看桌面版本"

我该如何处理?

我想在url中传递一个参数,例如

http://www.example.com/?desktop=1

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_action :detect_device_format

  private

    def detect_device_format
      return if params[:desktop] == 1
      case request.user_agent
      when /iPad/i
        request.variant = :tablet
      when /iPhone/i
        request.variant = :phone
      when /Android/i && /mobile/i
        request.variant = :phone
      when /Android/i
        request.variant = :tablet
      when /Windows Phone/i
        request.variant = :phone
      end
    end
end

通过这种方式,我无法为每个请求设置...我该如何解决?

0 个答案:

没有答案