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

285 views
Skip to first unread message

maddy

unread,
Sep 25, 2009, 5:57:56 AM9/25/09
to Ruby on Rails: Talk
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:in `initialize'
app/controllers/contact_controller.rb:24:in `new'
app/controllers/contact_controller.rb:24:in `update'
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:in `initialize'
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:in `perform_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:in `perform_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:in `measure'
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:in `perform_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:in
`cache'
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:in `perform_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:in `process_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:in `process'
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:in `handle_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:in `dispatch_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:in `process'
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:in `process'
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:in `each'
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:in `run'
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:in `new'
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:in `initialize'
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:in `run'
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:in `each'
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:in `run'
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:in `load'
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:in `new_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:in
`gem_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:in `require'
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:in `require'
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:in
`require'
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:in `initialize'
app/controllers/contact_controller.rb:24:in `new'
app/controllers/contact_controller.rb:24:in `update'
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:in `perform_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:in `perform_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:in `measure'
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:in `perform_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:in
`cache'
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:in `perform_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:in `process_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:in `process'
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:in `handle_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:in `dispatch_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:in `process'
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:in `process'
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:in `each'
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:in `run'
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:in `new'
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:in `initialize'
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:in `run'
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:in `each'
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:in `run'
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:in `load'
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:in `new_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:in
`gem_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:in `require'
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:in `require'
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:in
`require'
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"=>"ad...@gr.com"},
"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


Amar Daxini

unread,
Sep 25, 2009, 6:41:53 AM9/25/09
to rubyonra...@googlegroups.com
maddy wrote:
>
I think you are updating @contact
@contact.update_attributes(params[:contact])
--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Sep 25, 2009, 6:59:44 AM9/25/09
to Ruby on Rails: Talk


On Sep 25, 10:57 am, maddy <murali.man...@gmail.com> wrote:

>   The "Update" action in controller file looks like this,
>
>        def update
>              @contact = Contact.new(params[:id])

This should be Contact.find

Fred

maddy

unread,
Sep 29, 2009, 4:31:36 AM9/29/09
to Ruby on Rails: Talk
Hi Fred,

Thanks a lot!

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

Regards,
maddy
Reply all
Reply to author
Forward
0 new messages