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 trialBinu Alexander
4,081 PointsNoMethodError ... 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:in
method_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:in
start'
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:in
run_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:in
require'
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:in
load_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:in
block 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:in
load'
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:in
call'
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:in
fork'
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:in
block 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:in
run'
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:in
require'
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
Tommy Bregar
10,847 PointsWithout 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
Danish Saleem
7,965 PointsHi , i am having the same issue but i am using sqlite intead of mysql , can anyone help ?
Binu Alexander
4,081 PointsBinu Alexander
4,081 PointsThanks 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 )
Tommy Bregar
10,847 PointsTommy Bregar
10,847 PointsGood deal, glad you were able to sort it out.