Hi
I am a newbie to Ruby on Rails, but experienced in programming.
I am trying out Rolling with Ruby on Rails article by Curt H. on
onlamp.com. I have encountered following error:
Called id for nil, which would mistakenly be 4 – if you really wanted
the id of nil, use object_id
I searched the archives of the list and found that similar
question was left unanswered. I do understand from the error that the
recipe.id is null(or nil).
I have come to this page from edit link from the show page. This
show page is generated by the scaffolding. The url for this link seems
to be correct - recipe/edit/2 (where 2 is id of the recipe).
Any ideas?
The entire dump is reproduced below:
RuntimeError in Recipe#edit
Showing app/views/recipe/edit.rhtml where line #10 raised:
Called id for nil, which would mistakenly be 4 – if you really wanted
the id of nil, use object_id
Extracted source (around line #10):
7:
8: <form action=“…/update/” <%= @recipe.id %> method=“POST”>
9: <input id=“recipe_id” name=“recipe[id]” size=“30”
10: type=“hidden” value=“<%= @recipe.id %>” />
11:
Title
12: <input id=“recipe_title” name=“recipe[title]” size=“30”
13: type=“text” value=“<%= @recipe.title %>” />
RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/views/recipe/edit.rhtml:10:in _run_rhtml_recipe_edit' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb :314:in
send’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb
:314:in compile_and_render_template' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb :290:in
render_template’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb
:249:in render_file' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b ase.rb:699:in
render_file’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:621:in render_with_no_layout' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/l ayout.rb:251:in
render_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:53:in render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b enchmarking.rb:53:in
measure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:53:in render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b ase.rb:911:in
perform_action_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/f
ilters.rb:368:in perform_action_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b enchmarking.rb:69:in
perform_action_without_rescue’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:69:in measure' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b enchmarking.rb:69:in
perform_action_without_rescue’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/r
escue.rb:82:in perform_action' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b ase.rb:381:in
send’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:381:in process_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/f ilters.rb:377:in
process_without_session_management_support’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/s
ession_management.rb:117:in process' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in
service’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in
run’
c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in
start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in
start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in each' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in
start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in
start’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick. rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require__’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/de pendencies.rb:147:in
require’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require__' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/de
pendencies.rb:147:in require' script/server:3 #{RAILS_ROOT}/app/views/recipe/edit.rhtml:10:in
run_rhtml_recipe_edit’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb
:314:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb :314:in
compile_and_render_template’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb
:290:in render_template' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb :249:in
render_file’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:699:in render_file' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b ase.rb:621:in
render_with_no_layout’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/l
ayout.rb:251:in render_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b enchmarking.rb:53:in
render’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:53:in measure' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b enchmarking.rb:53:in
render’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:911:in perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/f ilters.rb:368:in
perform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:69:in perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b enchmarking.rb:69:in
measure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
enchmarking.rb:69:in perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/r escue.rb:82:in
perform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b
ase.rb:381:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/b ase.rb:381:in
process_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/f
ilters.rb:377:in process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/s ession_management.rb:117:in
process’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
handle_dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in
service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in
service’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in
start_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in
start_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in
each’
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in
start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.
rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require__' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/de
pendencies.rb:147:in require' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require_’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/de pendencies.rb:147:in
require’
script/server:3
Request
Parameters: {“id”=>“1”}
Show session dump
flash: !ruby/hash:ActionController::Flash::FlashHash {}
Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}
Regards,
Shreekar Joshi