While upgrading our Rails app to version 2.3.2 I ran into a painful bug when running our unit tests. Previously, we defined ActionMailer instance variables to be used in our views like this:
@body["name"] = user.name
@body["feedback"] = feedback
@body["when"] = Time.now
I had to refactor this to use a hash as the ActionMailer documentation suggests:
body {:name => user.name, :feedback => feedback, :when => Time.now}
It turns out this doesn’t work and generates an error. So I removed the hash and did the following:
body :name => user.name, :feedback => feedback, :when => Time.now
Now all is well. It cost me an hour of my day and hopefully it will cost you much less now that you’re informed. If you can share any information why the hash doesn’t work then please feel free to share. Thanks!
I suspect it was interpreted as a block:
body do
:name => user.name #etc
end
You would have to wrap it in parens to make it interpret as a hash.
body( { :name => user.name } )
Mike, thanks for the thoughts and I’ll be sure to give your suggestion a try.