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!

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 ActiveRecord Basics Migrations and Relationships Relationships

Binu Alexander
Binu Alexander
4,081 Points

NoMethodError ... What is wrong here ?

Command : Customer.first.time_entries

RESULTING ERROR

Customer Load (0.5ms) SELECT customers.* FROM customers ORDER BY customers.id ASC LIMIT 1

NoMethodError: undefined method time_entries' for #<Customer:0x007fee0aef8288> from /usr/local/lib/ruby/gems/2.2.0/gems/activemodel-4.2.1/lib/active_model/attribute_methods.rb:433:inmethod_missing' from (irb):6 from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in start' from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:instart' from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in console' from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:inrun_command!' from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in <top (required)>' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:inrequire' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in block in require' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:inload_dependency' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in require' from /Users/binualexander/OneDrive/My Documents/Programming/Ruby on Rails/biller/bin/rails:8:in<top (required)>' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in load' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:inblock in load' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in load_dependency' from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:inload' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/commands/rails.rb:6:in call' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/command_wrapper.rb:38:incall' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:183:in block in serve' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:156:infork' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:156:in serve' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:131:inblock in run' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:125:in loop' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application.rb:125:inrun' from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in <top (required)>' from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from -e:1:in<main>'irb(main):007:0>

What is wrong here ?

2 Answers

Without seeing your code it's hard to say. One thing that stands out to me is "time_entries" - plural. Just like Customer is singular, time_entry should be also - the model name is singular, the table name is plural. So, try this:

Customer.first.time_entry
Binu Alexander
Binu Alexander
4,081 Points

Thanks Tommy

I got it , i had made a mistake of refering to the table as 'customers' in the migration file and hence the id created was 'customers_id' when it should have been 'customer_id' . Fixed that and this command is working .

Customer.first.time_entries ( the video shows exactly this )

Good deal, glad you were able to sort it out.

Danish Saleem
Danish Saleem
7,965 Points

Hi , i am having the same issue but i am using sqlite intead of mysql , can anyone help ?