Forum: Ruby on Rails ActiveRecord::AssociationTypeMismatch - unsure how to proceed

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lawrence Lu (Guest)
on 2008-10-28 11:35
(Received via mailing list)
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!
Frederick C. (Guest)
on 2008-10-28 11:40
(Received via mailing list)
On 27 Oct 2008, at 22:44, Lawrence Lu wrote:

>
> @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
This topic is locked and can not be replied to.