# Getting AssociationTypeMismatch error when trying to create new object

**URL:** <https://www.ruby-forum.com/t/getting-associationtypemismatch-error-when-trying-to-create-new-object/145579>\
**Category:** Rails\
**Created:** [August 11, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/getting-associationtypemismatch-error-when-trying-to-create-new-object/145579 "2008-08-11T19:29:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 11, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/getting-associationtypemismatch-error-when-trying-to-create-new-object/145579/1 "2008-08-11T19:29:44Z")

</div>

Hi,

I’m trying to create a model, named “form”, which has\_many “form\_item”  
objects. The code is

```
            @form = Form.new(:user_id => session[:user_id],
                             :form_items => params[:form_items])

```

but I get an error, even though I thought I was passing in the  
expected form\_item …

ActiveRecord::AssociationTypeMismatch in FormsController#create

FormItem expected, got HashWithIndifferentAccess

Request

Parameters:

{“commit”=\>“Submit Form”,  
“form\_items”=\>[{“description”=\>“bbb”,  
“prescription\_number”=\>“111”,  
“day\_supply”=\>“20”}]}

Thanks for any input, - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 11, 2008, 7:39pm UTC](https://www.ruby-forum.com/t/getting-associationtypemismatch-error-when-trying-to-create-new-object/145579/2 "2008-08-11T19:39:07Z")

</div>

On 11 Aug 2008, at 18:29, removed\_email\_address@domain.invalid wrote:

> expected form\_item …

Same answer as last time you asked:  
Right now, you’re going to have to iterate over params[:form\_items]  
creating activerecord objects as you go. (Form.new is expecting  
form\_items to actually be an Array of FormItem objects)

Fred
