Reputation: 59
I have been trying to solve this for ages and can't figure it out.
I have a form like so (taking out a lot of other fields)
<% form_for @machine_enquiry, machine_enquiry_path(@machine_enquiry) do|me_form| %>
<% me_form.fields_for :messages_attributes do |f| %>
<%= f.text_field :title -%>
<% end %>
<%= me_form.submit 'Send message' %>
<% end %>
And an update action like
@machine_enquiry = MachineEnquiry.find(params[:id])
@machine_enquiry.update_attributes(params[:machine_enquiry]
And a machine_enquiry class like so:
class MachineEnquiry < ActiveRecord::Base
has_many :messages, :as => :messagable, :dependent => :destroy
accepts_nested_attributes_for :messages
end
I am getting an error like so:
NoMethodError in Machine enquiriesController#update
undefined method `stringify_keys' for "2":String
RAILS_ROOT: C:/INSTAN~2/rails_apps/Macrotec28th
Application Trace | Framework Trace | Full Trace
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:294:in `assign_nested_attributes_for_collection_association'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:293:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:293:in `assign_nested_attributes_for_collection_association'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:215:in `messages_attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in `attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in `attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2627:in `update_attributes'
C:/INSTAN~2/rails_apps/Macrotec28th/app/controllers/machine_enquiries_controller.rb:74:in `update'
C:/INSTAN~2/rails_apps/Macrotec28th/app/controllers/machine_enquiries_controller.rb:72:in `update'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:294:in `assign_nested_attributes_for_collection_association'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:293:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:293:in `assign_nested_attributes_for_collection_association'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:215:in `messages_attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in `attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in `attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2627:in `update_attributes'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_responds.rb:106:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_responds.rb:106:in `respond_to'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:1322:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:1322:in `perform_action_without_filters'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:617:in `call_filters'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in `ms'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:10:in `realtime'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in `ms'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/flash.rb:141:in `perform_action'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in `process_without_filters'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:606:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:391:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:386:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:433:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:88:in `dispatch'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:111:in `_call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:82:in `initialize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:9:in `cache'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:28:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb:24:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:93:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:9:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `synchronize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/cgi_process.rb:44:in `dispatch_cgi'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:102:in `dispatch_cgi'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:28:in `dispatch'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in `synchronize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in `process_client'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `process_client'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `initialize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `new'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `initialize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `new'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281
C:/INSTAN~2/ruby/bin/mongrel_rails:19:in `load'
C:/INSTAN~2/ruby/bin/mongrel_rails:19
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:294:in `assign_nested_attributes_for_collection_association'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:293:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:293:in `assign_nested_attributes_for_collection_association'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/nested_attributes.rb:215:in `messages_attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in `attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in `attributes='
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2627:in `update_attributes'
C:/INSTAN~2/rails_apps/Macrotec28th/app/controllers/machine_enquiries_controller.rb:74:in `update'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_responds.rb:106:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/mime_responds.rb:106:in `respond_to'
C:/INSTAN~2/rails_apps/Macrotec28th/app/controllers/machine_enquiries_controller.rb:72:in `update'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:1322:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:1322:in `perform_action_without_filters'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:617:in `call_filters'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in `ms'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:10:in `realtime'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in `ms'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/flash.rb:141:in `perform_action'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in `send'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in `process_without_filters'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:606:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:391:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:386:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:433:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:88:in `dispatch'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:111:in `_call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:82:in `initialize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:9:in `cache'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:28:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb:24:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:93:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:9:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `synchronize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in `call'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/cgi_process.rb:44:in `dispatch_cgi'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:102:in `dispatch_cgi'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:28:in `dispatch'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in `synchronize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in `process'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in `process_client'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `process_client'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `initialize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `new'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `initialize'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `new'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `each'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in `run'
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281
C:/INSTAN~2/ruby/bin/mongrel_rails:19:in `load'
C:/INSTAN~2/ruby/bin/mongrel_rails:19
Request
Parameters:
{"commit"=>"Send message",
"_method"=>"put",
"machine_enquiry"=>{"messages_attributes"=>{"message"=>"2",
"title"=>"1",
"message_type_id"=>"1",
"contact_detail_ids"=>["1",
"11"]}},
"id"=>"2",
"datetime"=>""}
Why am I getting this error? Can anyone help with this?
Upvotes: 2
Views: 2526
Reputation: 18193
Taking a look at the params in your trace, I think the form may be incorrect in some way, but it's hard to say how without a little more information. The params you're getting from the form right now are (reformated for legibility):
{ "commit" => "Send message",
"_method" => "put",
"machine_enquiry" => {
"messages_attributes" => {
"message" => "2",
"title" => "1",
"message_type_id" => "1",
"contact_detail_ids" => [ "1", "11" ]
}
},
"id" => "2",
"datetime" => ""
}
But they should look something like:
{ "commit" => "Send message",
"_method" => "put",
"machine_enquiry" => {
"messages_attributes" => {
0 => {
"message" => "2", # this may still be wrong
"title" => "1",
"message_type_id" => "1",
"contact_detail_ids" => [ "1", "11" ]
}
}
},
"id" => "2",
"datetime" => ""
}
Note that the hash that was directly inside of messages_attributes
is now a level deeper. The nested attributes section of the form should contain a hash with a unique key for each message that is being created or edited. The source of the error was that the form format parser was seeing message
, title
, message_id
, and contact_detail_ids
as the unique keys for four separate messages, but the values associated with those keys weren't hashes, as it expected.
The line I've called out with a comment in the corrected example I'm a little unsure of. Without seeing the form in its entirety or the Message
class, it's hard to know if that's an attribute of the message, or maybe it's supposed to be the message id. The message id, by the way, should be included only if you're editing an existing message.
There's an exhaustive explanation of the Rails forms micro-format available. Search for has_many
to find the relevant section.
The source of this mis-formatted params hash is almost certainly your form_for
. If you include the entirety of it, someone may be able to help you diagnose why the form is being created incorrectly.
Updated
After looking at your full form, the problem is this line:
<% me_form.fields_for :messages_attributes do |f| %>
It should read:
<% me_form.fields_for :messages do |f| %>
The fields_for
helper expects the association name in order to act correctly. Another problem I saw while looking at the form is the radio buttons that you use for contacts will need to have the name
changed as well to something like machine_enquiry[messages_attributes][0][contact_detail_ids][]
. You'll probably need to find a way to generate those radio buttons using the form helper so they can get the correct message id.
Upvotes: 2