Folks,
I am on Rails 2.3.8. I have models declared as below
class GradeSection < ActiveRecord::Base
has_many :class_calendars
end
class ClassCalendar < ActiveRecord::Base
has_many :uploaded_attachments, :class_name => ‘UploadedAttachment’
accepts_nested_attributes_for :uploaded_attachments
belongs_to :grade_section
end
class UploadedAttachment < ActiveRecord::Base
belongs_to :class_calendar
has_attached_file :phile,
:url => “/assets/class_cal/:id/:style/:basename.:extension”
end
In my create function in GradeSection controller I get data posted as
such
Processing GradeSectionController#create (for 127.0.0.1 at 2010-11-27
22:13:46) [POST]
Parameters:
{“authenticity_token”=>“fwdgGanIsScNQUcm6sYc952xhT2BSVH6LXggOJdxhKo=”,
“class_calendar”=>{“dt”=>“Mon Dec 13 2010 22:13:35 GMT-0800 (Paci
fic Standard Time)”, “summary”=>"", “grade_section_id”=>“1”,
“chkproj”=>“0”, “uploaded_attachments”=>{“name”=>“Test 2”},
“chkhw”=>“1”}}
“name” is a string field for filename in UploadedAttachments model (I
am going to use that model for storing uploaded attachments but taking
incremental steps - getting just the name for now) and
grade_section_id is passed in so I create the model through
ClassCalendar
When I get the above posted data, in the create function of
GradeSectionController, I create a ClassCalendar object from params
that are submitted as below
@cc = ClassCalendar.new(params[:class_calendar]) # line 96 in the
code
But this line gives me the following error
#================= Error Message =======================
ActiveRecord::AssociationTypeMismatch (UploadedAttachment(#90313070)
expected, got Array(#1200170)):
app/controllers/grade_section_controller.rb:96:in new' app/controllers/grade_section_controller.rb:96:in
create’
c:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/lib/ruby-
debug.rb:101:in debug_load' c:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/lib/ruby- debug.rb:101:in
debug_program’
c:/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/bin/rdebug-ide:
82
c:\ruby\bin\rdebug-ide:19:in load' c:\ruby\bin\rdebug-ide:19 -e:2:in
load’
-e:2
#================= end error message =======================
I may be missing something very simple but I don’t understand the
error and don’t quite know how to debug this - getting an Array
instead of UploadedAttachment. Looking for help with any pointers on
what the issue is and how to debug such errors.
Thanks,
-S