# Undefined method \`generate\_token'

**URL:** <https://www.ruby-forum.com/t/undefined-method-generate-token/183209>\
**Category:** Rails\
**Created:** [February 10, 2010, 12:07am UTC](https://www.ruby-forum.com/t/undefined-method-generate-token/183209 "2010-02-10T00:07:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 10, 2010, 12:07am UTC](https://www.ruby-forum.com/t/undefined-method-generate-token/183209/1 "2010-02-10T00:07:15Z")

</div>

Hi Everyone…

I’m following a railscast episode on how to implement an invitation  
feature.

It’s going really well, but i’ve hit a minor snag that I cant get  
over…

undefined method `generate\_token’ for #Invitation:0x2563bf8

The invite form allows me to check for a user, and whether they  
already have registered. If they have, the invitation is not sent, and  
a flash message is printed.

If the email does not exist, the invite count (starts at 5) decrements  
until you have none left.

When i click invite, i get the error above. It’s moaning about this  
line: @invitation.sender = @user

i tied replacing @user with user, but still no use…

def create  
@invitation = Invitation.new(params[:invitation])  
@invitation.sender = @user  
if @invitation.save  
flash[:notice] = “Thanks - Invitation sent successfully.”  
redirect\_to hub\_url  
else  
render :action =\> ‘new’  
end  
end

Any ideas why this wont decrement, and why this error is still  
visible?

Many Thanks

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 10, 2010, 5:11am UTC](https://www.ruby-forum.com/t/undefined-method-generate-token/183209/2 "2010-02-10T05:11:33Z")

</div>

You should specify where @user is defined, otherwise it looks like an  
undefined variable issue. You haven’t defined @user in the code you  
pasted. Most authentication schemes define the current logged in user  
as “current\_user” or “User.current”. Are you defining it as @user?

On Feb 9, 6:05 pm, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 10, 2010, 9:29am UTC](https://www.ruby-forum.com/t/undefined-method-generate-token/183209/3 "2010-02-10T09:29:04Z")

</div>

Ok -

So should I have another line in that says:

user = invitation.sender followed by

@invitation.sender = @user ?

Sorry - may be a daft question, but trying to get my head round it as  
I go. The tutorial has been trouble free until this… 🙂
