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:ininitialize_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:innew’
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:increate’
#{RAILS_ROOT}/app/controllers/meetings_controller.rb:23:in
addagendaitem' -e:4:inload’
-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:ininitialize_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:innew’
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:increate’
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:inperform_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:inperform_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:inperform_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:insend’
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:inprocess_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:indispatch’
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:inservice’
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart’
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' C:/ruby/lib/ruby/1.8/webrick/server.rb:95:instart’
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:instart’
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' C:/ruby/lib/ruby/1.8/webrick/server.rb:82:instart’
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:ingem_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:inrequire’
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:inrequire’
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:ininitialize_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:innew’
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:increate’
#{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:insend’
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:inperform_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:inmeasure’
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:inperform_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:inprocess_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:inprocess’
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:inhandle_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:inservice’
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/ruby/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:ineach’
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' C:/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’
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:indispatch’
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:inrequire’
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:ingem_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:inrequire’
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 ========================================

Run a Meeting

<%= render :partial => “run_meeting” %>

Agenda Items

<% for agenda_item in @meeting.agenda_items %> <%= agenda_item.name %> <% end %>

<%= form_tag :action => “addagendaitem”, :id => @meeting %>


Agenda Item:


<%= text_field_tag “name” %>

<p>
    <%= submit_tag 'Add agenda item' %>

</p>

<%= end_form_tag %>

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.

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.