mail-x_smtpapi
mail-x_smtpapi copied to clipboard
Doesn't work with any field
NoMethodError: undefined method `values' for "{\"category\": \"Category\"}":String
from /var/lib/gems/2.3.0/gems/mail-x_smtpapi-1.1.0/lib/mail_x_smtpapi/field.rb:40:in `empty?'
Rails version 4.2.6
@Looooong would you clarify how to reproduce this error?
@cainlevy I just try a piece of example code in my project code
mail.smtpapi.category = 'Category'
It seems like the Field#empty? expect each of value.values to be Hash, but it turns out to be String. I tried with field category, filters, unique_args, and all of them raise the same execption.
Perhaps this error relates to the version of Rails?
Perhaps this error relates to the version of Rails?
Sure, what versions of Rails and Mail do you have?
Would you also try:
mail.method(:smtpapi).source_location
Which should look something like:
".../mail-x_smtpapi/lib/mail/x_smtpapi.rb", 6]
Rails 4.2.6, ActionMailer 4.2.6, Mail 2.6.4
And source_location shows as you said.
class TestMailer < ActionMailer::Base
def test
mail.smtpapi.category = 'My category'
mail(to: '[email protected]', subject: 'Test')
end
end
[3] pry(main)> TestMailer.test.deliver_now
Rendered test_mailer/test.html.slim (43.4ms) Rendered test_mailer/test.html.slim (1.9ms)TestMailer#test: processed outbound mail in 220.4ms
Sent mail to [email protected] (11.5ms) nil NoMethodError: undefined method 'values' for "{"category": "My category"}":String from /var/lib/gems/2.3.0/gems/mail-x_smtpapi-1.1.0/lib/mail_x_smtpapi/field.rb:40:in `empty?'
this works for me:
require 'bundler/inline'
gemfile true do
source 'https://rubygems.org'
gem 'rails', '4.2.6'
gem 'mail', '2.6.4'
gem 'mail-x_smtpapi', path: './'
end
require 'action_mailer'
ActionMailer::Base.delivery_method = :test
class TestMailer < ActionMailer::Base
def test
mail(from: '[email protected]', to: '[email protected]', subject: 'Test', body: 'hello world')
# had to move this line down so that actionmailer wouldn't complain about a missing template
mail.smtpapi.category = 'My Category'
end
end
TestMailer.test.deliver_now
So I wonder if you have a gem conflict. Your pasted pry session says that the mail is delivered and then errors. Maybe that's a Mail observer? I believe you can check with:
Mail.class_variable_get("@@delivery_notification_observers")
[16] pry(main)> Mail.class_variable_get("@@delivery_notification_observers")
=> []
I ran into the same error when I tried to pass the unsubscribe group ID as an integer instead of as a string. Hope this helps anyone making the same mistake I did.
Bad
message.smtpapi.asm_group_id = 52
Good
message.smtpapi.asm_group_id = "52"