Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

returning an array of objects in rails

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.

like image 540
hanneswurstes Avatar asked Feb 16 '26 09:02

hanneswurstes


1 Answers

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.

like image 103
Leo Avatar answered Feb 19 '26 04:02

Leo