Search code examples
ruby-on-railsrubymailer

Rails mailer "undefined method" error.


I'm trying to setup a simple mailer in rails 3.1.

I have the following code in my mailer...

class Notify < ActionMailer::Base

  default :from => "signup@raceton.com"

  def send
    @email = email
    @ip = ip
    mail(:to => "test@test.com", :subject => "#{email} just signed up")
  end

end

Then in my controller I have...

Notify.send(params[:email], ip).deliver

For some reason that I can't work out when that line is called in my controller I get the following error...

undefined method `*string I passed in*' for Notify:Class

Any ideas what I'm doing wrong here?


Solution

  • send() is already defined by Ruby, and it is used to pass messages around.

    So, to ruby it looks like you are trying to call a method.

    User.first.send(:name)
    

    is the same thing as calling

    User.first.name
    

    Just rename your method.