NoMethodError : undefined method `stringify_keys!' for "2":String

Hi,

I have been trying to create a small Rails application. In one of
the steps, I am facing this error as “NoMethodError in
ContactController#update … undefined method `stringify_keys!’
for “2”:String”.

Let me give a brief description of the application. This application
is to Create, View and Update contacts. The problem came when updating
a record.

The “Update” action in controller file looks like this,

   def update
         @contact = Contact.new(params[:id])
         @contact.attributes = params[:contact]
         @contact.save!
         redirect_to :action => "index"
   end

Below is the complete error stack,


xxxxxxxxxxxxxxxx--------------------------------------------------

NoMethodError in ContactController#update
undefined method `stringify_keys!’ for “2”:String
RAILS_ROOT: D:/rails_projects/contactlist

Application Trace | Framework Trace | Full Trace
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2111:in attributes=' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/base.rb:1926:ininitialize’
app/controllers/contact_controller.rb:24:in new' app/controllers/contact_controller.rb:24:inupdate’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2111:in attributes=' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/base.rb:1926:ininitialize’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:1158:in send' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:1158:inperform_action_without_filters’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:697:in call_filters' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:689:inperform_action_without_benchmark’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/benchmarking.rb:68:in
perform_action_without_rescue' D:/RoR/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/benchmarking.rb:68:in
perform_action_without_rescue' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/rescue.rb:199:inperform_action_without_caching’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/caching.rb:678:in perform_action' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:33:incache’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/query_cache.rb:8:in cache' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/caching.rb:677:inperform_action’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:524:in send' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:524:inprocess_without_filters’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:685:in
process_without_session_management_support' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/session_management.rb:123:inprocess’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:388:in process' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:171:inhandle_request’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:115:in dispatch' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:126:indispatch_cgi’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:9:in dispatch' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel/rails.rb:76:inprocess’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/rails.rb:74:in synchronize' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel/rails.rb:74:inprocess’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:159:in process_client' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:158:ineach’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:158:in process_client' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:285:inrun’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:285:in initialize' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:285:innew’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:285:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:268:ininitialize’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:268:in new' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:268:inrun’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/configurator.rb:282:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel/configurator.rb:281:ineach’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/configurator.rb:281:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/ mongrel_rails:128:inrun’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/command.rb:212:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/ mongrel_rails:281 D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:489:inload’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in load' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:342:innew_constants_in’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in load' D:/RoR/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/ mongrel.rb:64 D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:inrequire’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:342:in new_constants_in' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:inrequire’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:
39
D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/base.rb:2111:in attributes=' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/base.rb:1926:ininitialize’
app/controllers/contact_controller.rb:24:in new' app/controllers/contact_controller.rb:24:inupdate’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:1158:in send' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:1158:inperform_action_without_filters’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:697:in call_filters' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:689:inperform_action_without_benchmark’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/benchmarking.rb:68:in
perform_action_without_rescue' D:/RoR/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/benchmarking.rb:68:in
perform_action_without_rescue' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/rescue.rb:199:inperform_action_without_caching’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/caching.rb:678:in perform_action' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:33:incache’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/query_cache.rb:8:in cache' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/caching.rb:677:inperform_action’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:524:in send' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:524:inprocess_without_filters’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/filters.rb:685:in
process_without_session_management_support' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/session_management.rb:123:inprocess’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/base.rb:388:in process' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:171:inhandle_request’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:115:in dispatch' D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:126:indispatch_cgi’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/
action_controller/dispatcher.rb:9:in dispatch' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel/rails.rb:76:inprocess’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/rails.rb:74:in synchronize' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel/rails.rb:74:inprocess’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:159:in process_client' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:158:ineach’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:158:in process_client' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:285:inrun’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:285:in initialize' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:285:innew’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:285:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:268:ininitialize’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel.rb:268:in new' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel.rb:268:inrun’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/configurator.rb:282:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/ mongrel/configurator.rb:281:ineach’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/configurator.rb:281:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/ mongrel_rails:128:inrun’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/
mongrel/command.rb:212:in run' D:/RoR/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/ mongrel_rails:281 D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:489:inload’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in load' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:342:innew_constants_in’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:489:in load' D:/RoR/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/ mongrel.rb:64 D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:inrequire’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active_support/dependencies.rb:342:in new_constants_in' D:/RoR/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:inrequire’
D:/RoR/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:
39
D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' D:/RoR/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3
Request
Parameters:

{“commit”=>“Update”,
“authenticity_token”=>“9ebbca881cc0e31be50530d9b3f1a38fcf1a74d1”,
“contact”=>{“city”=>“bangalo”,
“country”=>“India”,
“phone”=>“234122342”,
“first_name”=>“abc”,
“last_name”=>“def”,
“address”=>“weiwq,
werwqqq,
wer”,
“state”=>“KA”,
“email”=>“[email protected]”},
“id”=>“2”}

Show session dump


:csrf_id: 5d52f51ba29b9131292e9e783e78f09b
flash: !map:ActionController::Flash::FlashHash {}

Response
Headers:

{“cookie”=>[],
“Cache-Control”=>“no-cache”}


xxxxxxxxxxxxxxxxxxxxxxx----------------------------------------

What I feel is that there is something wrong with this statement in
‘Update’ action,

@contact.attributes = params[:contact]

I just don’t have enough command on this language to exactly know the
problem.

Can anyone help me solving this problem? Please do let me know if any
additional details are needed.

Many Thanks!!
Maddy

maddy wrote:

I think you are updating @contact
@contact.update_attributes(params[:contact])

On Sep 25, 10:57 am, maddy [email protected] wrote:

The “Update” action in controller file looks like this,

   def update
         @contact = Contact.new(params[:id])

This should be Contact.find

Fred

Hi Fred,

Thanks a lot!

You were right. It had to be Contact.find.

Regards,
maddy