Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError undefined method mail for

After setting up mailer (3.2.6) in Ruby on rails (3.2.6) I get this error:

NoMethodError (undefined method `mail' for #):

my user_mailer.rb looks like this:

class UserMailer < ActionMailer::Base
  default :from => "[email protected]"

  def activation_mail(user)
    @user = user
    mail(:to => user.mail, :subject => "Registration")
  end
end

I followed example provided here: http://guides.rubyonrails.org/action_mailer_basics.html

In configuration file I added this line: config.action_mailer.delivery_method = :test I also tried with :smtp and configuration for gmail.

What have I missed?

like image 905
Preseren Avatar asked Jul 03 '12 09:07

Preseren


3 Answers

I had a similar problem recently and rectified it by replacing:

def self.activation_mail()

with

def activation_mail()
like image 56
user3128345 Avatar answered Oct 21 '22 12:10

user3128345


you should try replacing

def activation_mail(user)
    @user = user
    mail(:to => user.mail, :subject => "Registration")
  end

with

def activation_mail(user)
    @user = user
    mail(:to => @user.mail, :subject => "Registration")
  end
like image 35
Faizan Avatar answered Oct 21 '22 12:10

Faizan


It's a typo error. Your user.mail doesn't exist. Maybe it should be user.email or something else.

like image 2
user1241920 Avatar answered Oct 21 '22 12:10

user1241920