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!

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