ryanb / letter_opener

Preview mail in the browser instead of sending.
MIT License
3.73k stars 238 forks source link

Getting: `undefined local variable or method `to_ary' for #<Mail::FromField>` #97

Closed jurre closed 10 years ago

jurre commented 10 years ago

Hi,

I'm running into an issue with letter_opener where Message#from, #to etc are throwing the following error: NameError: undefined local variable or methodto_ary' for #Mail::FromField:0x007fae398a28e0`

I've tracked it down to this code:

Array(@mail["from"])
=> NameError: undefined local variable or method `to_ary' for #<Mail::FromField:0x007fae398a28e0>

The strange thing is that whenever I try to do this on a Mail object created manually it works fine:

[11] pry(main)> m = Mail.new(from: "j.stender@example.com", to: "test@example.com") { content_type("text/html; charset=UTF-8"); content_transfer_encoding('quoted-printable'); body("hello!") }
=> #<Mail::Message:70297656821620, Multipart: false, Headers: <From: j.stender@example.com>, <To: test@example.com>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: quoted-printable>>
[12] pry(main)> Array(m["from"]).join(", ")
=> "j.stender@example.com"

I've tried using the .from syntax to access the Mail objects properties but that seems to open up another can of worms.

This seems to happen since the 2.6.1 version of the Mail gem, so I've tried updating letter_openers Mail gem but the specs also still pass just fine with that version.

This happens on ruby 2.1.3 and 2.1.4.

Hope you can help me out here, if you need any more info please let me know!

Thanks! <3

nashby commented 10 years ago

Can you please provide a sample application that reproduces the error?

jurre commented 10 years ago

On it! :)

jurre commented 10 years ago

Weird stuff, the example that I was making seems to work fine. I'll investigate further with our setup but I don't think this is necessarily a letter_opener issue..

giovannibonetti commented 10 years ago

I'm running into the same problem. It happens exactly with the "from" field, and when I call it from the console it seems to work, though. Any idea on what to do about it?

jurre commented 10 years ago

I've just disabled letter_opener for now, no idea what's causing this :(

giovannibonetti commented 10 years ago

Thanks, @jurre

dpaluy commented 10 years ago

I had the same issue. I disabled gem 'pry-remote'. And it solved the problem. But, after I enabled it, it still works correctly. :anguished:

yuki24 commented 9 years ago

This must be due to some of the old versions of did_you_mean gem: https://github.com/yuki24/did_you_mean/issues/14 Are you guys using 0.8.0 or older? If so, could you upgrade it to 0.9.4 and try again? I'm so sorry about the bug.

dpaluy commented 9 years ago

@yuki24 You are right. That was my issue.