Lawrence Lu
2008-Oct-27 22:44 UTC
ActiveRecord::AssociationTypeMismatch - unsure how to proceed
I''m creating a practice app on RoR, but i''ve run into this problem and I''m not sure how to proceed. Basically, its a stock picker, and there are Portfolios, Stocks, and Holdings. Holdings belong to both Portfolios and a particular Stock. In my "create holding" page, i''m allowing the user to provide a Stock symbol (a string column in the stock table) and a quanity. However, for obvious reasons this doesnt work as when the form is submitted, this line: @holding = Holding.new(params[:holding]) Expects the value of "stock" that is passed in to be an actual Stock object, not a string representing the symbol for that stock. How exactly should I get around this without converting the Stock field to a dropdown? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-28 09:39 UTC
Re: ActiveRecord::AssociationTypeMismatch - unsure how to proceed
On 27 Oct 2008, at 22:44, Lawrence Lu wrote:> > I''m creating a practice app on RoR, but i''ve run into this problem and > I''m not sure how to proceed. Basically, its a stock picker, and there > are Portfolios, Stocks, and Holdings. Holdings belong to both > Portfolios and a particular Stock. > > In my "create holding" page, i''m allowing the user to provide a Stock > symbol (a string column in the stock table) and a quanity. However, > for obvious reasons this doesnt work as when the form is submitted, > this line: > > @holding = Holding.new(params[:holding])> Expects the value of "stock" that is passed in to be an actual Stock > object, not a string representing the symbol for that stock. >change params[:holding][:stock] before you pass it to Holding.new Fred> How exactly should I get around this without converting the Stock > field to a dropdown? > > Thanks! > > >--~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---