On 18 Jul 2010, at 18:55, RichardOnRails <richarddummymailbox58...@uscomputergurus.com> wrote:
> > > 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 ) > 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 > --- > Response > Headers: > {"Content-Type"=>"", > "Cache-Control"=>"no-cache"} > > For some reason, this above dump does not display line 45 nor its > context. But the relevant portion of app\controllers > \expenses_controller.rb is shown here: > # POST /expenses > # POST /expenses.xml > def create > debugger > @expense = Expense.new(params[:expense]) # <== Line 45 > ***************** > > 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 } > else > format.html { render :action => "new" } > format.xml { render :xml => @expense.errors, :status > => :unprocessable_entity } > end > end > end > > I note that the params["expense"]["vendor"]=>"65", which I view as > almost perfect, i.e. it’s a vendor ID as opposed to a vendor > nickname. But is it the ID matching my selection? > > It is indeed, as witnessed by the fact: > mysql> select * from vendors; > +----+-----------------------+---------------------------------- > +---------------------+---------------------+ > | id | nickname | qbname | > created_at | updated_at | > +----+-----------------------+---------------------------------- > +---------------------+---------------------+ > | 62 | vendor 5/15/2010 | Test new field names | > 2010-05-15 16:30:11 | 2010-05-15 16:30:11 | > | 63 | vendor 5/21/2010 | Testing pre-plugin version | > 2010-05-21 19:38:36 | 2010-05-21 19:38:36 | > | 64 | Z01-2010.06.26 | Z01-Test | > 2010-06-26 14:28:11 | 2010-06-26 14:28:11 | > | 65 | vendor 7/12/2010-1623 | Just a test of "belongs_to", etc | > 2010-07-12 20:25:05 | 2010-07-12 20:35:11 | > +----+-----------------------+---------------------------------- > +---------------------+---------------------+ > > I hope you can see what's wrong here. Maybe I should just rebuild the > Expense portion in its entirety, now that I'm so close to getting the > ID of a selected vendor to appear ready to be saved in new expense > records. > > Best wishes, > Richard > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.