Created
June 20, 2009 01:51
-
-
Save tispratik/132996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
---------------- | |
<h1>New chapter</h1> | |
<% 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, :id, :display_value, :prompt => 'Select chapter | |
type' | |
%> | |
</p> | |
<p> | |
<%= chapter_form.submit 'Create' %> | |
</p> | |
<% 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 | |
Logs: | |
===== | |
Processing ChaptersController#create (for 127.0.0.1 at 2009-06-19 21:02:28) [POST] | |
Parameters: {"commit"=>"Create", "chapter"=>{"chapter_type"=>"1", "moduls_attributes"=>{"0"=>{"name"=>"t", "level"=>"1", "description"=>"t", "alias"=>"t", "parent"=>"1"}}}, "action"=>"create", "authenticity_token"=>"EV3yhF3gFxf3a6hHwfvfQ15zCFFYx0CXs45IESt+nNU=", "controller"=>"chapters"} | |
[4;36;1mChapter Columns (15.0ms)[0m [0;1mSHOW FIELDS FROM `chapters`[0m | |
[4;35;1mModul Columns (0.0ms)[0m [0mSHOW FIELDS FROM `moduls`[0m | |
ActiveRecord::AssociationTypeMismatch (Modul(#37776460) expected, got String(#21132310)): | |
app/controllers/chapters_controller.rb:47:in `new' | |
Does anyone have an idea about the problem? | |
Thanks in advance, | |
Prats | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment