I'm at a loss here. When running in Dev mode (script/server) I the error "undefined local variable or method 'id' for #<InsertModelNameHere:0x7f19bdb87dc8>
" at random times when I try to list entries for a number of my models. If I refresh the page it works fine and I'm assuming that I only see it in dev because everything gets reloaded for each request. Maybe a race condition or something going on? I'm not even referencing the "id" attribute (legacy table that uses a different key naming convention) in the views where this is an issue, One of my co-workers informed me that rails will create an "id" attribute based on the primary key defined in the model though.
Below is the code for the view, the error message,a and the stack trace. I'm running rails 2.3.3.
View:
<h2 class="textCenter">To Do List</h2>
<% form_tag({:action => "list"}, :method => "get") do %>
<div class="full_width textCenter">
<%= text_field_tag "q", params[:q] %>
<input type="submit" value="Search" />
</div>
<% end %>
<table class="full_width list">
<thead >
<tr >
<th >ID</th>
<th >Name</th>
<th >Resource ID</th>
<th >Company</th>
<th > </th>
<th > </th>
</tr>
</thead>
<tbody >
<% begin %>
<% @todos.each do |todo| %>
<tr class="<%= cycle "striped", "" %>" >
<td ><%= todo.pk_todo_id %></td>
<td ><%= todo.name %></td>
<td ><%= todo.fk_resource_id %></td>
<td ><%= todo.fk_company_id %></td>
<td ><%= link_to "STA", {:controller => "stas", :action => "list", :id => todo.fk_resource_id} %></td>
<td ><%= link_to "Edit", {:controller => "todos", :action => "edit", :id => todo.pk_todo_id} %></td>
</tr>
<% end %>
<% rescue => e; puts e.message; puts e.backtrace %>
<% end %>
</tbody>
</table>
Error: undefined local variable or method 'id' for #<Todo:0x7f19bdb87dc8>
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/attribute_methods.rb:260:in 'method_missing'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/attribute_methods.rb:249:in 'method_missing'
/home/scott/Projects/cllsuite/trunk/app/views/todos/list.rhtml:25:in '_run_rhtml_app47views47todos47list46rhtml'
/home/scott/Projects/cllsuite/trunk/app/views/todos/list.rhtml:23:in 'each'
/home/scott/Projects/cllsuite/trunk/app/views/todos/list.rhtml:23:in '_run_rhtml_app47views47todos47list46rhtml'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/renderable.rb:34:in 'send'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/renderable.rb:34:in 'render'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/base.rb:301:in 'with_template'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/renderable.rb:30:in 'render'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/template.rb:199:in 'render_template'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/base.rb:260:in 'render'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/base.rb:343:in '_render_with_layout'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_view/base.rb:257:in 'render'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:1246:in 'render_for_file'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:941:in 'render_without_benchmark'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/benchmarking.rb:51:in 'render'
/var/lib/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/benchmark.rb:17:in 'ms'
/usr/lib/ruby/1.8/benchmark.rb:308:in 'realtime'
/var/lib/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/benchmark.rb:17:in 'ms'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/benchmarking.rb:51:in 'render'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:1322:in 'default_render'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:1328:in 'perform_action_without_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/filters.rb:617:in 'call_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/filters.rb:610:in 'perform_action_without_benchmark'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/benchmarking.rb:68:in 'perform_action_without_rescue'
/var/lib/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/benchmark.rb:17:in 'ms'
/usr/lib/ruby/1.8/benchmark.rb:308:in 'realtime'
/var/lib/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/benchmark.rb:17:in 'ms'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/benchmarking.rb:68:in 'perform_action_without_rescue'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/rescue.rb:160:in 'perform_action_without_flash'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/flash.rb:146:in 'perform_action'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:527:in 'send'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:527:in 'process_without_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/filters.rb:606:in 'process'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:391:in 'process'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/base.rb:386:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/routing/route_set.rb:434:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:88:in 'dispatch'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:111:in '_call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:82:in 'initialize'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:29:in 'call'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:29:in 'call'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in 'cache'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:9:in 'cache'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:28:in 'call'
/var/lib/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapter /abstract/connection_pool.rb:361:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/head.rb:9:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:24:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/params_parser.rb:15:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/session/cookie_store.rb:93:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/reloader.rb:29:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/failsafe.rb:26:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in 'synchronize'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in 'call'
/var/lib/gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:106:in 'call'
/var/lib/gems/1.8/gems/rails-2.3.3/lib/rails/rack/static.rb:31:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in 'each'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in 'call'
/var/lib/gems/1.8/gems/rails-2.3.3/lib/rails/rack/log_tailer.rb:17:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/content_length.rb:13:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/chunked.rb:15:in 'call'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:61:in 'process'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in 'process_client'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in 'each'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in 'process_client'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in 'run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in 'initialize'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in 'new'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in 'run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in 'initialize'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in 'new'
/var/lib/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in 'run'
/var/lib/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:34:in 'run'
/var/lib/gems/1.8/gems/rails-2.3.3/lib/commands/server.rb:111
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in 'gem_original_require'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in 'require'
script/server:3