Hi,
I have this Test, User and Project models where every test belongs_to
a project and project has_many tests.
Test also belongs_to User as ''owner''.
Then i followed railcast#139 to create nested route as -
map.resources :projects, :has_many => :tests
But somehow i get this error when url is ''http://127.0.0.1:3000/
projects/1/tests'' in tests/index.html.erb. Please help.
How line 24 works and not 25 :?
- Ninad
**** ERROR ****
NoMethodError in Tests#index
Showing app/views/tests/index.html.erb where line #25 raised:
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.username
**** tests_controller.rb ***
@project = Project.find(params[:project_id])
@tests = @project.tests.find(:all, :include =>
[:owner, :project, :category])
**** index.html.erb ****
20: <% @tests.each do |testcase| %>
21: <tr>
22: <td><%=h test.status %></td>
23: <td><%=h test.defunct %></td>
24: <td><%=h test.project.title %></td>
25: <td><%=h test.owner.username %></td>
26: </tr>
27: <% end %>
nin_d
2009-Oct-23 19:44 UTC
Re: error: nested-routes with nested-model having foreign keys
I observed that eager loading works when there is only one entry in tests model. Strange! Any suggestions? On Oct 23, 9:56 pm, nin_d <ninadpachp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have this Test, User and Project models where every test belongs_to > a project and project has_many tests. > Test also belongs_to User as ''owner''. > > Then i followed railcast#139 to create nested route as - > map.resources :projects, :has_many => :tests > > But somehow i get this error when url is ''http://127.0.0.1:3000/ > projects/1/tests'' in tests/index.html.erb. Please help. > > How line 24 works and not 25 :? > > - Ninad > > **** ERROR **** > > NoMethodError in Tests#index > > Showing app/views/tests/index.html.erb where line #25 raised: > > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.username > > **** tests_controller.rb *** > > @project = Project.find(params[:project_id]) > @tests = @project.tests.find(:all, :include => > [:owner, :project, :category]) > > **** index.html.erb **** > > 20: <% @tests.each do |testcase| %> > 21: <tr> > 22: <td><%=h test.status %></td> > 23: <td><%=h test.defunct %></td> > 24: <td><%=h test.project.title %></td> > 25: <td><%=h test.owner.username %></td> > 26: </tr> > 27: <% end %>
Sijo k g
2009-Oct-24 04:40 UTC
Re: error: nested-routes with nested-model having foreign keys
Hi> 20: <% @tests.each do |testcase| %> > 21: <tr> > 22: <td><%=h test.status %></td> > 23: <td><%=h test.defunct %></td> > 24: <td><%=h test.project.title %></td> > 25: <td><%=h test.owner.username %></td>Is it actually |testcase| or |test| ? Sijo -- Posted via http://www.ruby-forum.com/.
nin_d
2009-Oct-24 04:49 UTC
Re: error: nested-routes with nested-model having foreign keys
it is test not testcase! On Oct 24, 9:40 am, Sijo k g <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > > > 20: <% @tests.each do |testcase| %> > > 21: <tr> > > 22: <td><%=h test.status %></td> > > 23: <td><%=h test.defunct %></td> > > 24: <td><%=h test.project.title %></td> > > 25: <td><%=h test.owner.username %></td> > > Is it actually |testcase| or |test| ? > > Sijo > -- > Posted viahttp://www.ruby-forum.com/.