# Undefined method \`+' for nil:NilClass

**URL:** <https://www.ruby-forum.com/t/undefined-method-for-nil-nilclass/108454>\
**Category:** Rails\
**Created:** [July 3, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/undefined-method-for-nil-nilclass/108454 "2007-07-03T17:34:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [July 3, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/undefined-method-for-nil-nilclass/108454/1 "2007-07-03T17:34:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [July 3, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/undefined-method-for-nil-nilclass/108454/2 "2007-07-03T17:46:52Z")

</div>

> @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

---

<div class="post-metadata">

**Author:** ![scrajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@scrajesh](https://www.ruby-forum.com/u/scrajesh)\
**Post date:** [July 3, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/undefined-method-for-nil-nilclass/108454/3 "2007-07-03T17:58:17Z")

</div>

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.
