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: <td><%=h feature.details %></td> 17: <td><%=h feature.priority %></td> 18: <td><%=h feature.project.title %></td> 19: <td><%=h feature.owner.username %></td> 20: <td><%= link_to 'Show', [...@project, feature] %></td> 21: <td><%= link_to 'Edit', edit_project_feature_path(@project, feature) %></td> 22: <td><%= link_to 'Destroy', [...@project, feature], :confirm => 'Are you sure?', :method => :delete %></td> ========= 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: <td><%=h feature.details %></td> 17: <td><%=h feature.priority %></td> 18: <td><%=h feature.project.title %></td> 19: <td><%=h feature.owner.username %></td> 20: <td><%= link_to 'Show', [...@project, feature] %></td> 21: <td><%= link_to 'Edit', edit_project_feature_path(@project, feature) %></td> 22: <td><%= link_to 'Destroy', [...@project, feature], :confirm => 'Are you sure?', :method => :delete %></td> 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) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---