3

I need to pass an array of mailobjects from my rails mailer class to the corresponding controller which i thought should work if i just do

class foo < Actionmailer::Base

    def bar(...)
        mails_array = Array.new
        return mails_array
    end

but as the controller gets mails_array via

@mails = Array.new
@mails.concat(foo.bar(...))

i get a:

TypeError in mailsController#index
can't convert Mail::Message into Array

did i miss something?? I would expect to have the mails_array in mails and can't understand why it is not.

1
  • concat why that's not passing my mind, haha tqq Commented Jul 24, 2013 at 7:50

2 Answers 2

2

You are calling foo.bar, but bar is defined as instance method, not class method. Try

class foo < Actionmailer::Base      

    def self.bar(...)
        mails_array = Array.new
        return mails_array
    end

instead.

Sign up to request clarification or add additional context in comments.

Comments

0

Array#concat expects the argument to be an array but you're passing a Mail::Message. Try the following:

@mails << foo.bar(...)

or

@mails.push(foo.bar(...))

1 Comment

unfortunately that doesn't help.. the array will be filled but just with the first element out of mails_array although it should be the whole array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.