ruby on rails - "NoMethodError in TasksController#update" -- why? -
i'm learning rails (so stupid error). i'm trying write edit screen updates parent , children @ same time. when hit save get:
nomethoderror in taskscontroller#update undefined method `to_sym' #<arel::attributes::integer:0x00000004d11970>
i can't figure out has caused , where/what integer object is. can give me pointers?
edit: can make work if start scratch new rails project. parameters raising error ones under key "flactions_attributes". there seem values missing that, that's not problem.
detail
the parent model task, child flaction. (take me, don't want name table 'action' in rails...)
the error page helpfully shows params hash (please pardon 'comedy' test data.):
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"qs1gvsz+lkniybsidnsmvfciba+3j0nfk37477a7mps=", "task"=>{"name"=>"finish secret lair", "description"=>"", "flactions_attributes"=>{"0"=>{"name"=>"choose colour scheme", "notes"=>"ask voices?", "id"=>"80"}, "1"=>{"name"=>"pick name", "notes"=>"something skulls in it?", "id"=>"81"}}}, "x"=>"3", "y"=>"14", "id"=>"53"}
here's update method in controller. afaics it's vanilla:
def update @task = task.find(params[:id]) respond_to |format| if @task.update_attributes(params[:task]) format.html { redirect_to(@task, :notice => 'task updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @task.errors, :status => :unprocessable_entity } end end end
so: @task.update_attributes finds integer , tries run to_sym on it. thing pass update_attributes params, , there no integer keys there. how work out going on?
here's _form file, fwiw:
<%= form_for(@task) |f| %> <% if @task.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@task.errors.count, "error") %> prohibited task being saved:</h2> <ul> <% @task.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="<%= @task.hold ? 'task held' : 'task' %>" > <div class="field name"> <%= f.text_field :name, size: 20 %> <span class="buttons"> <%= if @task.hold link_to image_tag('unhold-icon.png', alt: 'un-hold'), change_hold_task_path(@task) else link_to image_tag('hold-icon.png', alt: 'hold'), change_hold_task_path(@task) end %> <%= link_to image_tag('delete-icon.png', alt: 'delete'), @task, confirm: 'are sure?', method: :delete %> </span> </div> <div class="field desc"> <%= f.text_area :description, rows: 3, cols: 95 %> </div> <table> <% f.fields_for :flactions |a| %> <tr> <td class="field"> <%= a.text_field :name %> </td> <td class="field"> <%= a.text_area :notes, rows: 2, columns: 40 %> </td> <td class="buttons"> <%= link_to image_tag("up-icon-small.png", alt: 'move up'), move_flaction_path(a.object, direction: "up") %> <%= link_to image_tag("down-icon-small.png", alt: 'move down'), move_flaction_path(a.object, direction: "down") %> <%= link_to image_tag("delete-icon-small.png", alt: 'delete'), a.object, :confirm => 'are sure?', :method => :delete %> </td> </tr> <% end # f.fields_for %> </table> <%= image_submit_tag('save-icon.png', alt: 'save') %> </div> <!-- of div.task or div.task_held --> <% end %>
edit: stack trace, requested:
activerecord (3.0.8) lib/active_record/base.rb:1267:in `block in expand_hash_conditions_for_aggregates' activerecord (3.0.8) lib/active_record/base.rb:1266:in `each' activerecord (3.0.8) lib/active_record/base.rb:1266:in `expand_hash_conditions_for_aggregates' activerecord (3.0.8) lib/active_record/relation/query_methods.rb:225:in `build_where' activerecord (3.0.8) lib/active_record/relation/query_methods.rb:76:in `where' activerecord (3.0.8) lib/active_record/relation/spawn_methods.rb:124:in `apply_finder_options' activerecord (3.0.8) lib/active_record/relation/finder_methods.rb:143:in `all' activerecord (3.0.8) lib/active_record/nested_attributes.rb:364:in `assign_nested_attributes_for_collection_association' activerecord (3.0.8) lib/active_record/nested_attributes.rb:254:in `flactions_attributes=' activerecord (3.0.8) lib/active_record/base.rb:1564:in `block in attributes=' activerecord (3.0.8) lib/active_record/base.rb:1560:in `each' activerecord (3.0.8) lib/active_record/base.rb:1560:in `attributes=' activerecord (3.0.8) lib/active_record/persistence.rb:131:in `block in update_attributes' activerecord (3.0.8) lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status' activerecord (3.0.8) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction' activerecord (3.0.8) lib/active_record/transactions.rb:207:in `transaction' activerecord (3.0.8) lib/active_record/transactions.rb:290:in `with_transaction_returning_status' activerecord (3.0.8) lib/active_record/persistence.rb:130:in `update_attributes' app/controllers/tasks_controller.rb:62:in `block in update' actionpack (3.0.8) lib/action_controller/metal/mime_responds.rb:264:in `call' actionpack (3.0.8) lib/action_controller/metal/mime_responds.rb:264:in `retrieve_response_from_mimes' actionpack (3.0.8) lib/action_controller/metal/mime_responds.rb:191:in `respond_to' app/controllers/tasks_controller.rb:61:in `update' actionpack (3.0.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action' actionpack (3.0.8) lib/abstract_controller/base.rb:150:in `process_action' actionpack (3.0.8) lib/action_controller/metal/rendering.rb:11:in `process_action' actionpack (3.0.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action' activesupport (3.0.8) lib/active_support/callbacks.rb:436:in `_run__950750868564864989__process_action__1833593346352443574__callbacks' activesupport (3.0.8) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks' activesupport (3.0.8) lib/active_support/callbacks.rb:94:in `run_callbacks' actionpack (3.0.8) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.0.8) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.0.8) lib/active_support/notifications.rb:52:in `block in instrument' activesupport (3.0.8) lib/active_support/notifications/instrumenter.rb:21:in `instrument' activesupport (3.0.8) lib/active_support/notifications.rb:52:in `instrument' actionpack (3.0.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.0.8) lib/action_controller/metal/rescue.rb:17:in `process_action' actionpack (3.0.8) lib/abstract_controller/base.rb:119:in `process' actionpack (3.0.8) lib/abstract_controller/rendering.rb:41:in `process' actionpack (3.0.8) lib/action_controller/metal.rb:138:in `dispatch' actionpack (3.0.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.0.8) lib/action_controller/metal.rb:178:in `block in action' actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:62:in `call' actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:62:in `dispatch' actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:27:in `call' rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call' rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize' rack-mount (0.6.14) lib/rack/mount/code_generation.rb:68:in `optimized_each' rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize' rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call' actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:493:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/head.rb:14:in `call' rack (1.2.3) lib/rack/methodoverride.rb:24:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/flash.rb:182:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/cookies.rb:302:in `call' activerecord (3.0.8) lib/active_record/query_cache.rb:32:in `block in call' activerecord (3.0.8) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache' activerecord (3.0.8) lib/active_record/query_cache.rb:12:in `cache' activerecord (3.0.8) lib/active_record/query_cache.rb:31:in `call' activerecord (3.0.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call' activesupport (3.0.8) lib/active_support/callbacks.rb:416:in `_run_call_callbacks' actionpack (3.0.8) lib/action_dispatch/middleware/callbacks.rb:44:in `call' rack (1.2.3) lib/rack/sendfile.rb:107:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/remote_ip.rb:48:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call' railties (3.0.8) lib/rails/rack/logger.rb:13:in `call' rack (1.2.3) lib/rack/runtime.rb:17:in `call' activesupport (3.0.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.2.3) lib/rack/lock.rb:11:in `block in call' <internal:prelude>:10:in `synchronize' rack (1.2.3) lib/rack/lock.rb:11:in `call' actionpack (3.0.8) lib/action_dispatch/middleware/static.rb:30:in `call' railties (3.0.8) lib/rails/application.rb:168:in `call' railties (3.0.8) lib/rails/application.rb:77:in `method_missing' railties (3.0.8) lib/rails/rack/log_tailer.rb:14:in `call' rack (1.2.3) lib/rack/content_length.rb:13:in `call' rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service' /usr/lib/ruby/1.9.2-p180/webrick/httpserver.rb:111:in `service' /usr/lib/ruby/1.9.2-p180/webrick/httpserver.rb:70:in `run' /usr/lib/ruby/1.9.2-p180/webrick/server.rb:183:in `block in start_thread'
got it! wins personal running prize least helpful rails error ... far.
the problem caused because i'd written own task.flactions method in model. once deleted that, worked fine. so, 1 more thing remember never again: don't override methods rails creates you.
incidentally, far can tell, place parent-child forms in rails 3 documented in ri form_for
. there examples there, too. worth looking at.
Comments
Post a Comment