# 根据设备类型自动渲染页面

### 添加Gem

```ruby
gem "browser"
```

### 定义方法

```ruby
class ApplicationController < ActionController::Base
  
  before_action :detect_device_variant

  def detect_device_variant
    # 定义手机端调用
    request.variant = :mobile if browser.device.mobile?
    # 定义平板，如果需要
    request.variant = :tablet if browser.device.tablet?
  end

end

```

### 配置View

找到需要配置的view

```ruby
application.html.erb  #原始模板文件
application.html+mobile.erb  #如果定义的有mobile
application.html+tablet.erb  #如果定义的有tablet
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.tanmer.cn/gem/ruby-on-rails/gen-ju-she-bei-lei-xing-zi-dong-ran.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
