Added associations but don't see generated methods

Hi Fred,

I posted four files for easier viewing, I will also post details below, though I find reading them unattractive.

The code in question (I thought) was in app\views\expenses \new.html.erb, specifically the lines:     <%# New version of vendor selection -%>     <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%>     <%= f.collection_select(:vendor_id, @vendors, :id, :nickname) %>     <%# NOTE: first argument, symbol :vendor, does not produce an error here either -%>     <%# End of New version -%> You may download the file in its entirety from

However, the output from the crash indicates the failure was in line 44 of the controller, app\controllers\expenses_controller.rb The code in the neighborhood around line 44 is:   # GET /expenses/1/edit   def edit     @expense = Expense.find(params[:id])   end

  # POST /expenses   # POST /expenses.xml   def create     debugger # <== Line 44     @expense = Expense.new(params[:expense])

    respond_to do |format|       if @expense.save         flash[:notice] = 'Expense was successfully created.'         format.html { redirect_to(@expense) }         format.xml { render :xml => @expense, :status => :created, :location => @expense } Apparently, the crash display-logic doesn't think the "debugger" line merits a line number. You can download the controller in its entirety from:

The dump from the crash is shown below. It strikes me as fairly ugly, so I did screen captures which may be download from:

(My screen-capture utility doesn't support scrolling, so I had to take two images.)

Incidentally, the crash dump includes a display of params[:expense], which includes "vendor"=>"65". That's what I've been trying to get, i.e. the vendor field is now populated with the vendor::id of the vendor I selected in the drop-down, rather than the vendor:nickname that I used to get. Hooray!!

I hope you can define a cause for my current crash. I can't.

Best wishes, Richard

ActiveRecord::AssociationTypeMismatch in ExpensesController#create

Vendor(#37410590) expected, got String(#21132310)

RAILS_ROOT: K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS Application Trace | Framework Trace | Full Trace

K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/association_proxy.rb: 262:in `raise_on_type_mismatch' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/ belongs_to_association.rb:22:in `replace' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations.rb:1281:in `vendor=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2438:in `initialize' K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/ expenses_controller.rb:44:in `new' K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/ expenses_controller.rb:44:in `create'

K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/association_proxy.rb: 262:in `raise_on_type_mismatch' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/ belongs_to_association.rb:22:in `replace' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations.rb:1281:in `vendor=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2438:in `initialize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:1331:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:1331:in `perform_action_without_filters' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/filters.rb:617:in `call_filters' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:10:in `realtime' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:532:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:391:in `process' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:386:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/connection_adapters/abstract/ query_cache.rb:34:in `cache' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/connection_adapters/abstract/ connection_pool.rb:361:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/head.rb:9:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/methodoverride.rb:24:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/lock.rb:11:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/lock.rb:11:in `synchronize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/lock.rb:11:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/rails/rack/static.rb:31:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/urlmap.rb:46:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/urlmap.rb:40:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/urlmap.rb:40:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/rails/rack/debugger.rb:19:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/rails/rack/log_tailer.rb:17:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/content_length.rb:13:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/chunked.rb:15:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/handler/mongrel.rb:64:in `process' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:159:in `process_client' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:158:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:158:in `process_client' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `initialize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `new' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:268:in `initialize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:268:in `new' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:268:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/handler/mongrel.rb:34:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/commands/server.rb:111 K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:31:in `gem_original_require' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:31:in `require' script/server:3

K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/association_proxy.rb: 262:in `raise_on_type_mismatch' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/ belongs_to_association.rb:22:in `replace' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations.rb:1281:in `vendor=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2438:in `initialize' K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/ expenses_controller.rb:44:in `new' K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/ expenses_controller.rb:44:in `create' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:1331:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:1331:in `perform_action_without_filters' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/filters.rb:617:in `call_filters' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:10:in `realtime' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:532:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:391:in `process' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/base.rb:386:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/connection_adapters/abstract/ query_cache.rb:34:in `cache' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/connection_adapters/abstract/ connection_pool.rb:361:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/head.rb:9:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/methodoverride.rb:24:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/lock.rb:11:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/lock.rb:11:in `synchronize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/lock.rb:11:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/rails/rack/static.rb:31:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/urlmap.rb:46:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/urlmap.rb:40:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/urlmap.rb:40:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/rails/rack/debugger.rb:19:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/rails/rack/log_tailer.rb:17:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/content_length.rb:13:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/chunked.rb:15:in `call' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/handler/mongrel.rb:64:in `process' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:159:in `process_client' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:158:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:158:in `process_client' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `initialize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `new' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:285:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:268:in `initialize' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:268:in `new' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5- x86-mswin32-60/lib/mongrel.rb:268:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/ lib/rack/handler/mongrel.rb:34:in `run' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/ lib/commands/server.rb:111 K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:31:in `gem_original_require' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:31:in `require' script/server:3

Request

Parameters:

{"commit"=>"Create", "expense"=>{"category"=>"cat", "account"=>"acc", "mode"=>"cash", "tran_date(1i)"=>"2010", "tran_date(2i)"=>"7", "description"=>"7/17 2238 ", "amount"=>"12.34", "tran_date(3i)"=>"18", "vendor"=>"65", "user_id"=>"rlm"}, "authenticity_token"=>"p0Vg6N2ZxXK/A9d2guWtlmqqsWYo5yj6Ey2+hgmPGCs="}

Show session dump

Hi Fred,

I posted four files for easier viewing, I will also post details below, though I find reading them unattractive.

The code in question (I thought) was in app\views\expenses \new.html.erb, specifically the lines: <%# New version of vendor selection -%> <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%> <%= f.collection_select(:vendor_id, @vendors, :id, :nickname) %> <%# NOTE: first argument, symbol :vendor, does not produce an error here either -%> <%# End of New version -%> You may download the file in its entirety from FileFactory

However, the output from the crash indicates the failure was in line 44 of the controller, app\controllers\expenses_controller.rb The code in the neighborhood around line 44 is: # GET /expenses/1/edit def edit @expense = Expense.find(params[:id]) end

# POST /expenses # POST /expenses.xml def create debugger # <== Line 44 @expense = Expense.new(params[:expense])

respond_to do |format| if @expense.save flash[:notice] = 'Expense was successfully created.' format.html { redirect_to(@expense) } format.xml { render :xml => @expense, :status => :created, :location => @expense } Apparently, the crash display-logic doesn't think the "debugger" line merits a line number. You can download the controller in its entirety from: FileFactory

The dump from the crash is shown below. It strikes me as fairly ugly, so I did screen captures which may be download from: FileFactory FileFactory (My screen-capture utility doesn't support scrolling, so I had to take two images.)

Incidentally, the crash dump includes a display of params[:expense], which includes "vendor"=>"65". That's what I've been trying to get, i.e. the vendor field is now populated with the vendor::id of the vendor I selected in the drop-down, rather than the vendor:nickname that I used to get. Hooray!!

Are you absolutely certain that the trace you show is as a result of the code you have posted? I would have expected the vendor id value (65) to be passed in vendor_id in params not vendor, as that is what you have put in your collection_select. Have a look at the html generated by the collection_select and see if that looks right.

Colin

Before I start, let me mention that I have posted a Microsoft Word document of the following response, along with two relevant files of the app here:

You may wish to download some or all for reference purposes of ease of reading.

Are you absolutely certain that the trace you show is as a result of the code you have posted?

No. When I originally ran the app (and when I ran it just now), I had expense\new.html.erb set with:    <%# New version of vendor selection -%>     <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%>     <%= f.collection_select(:vendor_id, @vendors, :id, :nickname) %>     <%# NOTE: first argument, symbol :vendor, does not produce an error here either -%>     <%# End of New version -%>

Because of “vendor_id” in the collection_select, I get; NoMethodError in Expenses#new Showing app/views/expenses/new.html.erb where line #13 raised: undefined method `vendor_id' for #<Expense:0x47034fc> Extracted source (around line #13): 10: 11: <%# New version of vendor selection -%> 12: <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%> 13: <%= f.collection_select(:vendor_id, @vendors, :id, :nickname) %> 14: <%# NOTE: first argument, symbol :vendor, does not produce an error here either -%> 15: <%# End of New version -%> 16:

But I had originally run it with (and just now changed it to):

    <%# New version of vendor selection -%>     <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%>     <%= f.collection_select(:vendor, @vendors, :id, :nickname) %>     <%# NOTE: first argument, symbol :vendor, does not produce an error here -%>     <%# End of New version -%> where I went back to :vendor (and removed “also” from my comment.

I had changed to vendor_id because that’s what Frederick Cheung suggested, but I apparently changed it after I encountered the error in the Expense controller.

Now with the change back to :vendor and clicking the “Reload current page” icon in Firefox, the Expense\new.html.erb pages is displayed without error. From there I click the down arrow in the item immediately below the Vendor tag and select the item with the vendor nickname “vendor 7/12/2010-1623” and populate the rest of the fields.

Then when I click Create, I get the error display: ActiveRecord::AssociationTypeMismatch in ExpensesController#create Vendor(#37496880) expected, got String(#21132310) RAILS_ROOT: K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS Application Trace | Framework Trace | Full Trace K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/association_proxy.rb: 262:in `raise_on_type_mismatch' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations/ belongs_to_association.rb:22:in `replace' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/associations.rb:1281:in `vendor=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `send' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2746:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `each' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2742:in `attributes=' K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.3.5/lib/active_record/base.rb:2438:in `initialize' K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/ expenses_controller.rb:45:in `new' K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/ expenses_controller.rb:45:in `create' Request Parameters: {"commit"=>"Create", "expense"=>{"category"=>"cat", "account"=>"acc", "mode"=>"cash", "tran_date(1i)"=>"2010", "tran_date(2i)"=>"7", "description"=>"7/12/2010-1623", "amount"=>"12.34", "tran_date(3i)"=>"18", "vendor"=>"65", "user_id"=>"rlm"}, "authenticity_token"=>"p0Vg6N2ZxXK/A9d2guWtlmqqsWYo5yj6Ey2+hgmPGCs="} Show session dump

Then when I click Create, I get the error display: ActiveRecord::AssociationTypeMismatch in ExpensesController#create Vendor(#37496880) expected, got String(#21132310)

This is precisely the error you'll get if you put :vendor (the name of the association) rather than :vendor_id (the name of the attribute). There's a section explaining why this happens in the form helpers guide (at guides.rubyonrails.org )

I presume you *have* got a vendor_id column in the expenses table?

Colin

Hey Fred and Colin,

I presume you *have* got a vendor_id column in the expenses table?

No, I don't. I thought that's the kind of thing was generated dynamically. But now that you ask, I see that dynamic generation of methods would extend to the addition of columns to tables

On second thought, vendor_id should be in the join_table, not in the expense_table. And that's true:

.mysql> show columns in expenses_vendor;

OK Guys,

I think I understand the problem now. We've got to populate the join- table with the ID of the new Expanse record and the ID of the selected Vendor record.

Heretofore, I thought using vendor instead of Fred's vendor_id was cool because: 1. It didn't crash the new Expense record 2. It populated the Expense vendor field with the ID of the selected vendor.

Only now do I see that our goal is to populate the join-table. My idea of qualifying vendor_id as expenses_vendor/:vendor didn't fly. But you guys sound like you've got enough experience in Rails to see through this problem. I keeping my fingers crossed.

Hey Guys,

How about this idea. 1. We revert to vendor as the first arg to collection_select. 2. That populates params["expense"]["vendor"] with the selected vendor's ID 3. We create an observer on the Create button 4. In the observer, we create a new join record and populate it with:     a. The new Expense record's ID     b. The selected vendor's ID     c. Save the the join record.

Ideally, that's what collection_select would do for us if we could invoke it in just the right way.

Any votes in favor of this idea?

Best wishes, Richard

In stead of the observer idea, how about switching to an option containing the link-record creation/population with the caveat that the join-table be checked for the existence of a join-record for the current expense-record ID, offering to overwrite the existing link or canceling the new-link request.

That sounds pretty simple. Any fans of this idea?

Best, Richard

Hey Fred and Colin,

> I presume you *have* got a vendor_id column in the expenses table?

No, I don't. I thought that's the kind of thing was generated dynamically. But now that you ask, I see that dynamic generation of methods would extend to the addition of columns to tables

They aren;t

On second thought, vendor_id should be in the join_table, not in the expense_table. And that's true:

Wrong. You've got a belongs_to/has_many so there is no join table.

So why does: <%# New version of vendor selection -%> <% @vendors = Vendor.find( :all, :order=>"nickname ASC") -%> <%= f.collection_select(:vendor, @vendors, :id, :nickname) %> <%# NOTE: first argument, symbol :vendor, does not produce an error here -%> <%# End of New version -%> fail when I use vendor_id as the first argument of collection_select, i.e.

NoMethodError in Expenses#new

Showing app/views/expenses/new.html.erb where line #13 raised:

undefined method `vendor_id' for #<Expense:0x47fa518>

Because Expense doesn't have a vendor_id method since you haven't added that column to it. I'd recommend having another read of

Fred

I am sorry Richard I have completely lost track of what you are trying to do, and have no idea what the relationships between your models is. Have you worked through Rails Guide on Active Record Relationships? I mean worked through it and understood all the concepts there, and experimented with the code there to see how it all works. If not then I suggest you do it. Then do the same for the other guides there.

When you have done that then hopefully you will have a better idea of how to organise your relationships and what fields you need to put in the tables.

Then I suggest you work right through some tutorials, I like the one at http://railstutorial.org/. The one in Agile Development with Rails is also excellent.

When you have done the above then you should have a much better idea of the basics or Rails. If you still have problems then come back again, with a new thread, and try again.

Colin

OK Fred and Colin,

Problem solved: Throw away the join table; add a vendor_id column to the expense table; use vendor_id in the collection_select method.

This has been a thorn in my side for a long time. I'm so relieved to learn the way out of my dilemma.

Best wishes, Richard