# AssociationTypeMismatch

**URL:** <https://www.ruby-forum.com/t/associationtypemismatch/170646>\
**Category:** Rails\
**Created:** [June 20, 2009, 2:57am UTC](https://www.ruby-forum.com/t/associationtypemismatch/170646 "2009-06-20T02:57:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tispratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d78d45/32.png) [@tispratik](https://www.ruby-forum.com/u/tispratik)\
**Post date:** [June 20, 2009, 2:57am UTC](https://www.ruby-forum.com/t/associationtypemismatch/170646/1 "2009-06-20T02:57:21Z")

</div>

Am getting the following error:  
Modul(#36555780) expected, got String(#21132310)

After doing a lot of research on the net, i found that i need to pass  
on the id field somehow, but i dont really know how to do it.

## Following is the model:

class Modul \< ActiveRecord::Base  
belongs\_to :modulable, :polymorphic =\> true  
end

class Chapter \< ActiveRecord::Base  
has\_many :moduls, :as =\> :modulable  
accepts\_nested\_attributes\_for :moduls  
end

## New Page:

# New chapter

\<% form\_for @chapter do |chapter\_form| %\>  
\<%= chapter\_form.error\_messages %\>

```
<% chapter_form.fields_for :moduls do |modul_form| %>
  <p>
    <%= modul_form.label :name %><br />
    <%= modul_form.text_field :name %>
  </p>
  <p>
    <%= modul_form.label :alias %><br />
    <%= modul_form.text_field :alias %>
  </p>
  <p>
    <%= modul_form.label :description %><br />
    <%= modul_form.text_field :description %>
  </p>
  <p>
    <%= modul_form.label :level %><br />
    <%= modul_form.select :level, %w{ nil 0 1 2 3 } %><br />
  </p>
  <p>
    <%= modul_form.label :parent %><br />
    <%= modul_form.text_field :parent %>
  </p>
  <% end %>
 <p>
<%= chapter_form.label :chapter_type %><br />
<%=

```

#@decodes = Decode.find(:all, :conditions =\> {:name =\>  
“Chapter\_Type”, :is\_active =\> 1 })  
@decodes = Decode.all(:conditions =\> {:name =\>  
“Chapter\_Type”, :is\_active =\> 1 })  
chapter\_form.collection\_select :chapter\_type,  
@decodes, :internal\_value, :display\_value, :prompt =\> ‘Select module  
type’  
%\>

\<%= chapter\_form.submit 'Create' %\>

\<% end %\>

\<%= link\_to ‘Back’, chapters\_path %\>

## Controller:

class ChaptersController \< ApplicationController

def create  
@chapter = Chapter.new(params[:chapter])

```
respond_to do |format|
  if @chapter.save
    flash[:notice] = 'Chapter was successfully created.'
    format.html { redirect_to(@chapter) }
    format.xml { render :xml => @chapter, :status

```

=\> :created, :location =\> @chapter }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @chapter.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end

end

Does anyone have an idea about the problem?

Thanks in advance,  
Pratik
