首页 > 解决方案 > 安培。Rails 上的 AMP 列表。信中的数据未加载到谷歌电子邮件中

问题描述

我已经翻遍了几乎所有东西,但我找不到如何在航班上解决它。怎么了,您需要向客户发送包含动态内容的电子邮件。模板已制作、检查、工作。我正在使用放大器列表。创建了一个用于拉取数据的端点。在场外AMP上一切正常,但在 AMP Google中,远程链接上的数据无法通过。我认为这种形式是错误的。我给自己寄了一封信。邮件上有一个空白屏幕。是的,amp-list 需要 Cors。添加gem 'rack-cors'到 Gemfile。

配置/应用程序.rb

config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '/api/v1/offer', headers: :any, methods: %i[get]
  end
end

我在控制器中的端点。(app/controllers/api/v1/offer_controller.rb)

module Api
  module V1
    class OfferController < ActionController::API
      def index
        country = params[:country].to_i if params && params[:country]
        region = params[:region].to_i if params && params[:region]
        if !country || !region
          render json: { items: [] }.to_json, status: :ok
          return
        end
        tour = Tour.where(country: country, region: region).order(:position)
        @actual = tour.where(star: true)
        
        response.set_header('Access-Control-Allow-Credentials', 'true')
        render 'api/offer/index', content_type: :'application/json'
      end
    end
  end
end

AMP 内容(为简单起见,最多截断)

<!doctype html>
<html ⚡4email data-css-strict>

<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
  <script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
  <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
  <script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
  <style amp4email-boilerplate>
    body {
      visibility: hidden
    }
  </style>
  <style amp-custom>

  </style>
</head>
<body>
      <amp-list id="amp-list-placeholder" noloading width="auto" height="365" layout="fixed-height"
      src="https://joinupdev.shm.best/api/v1/offer?country=1&region=2">
        <template type="amp-mustache">
           <amp-img src="{{img1}}" width="450" height="300" layout="responsive" alt="{{name1}}"></amp-img>
        </template>
      </amp-list>
</body>
</html>

我忘记在标题中添加什么以使 amp-list 在谷歌上工作?我会很感激你的帮助。

标签: ruby-on-railsemailamp-list

解决方案


推荐阅读