неопределенный метод `high_chart 'для # <Mail :: Part - Ruby - PullRequest
0 голосов
/ 24 февраля 2020

У меня есть скрипт Ruby, который отправляет электронную почту при запуске из терминала. Я хочу создать и отправить автоматически сгенерированную гистограмму вместе с ней. Я использую LazyHighCharts , но получаю эту ошибку:

undefined method `high_chart' for #<Mail::Part

Это мой сценарий:

#!/usr/bin/env rvm 2.3.3@mygemset do ruby
require 'net/http'
require 'json'
require 'chronic'
require 'mail'
require 'pry'
require 'letter_opener'
require 'pg'
require 'lazy_high_charts'

@chart = LazyHighCharts::HighChart.new('graph') do |f|
  f.title(text: "Population vs GDP For 5 Big Countries [2009]")
  f.xAxis(categories: ["United States", "Japan", "China", "Germany", "France"])
  f.series(name: "GDP in Billions", yAxis: 0, data: [14119, 5068, 4985, 3339, 2656])
  f.series(name: "Population in Millions", yAxis: 1, data: [310, 127, 1340, 81, 65])

  f.yAxis [
    {title: {text: "GDP in Billions", margin: 70} },
    {title: {text: "Population in Millions"}, opposite: true},
  ]

  f.legend(align: 'right', verticalAlign: 'top', y: 75, x: -50, layout: 'vertical')
  f.chart({defaultSeriesType: "column"})
end

@chart_globals = LazyHighCharts::HighChartGlobals.new do |f|
  f.global(useUTC: false)
  f.chart(
    backgroundColor: {
      linearGradient: [0, 0, 500, 500],
      stops: [
        [0, "rgb(255, 255, 255)"],
        [1, "rgb(240, 240, 255)"]
      ]
    },
    borderWidth: 2,
    plotBackgroundColor: "rgba(255, 255, 255, .9)",
    plotShadow: true,
    plotBorderWidth: 1
  )
  f.lang(thousandsSep: ",")
  f.colors(["#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354"])
end

И функция электронной почты определяется как:

mail = Mail.deliver do
  from    'PLACEHOLDER'
  to      'PLACEHOLDER'
  subject "Automated Report: New prospects created by rep based on lead source "
  html_part do
   body "<i>This is an automated email.  All data in this email was generated automatically.</i>
    <br>
    <br>
    <b>For the date range of last Monday through Sunday inclusive, each rep was credited with creating the following amount of records based on lead source:</b>
    <br>
    <br>

    #{high_chart("some_id", @chart)}
    "
  end
end
...