【问题标题】:Sending HAML emails with Pony使用 Pony 发送 HAML 电子邮件
【发布时间】:2011-10-26 16:21:08
【问题描述】:

Sinatra 1.2.6 / Haml 3.1.2 和 Pony

我收到“错误数量的参数错误(0 代表 1)”,它指向

sinatra/base.rb

def haml(template, options={}, locals={})
  render :haml, template, options, locals
end

我正在发送 :html_body => (haml :html_email) 给 Pony

任何帮助将不胜感激!

M.

【问题讨论】:

    标签: sinatra haml pony


    【解决方案1】:

    您的代码似乎可以在 Sinatra 1.2.6、Haml 3.1.3 和 Pony 1.3 中运行。 虽然我会使用 haml(:test) 而不是 (haml :test)

    test.rb:

    require 'rubygems'
    require 'sinatra'
    require 'pony'
    require 'haml'
    
    set :views, Proc.new { root }
    
    get '/send' do
        options = {
        :to => 'user@gmail.com',
        :from => 'user@gmail.com',
        :subject => 'Test',
        :body => 'Test Text',
        :html_body => (haml :test),
        :via => :smtp,
        :via_options => {
          :address => 'smtp.gmail.com',
          :port => 587,
          :enable_starttls_auto => true,
          :user_name => 'login',
          :password => 'password',
          :authentication => :plain,
          :domain => 'HELO'
        }
      }
    
      Pony.mail(options)
    end
    

    test.haml:

    !!!
    %html
      %head
        %meta{ :content => "text/html; charset=utf-8", :"http-equiv" => "Content-Type" }
        %title Test
      %body
        %h1 Test
        %p Test content
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多