On 14 December 2011 11:50, Pieter Hugo <[email protected]> wrote: > hi Guys > > I have now spent hours on this and turn to you in desperation. > > I am using Actionmailer to fetch emails, but I need to pass a userid to > the receive method, so that the receive method knows what user to pass > the email to. I tried: > (ATTEMPT 1) > class PokeMailer < ActionMailer::Base > def receive(email,userid)
If you are trying to define a class method (rather than an instance method) you need def self.receive(..) I think this may be the root of all the problems below also. Colin > ... > end > > I then invoke the receipt of email with > > task = PokeMailer.receive(m.pop,userid) > > But I get the error 'wrong number of arguments (2 for 1)' > > So I though - ok - the actionmailer receive method must be expecting one > argument. Lets create another method to accept the userid and call the > receive method with only the raw email. So I wrote as second PokeMailer > method: > (ATTEMPT 2) > class PokeMailer < ActionMailer::Base > def getemail(email,userid) > @userid=userid > PokeMailer.receive(email) > end > def receive(email) > .. > end > .. > end > > and call it with > > task = PokeMailer.getemail(m.pop,userid) > > Now I get the error 'undefined method `getemail' for PokeMailer:Class' > > (kindof figured this out - changed def getemail to def self.getemail > > My third attempt was to try and instantiate an instance of PokeMailer > with a initialize method: > (ATTEMPT 3) > class PokeMailer < ActionMailer::Base > def intitalize (userid) > @userid = userid > super #not sure if this is needed? > end > def receive(email) > ... > end > ... > end > > and then call this with something like: > > pm = PokeMailer.new(userid) > task = pm.receive(m.pop) > > This fails because it seems that pm == nil - it doesn't event get > created?!!! > > I am at whits' end. Please save me! > > Thanks for anything - even sympathy would help ;) > > Pieter Hugo > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- gplus.to/clanlaw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

