Использование mailjet в рельсах

Я хочу использовать 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

конфиг /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'

1 ответ

Это проблема зависимости. Попробуйте добавить это: gem rest-client '~>1.6.9' на ваш Gemfile и беги bundle update

Другие вопросы по тегам