Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError: undefined method 'index' when calling deliver on rails 3.1 mailer

I have set up a staging instance of a rails 3.1 application on Heroku and everything seems to work fine except I'm getting a strange error when I try to send emails. I am using the sendgrid starter addon for email delivery. The full error is 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 generate the message object without calling deliver on it and inspect it everything seems fine. I am not seeing this error on my production app. Can you tell me what this error means and how to resolve it? Thanks.

like image 836
tks Avatar asked Dec 13 '22 06:12

tks


2 Answers

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

mail(to: object.to_s)
like image 75
Mario Uher Avatar answered Apr 27 '23 23:04

Mario Uher


A new version of Mail, Mail 2.4.0, was released this weekend. I would recommend upgrading to this latest version and seeing if that has fixed your issue.

like image 25
Ryan Bigg Avatar answered Apr 28 '23 00:04

Ryan Bigg