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)
...
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Dec 14, 2011 at 12:28 pm

    On 14 December 2011 11:50, Pieter Hugo 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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Pieter Hugo at Dec 14, 2011 at 2:36 pm
    Hi Colin

    Thanks for the feedback. I kinda grokked that eventually. But I can't
    just turn my receive method into a class level method - because then the
    raw email string never gets turned into a tmail object. I any case the
    original code - which works, but doesnt pass my userid, is

    class PokeMailer < ActionMailer::Base
    def receive(email)
    ...
    end

    I then invoke the receipt of email with

    task = PokeMailer.receive(m.pop)

    Question - is this now a class method or an instance method? It gets
    called on the PokeMailer class, and responds, but its not defined with
    def self.receive.

    I suspect my ruby skills are woefully inadequate.... :(

    Any other suggestions?

    Pieter

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Dec 14, 2011 at 2:53 pm

    On 14 December 2011 14:35, Pieter Hugo wrote:
    Hi Colin

    Thanks for the feedback. I kinda grokked that eventually. But I can't
    just turn my receive method into a class level method - because then the
    raw email string never gets turned into a tmail object. I any case the
    original code - which works, but doesnt pass my userid, is

    class PokeMailer < ActionMailer::Base
    def receive(email)
    That is an instance method. To call it you would need a PokeMailer
    object and then call it via
    my_poke_mailer.receive(..)
    ...
    end

    I then invoke the receipt of email with

    task = PokeMailer.receive(m.pop)
    You are asking here for a class method, so it will look for something
    defined as
    def self.receive()
    Since you have not overridden that then presumably it will call an
    existing method (I don't know PokeMailer so I can't comment on the
    details). It will not call your method. Take your method out and see
    if it still finds a method.
    Question - is this now a class method or an instance method? It gets
    called on the PokeMailer class, and responds, but its not defined with
    def self.receive.
    not sure what you are asking here. If you want to find out which
    method it is calling have a look at the Rails Guide on debugging, it
    will show you how to use ruby-debug to break into your code, you can
    then step into the function and see where it goes.
    I suspect my ruby skills are woefully inadequate.... :(
    So are mine, just possibly slightly less so. The problem is that the
    problem one is tackling often seems to require just a little more
    knowledge than one's current state. :)

    Colin

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Pieter Hugo at Dec 14, 2011 at 3:15 pm
    Hi Colin

    Thanks for bearing with me. Your thinking is spot on in agreement with
    how I understand ruby. And yet
    class PokeMailer < ActionMailer::Base
    def receive(email)
    ...
    end

    I then invoke the receipt of email with

    task = PokeMailer.receive(m.pop)
    works 100%

    I tried creating an instance of PokeMailer (see first post)

    pm = PokeMailer.new(userid)

    But it just returns nil, and pm.receive says nil doesn't have a receive
    method.

    I think its something to do with Actionmailer - but it definitely doesnt
    behave like a normal class.

    :(

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Dec 14, 2011 at 3:21 pm

    On 14 December 2011 15:14, Pieter Hugo wrote:
    Hi Colin

    Thanks for bearing with me. Your thinking is spot on in agreement with
    how I understand ruby. And yet
    class PokeMailer < ActionMailer::Base
    def receive(email)
    ...
    end

    I then invoke the receipt of email with

    task = PokeMailer.receive(m.pop)
    works 100%
    What happens if you comment out your receive method and then run the code?

    Colin
    I tried creating an instance of PokeMailer (see first post)

    pm = PokeMailer.new(userid)

    But it just returns nil, and pm.receive says nil doesn't have a receive
    method.

    I think its something to do with Actionmailer - but it definitely doesnt
    behave like a normal class.

    :(

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Frederick Cheung at Dec 14, 2011 at 6:22 pm

    On 14 Dec 2011, at 15:14, Pieter Hugo wrote:

    Hi Colin

    Thanks for bearing with me. Your thinking is spot on in agreement with
    how I understand ruby. And yet
    class PokeMailer < ActionMailer::Base
    def receive(email)
    ...
    end

    I then invoke the receipt of email with

    task = PokeMailer.receive(m.pop)
    works 100%

    I tried creating an instance of PokeMailer (see first post)

    pm = PokeMailer.new(userid)

    But it just returns nil, and pm.receive says nil doesn't have a receive
    method.

    I think its something to do with Actionmailer - but it definitely doesnt
    behave like a normal class.
    There's a method_missing handler which handles calls to class methods that aren't there by creating new instances and dispatching the method to the newly created instance

    Fred
    :(

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Pieter Hugo at Dec 15, 2011 at 7:38 am
    Thanks for all the help guys. I got a solution in the end. I created a
    class level variable called @@userid which I then set in my
    getemail(email,userid) method before calling receive(email). Nasty, and
    not what I'd have expected, but it works.

    Regards

    Pieter

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 14, '11 at 11:50a
activeDec 15, '11 at 7:38a
posts8
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase