0

注文確認メールを送信するために Mailjet を使用したいです。

まずはGemをインストールしてMailjetガイドとして設定してみました

gem 'mailjet'

初期化子/mailjet.rb

Mailjet.configure do |config|
  config.api_key = '<my_api_key>'
  config.secret_key = '<my_secret_key>'
  config.default_from = '<my_email>'
end

config/application.rb

config.action_mailer.delivery_method = :mailjet_api

そして、これは私のコントローラーのアクションです

def send_email_reserved
    email = { :from_email   => "<my_from_email>",
          :from_name    => "Dona Sky",
          :subject      => "Hello",
          :text_part    => "Hi",
          :recipients   => [{:email => "<my_to_email>"}] }

    test = Mailjet::Send.create(email)
    p test.attributes['Sent']
  end

アクションを呼び出すと、エラーが表示されました

NoMethodError: undefined method `[]' for #<Set: {#<MIME::Type: application/json>}>
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:307:in `type_for_extension'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:312:in `type_for_extension'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block (2 levels) in stringify_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `map'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block in stringify_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `each'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `inject'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `stringify_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:92:in `make_headers'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:58:in `initialize'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:67:in `handle_api_call'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:47:in `post'
    from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/resource.rb:215:in `save'
4

1 に答える 1

1

これは依存関係の問題です。これを追加してみてください:gem rest-client '~>1.6.9'あなたGemfileの実行にbundle update

于 2016-06-07T07:45:09.740 に答える