Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Methods Class Methods

I get 'NameError: undefined local variable or method' whenever I try to run BankAccount.find_for

After creating an account in the BankAccount class, I then try to run the find_for method and it just returns the below errors:

NameError: undefined local variable or method `first_name' for #<BankAccount:0x007fcfda04a338>
    from /Users/jamilvelji/Ruby_Testing/Source/methods/bank_account.rb:19:in `full_name'
    from /Users/jamilvelji/Ruby_Testing/Source/methods/bank_account.rb:9:in `block in find_for'
    from /Users/jamilvelji/Ruby_Testing/Source/methods/bank_account.rb:9:in `each'
    from /Users/jamilvelji/Ruby_Testing/Source/methods/bank_account.rb:9:in `find'
    from /Users/jamilvelji/Ruby_Testing/Source/methods/bank_account.rb:9:in `find_for'
    from (irb):5
    from /Users/jamilvelji/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'
Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

This is for Ruby Foundations -- not with Rails -- however, Jamil, can we see your bank_account.rb file?

1 Answer

David Curtis
David Curtis
11,301 Points

can you post the code from your controller? did you define the first_name variable? is it "@first_name" or something else?