Greetings!
I’m trying to update a set of records from the same model on one form.
The AWD book gives an example on p.356 but I guess I’m not understanding
it.
I can see from the error message I’m getting that the controller is
receiving a hash of hashes back from the view, and that it’s got the
stuff I expected (two values per record that was sent to the view)
What I can’t figure out is how to update the records I sent in, based on
the values returned. I would really appreciate it if someone could
help point me in the right direction. I’ve included the view and
controller code below.
Thanks in advance for any assistance!
Bill
--------------------- controller code ------------------------
def edit_illnesses
# send a collection of records to the view
@emrec = find_emrec
@illnesses = Illness.find(:all,
:conditions => [“emrec_id = ?”,
@emrec.id])
end
def update_illness
update the records sent in ‘edit_illnesses’ based on what’s
returned in ‘params’
@emrec = find_emrec
@illnesses = Illness.find(:all,
:conditions => [“emrec_id = ?”,
@emrec.id])
for i in @illnesses
# I can’t figure out what should go here to update each of the
records
# with the new content returned from the form. How do I pull
the
# data from the params hash of hashes? The current code is:
i.update(params[:illness].id, (params[:illness].id).illness_date,
(params[:illness].id).qualifier)
i.save
end
redirect_to :controller => ‘creation’, :action => ‘show_emrec’
end
---------------------- end controller code -------------------------
------------------ view code --------------------------------
<%= form_tag(:action => “update_illness”) %>
<%=h @illness.illness %> | <%= options = [["Select a qualifier", ""]] + Illness::DATE_QUALIFIERS select("illness[]", "qualifier", options) %> | <%= options = [["Select a year", ""]] + Illness::DATE_YEARS select("illness[]", "illness_date", options) %> |
<%= end_form_tag %>
----------------------- end view code ----------------------
----------------------- error message -----------------------
NoMethodError in Phistoryadmin#update_illness
undefined method `illness_date’ for 32200148:FixnumRAILS_ROOT:
./script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/phistoryadmin_controller.rb:22:in
update_illness' #{RAILS_ROOT}/app/controllers/phistoryadmin_controller.rb:21:in
update_illness’C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
perform_action_without_filters' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in
perform_action_without_benchmark’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in
measure’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in
perform_action’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
process_without_session_management_support' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in
process’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in
handle_dispatch’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
service' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in
service’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:173:in
start_thread’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:95:in
start’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:23:in
start’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in
dispatch’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59
C:/INSTAN~1/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28
C:/INSTAN~1/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require’
script/server:3#{RAILS_ROOT}/app/controllers/phistoryadmin_controller.rb:22:in
update_illness' #{RAILS_ROOT}/app/controllers/phistoryadmin_controller.rb:21:in
update_illness’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
perform_action_without_filters' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in
perform_action_without_benchmark’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' C:/INSTAN~1/ruby/lib/ruby/1.8/benchmark.rb:293:in
measure’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in
perform_action’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
process_without_session_management_support' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in
process’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in
handle_dispatch’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
service' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in
service’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:173:in
start_thread’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:95:in
start’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:23:in
start’
C:/INSTAN~1/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in
dispatch’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59
C:/INSTAN~1/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28
C:/INSTAN~1/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require’
script/server:3Request
Parameters: {“illness”=>{“11”=>{“illness_date”=>“1970”,
“qualifier”=>“not since”}, “9”=>{“illness_date”=>“1972”,
“qualifier”=>“since”}, “10”=>{“illness_date”=>“1971”, “qualifier”=>“not
since”}}}