Undefined method `+' for nil:NilClass

I’m trying to send emails in my application.
the email function in under the ActionMailer::Base as follows:


def xxxxx(aaa, recipient, bbb, burl)
@from = aaa.email
@recipients = [ recipient ]
@subject = “#{aaa.firstname} #{aaa.lastname} has emailed U!”
@content_type = “text/plain”

@body["aaa"] = aaa
@body["bbb"]= bbb
@body["uri"] = "#{burl}subscribe/welcome/#{bbb.id}";

end


It’s email template is:

Hi,

<%= @aaa.firstname %> <%= @aaa.lastname %> has wants to discuss: ‘<%=
@bbb.name %>’.

Click here: <%= @uri %> .

Best regards,
The MySite Team

When i execute these i get this error “undefined method `+’ for
nil:NilClass”.
Kindly help me out to overcome this issue!

thanx,

  • Charles.

@body[“aaa”] = aaa

nil:NilClass".
Kindly help me out to overcome this issue!

It would help to know what line/file that error is happening on.

I’m gonna guess since I don’t see a ‘+’ anywhere in the above code that
the model for @bbb has a ‘name’ method which looks something like:

def name
self.firstname + self.lastname
end

And I’m guessing that @bbb is nil.

But without knowing where the actual error occured it’s hard to say…

-philip

Philip H. wrote:

It would help to know what line/file that error is happening on.

I’m gonna guess since I don’t see a ‘+’ anywhere in the above code that
the model for @bbb has a ‘name’ method which looks something like:

def name
self.firstname + self.lastname
end

And I’m guessing that @bbb is nil.

-philip

thanx for taking time to reply me.

Actually the problem is the one U’ve highlighted

But without knowing where the actual error occured it’s hard to say…

Also i didn’t use the ‘+’ mark anywhere in these functions,
the @aaa & @bbb are the hashes directly from the DB. I just use
AAA.find(1) and BBB.find(58) to retrieve the records.
Also i didn’t use any kind of function as U’ve suggested above.

Really i don’t know what the heck is going on with this piece of code!!
Was sitting a whole day by applying & trying various possibilities to
overcome this issue!!

– Charles.