Joe at CodeGear
2006-Dec-23 17:06 UTC
help with "undefined method `stringify_keys!''" please
This is probably some dumb mistake on my part, but I''m not seeing it. I have a _simple_ app that I''m playing with. In this scenario I have a meeting that I want to add agenda items to. When I click the submit button in this form I get a "stringify keys" error. I''d appreciate it if someone could point out my error. What tools/practices do you use to trouble shoot these kinds of problems? the error ======================================================(enter "New Agenda Item" in the text box) the error ====================================================== NoMethodError in MeetingsController#addagendaitem undefined method `stringify_keys!'' for "New Agenda Item":String RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1506:in `attributes='' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1354:in `initialize_without_callbacks'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:236:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:14:in `new'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:14:in `build'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_collection.rb:88:in `create'' #{RAILS_ROOT}/app/controllers/meetings_controller.rb:23:in `addagendaitem'' -e:4:in `load'' -e:4 C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1506:in `attributes='' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1354:in `initialize_without_callbacks'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:236:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:14:in `new'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:14:in `build'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_collection.rb:88:in `create'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/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:173:in `start_thread'' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' script/server:3 C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1506:in `attributes='' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1354:in `initialize_without_callbacks'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:236:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:14:in `new'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:14:in `build'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_collection.rb:88:in `create'' #{RAILS_ROOT}/app/controllers/meetings_controller.rb:23:in `addagendaitem'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/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:173:in `start_thread'' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' script/server:3 -e:4:in `load'' -e:4 Request Parameters: {"name"=>"New Agenda Item", "commit"=>"Add agenda item", "id"=>"1"} Show session dump --- :user: 1 :return_to: flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} from meetings_controller.rb ========================================... def addagendaitem Meeting.find(params[:id]).agenda_items.create(params[:name]) end ... show.rhtml in views/meetings =======================================<h1>Run a Meeting</h1> <%= render :partial => "run_meeting" %> <h2>Agenda Items</h2> <% for agenda_item in @meeting.agenda_items %> <%= agenda_item.name %> <% end %> <hr> <%= form_tag :action => "addagendaitem", :id => @meeting %> <p> <label for="name">Agenda Item:</label> <br/> <%= text_field_tag "name" %> </p> <p> <%= submit_tag ''Add agenda item'' %> </p> <%= end_form_tag %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Elad Meidar - Creopolis.com
2006-Dec-23 18:45 UTC
Re: help with "undefined method `stringify_keys!''" please
Hi. in the addagendaitem method, you try to create a new object (create method) while transfering just a string to it (params[:name]). create expects to get an attributes hash and to stringify it''s keys for the column names. i suggest you expand your code into more lines and create a new item, setting it''s values and then saving. you can also make your form in a way in which it will send an hash as the object (ex. "item" => { "name"=> "kof", "amount" => "2"}) this will enable you for doing Example.create(params[:item]) Hope this helps. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joe at CodeGear
2006-Dec-24 04:28 UTC
Re: help with "undefined method `stringify_keys!''" please
Thanks, breaking it out into separate calls (create, initialize, save, add to meeting) works. The coding pattern I used was based on what I saw in the "15 minute blog in Rails" video. I must have missed a concept there somehow. I''ll have to experiment and see if I can get a better bearing on this. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---