NoMethodError: undefined method 'index' when called deliver to rails 3.1 mailer

I installed an intermediate instance of rails 3.1 application on Heroku and everything works fine, but I get a strange error when I try to send emails. I am using the sendgrid addon to send email. Full error below:

NoMethodError: undefined method `index' for #<Mail::Message:0x000000048daf28> /app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:1289:in `method_missing' /app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:117:in `value_decode' /app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:101:in `decode_encode' /app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/fields/unstructured_field.rb:74:in `do_decode' 

if I just create a message object without causing it to be delivered and inspected, everything seems fine. I do not see this error in my working application. Can you tell me what this error means and how to solve it? Thanks.

+4
source share
5 answers

Got the same error on my local machine using Rails 3.0.11. This happened after I passed some object instead of a string to the mail :to attribute. So make sure the :to attribute is a string!

 mail(to: object.to_s) 
+11
source

A new version of Mail, Mail 2.4.0, was released this weekend. I would recommend updating this latest version and see if it fixed your problem.

+1
source

This error was the result of using the class instead of the module when defining the created mail assistant.

+1
source

This error occurred because I was setting my own headers to an integer value. Using to_s for these values ​​solved the problem for me.

0
source

I had a similar problem. However, I got an error:

 NoMethodError (undefined method `ascii_only?' for nil:NilClass) 

My problem was with me:

 mail(to: emails,....) 

And my "emails" variables were actually an array, not a single line of letters.

0
source

Source: https://habr.com/ru/post/1391351/


All Articles