Hi Everyone,
I have issue while doing eager loading when url is =>
http://127.0.0.1:3001/projects/1/features
I also did <%= debug @features %> to dump @feature object but I did
not see ‘owner’ being eager-loaded.
Can anyone find out why owner is not being ‘eager-loaded’?
Thanks in advance.
========= features_controller.rb -> index method
def index
@project = Project.find(params[:project_id])
@features = @project.features.find(:all, :include =>
[:owner, :project])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @features }
end
end
========= Output of <%= debug @features %>
-
!ruby/object:Feature
attributes:
project_id: “1”
updated_at: 2009-10-24 11:07:19
created_at: 2009-10-24 11:07:19
attributes_cache: {}project: &id001 !ruby/object:Project
attributes:
status: In Progress
title: TestProject
id: “1”
finished_on: 2009-12-31 23:59:00
owner_user_id: “4”
brief: RAID Controller and DMA Engine for Invader
created_at: 2009-10-20 19:35:15
attributes_cache: {} -
!ruby/object:Feature
attributes:
project_id: “1”
updated_at: 2009-10-24 11:26:09
details: for testing
priority: normal
id: “3”
owner_id: “1”
brief: test feature updated
created_at: 2009-10-24 11:18:11
attributes_cache: {}project: *id001
========= Error in browser
NoMethodError in Features#index
Showing app/views/features/index.html.erb where line #19 raised:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.username
Extracted source (around line #19):
16:
17:
18:
19:
20:
21:
feature) %>
22:
‘Are you sure?’, :method => :delete %>
========= Server Log
ActionView::TemplateError (You have a nil object when you didn’t
expect it!
The error occurred while evaluating nil.username) on line #19 of app/
views/features/index.html.erb:
16:
17:
18:
19:
20:
21:
feature) %>
22:
‘Are you sure?’, :method => :delete %>
app/views/features/index.html.erb:19
app/views/features/index.html.erb:13:in `each'
app/views/features/index.html.erb:13
app/controllers/features_controller.rb:8:in `index'
-e:2:in `load'
-e:2
Rendered rescues/_trace (94.0ms)
Rendered rescues/_request_and_response (0.0ms)
Rendering rescues/layout (internal_server_error)