I need to pass an array of mailobjects from my rails mailer class to the co开发者_StackOverflowrresponding 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.
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.
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(...))
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论