json - Creating a collection of nested resources in roar-rails -


i trying create new objects collection of nested resources. when post json, get:

activerecord::associationtypemismatch: formlabel(#70306552439440) expected, got hash(#70306480154920) 

here's code:

# form.rb class form < activerecord::base   has_many :form_labels   validates_presence_of :name end  # form_label.rb class formlabel < activerecord::base   belongs_to :form   validates_presence_of :form   validates_presence_of :text end  # form_representer.rb module formrepresenter   include roar::json   property :id   property :name   collection :form_labels end  # form_label_representer.rb module formlabelrepresenter   include roar::json   property :text   end  # form_controller.rb class formscontroller < applicationcontroller   include roar::rails::controlleradditions   def create     form = form.new     consume!(form)     respond_with(form)   end 

when debug, these params:

0> params => {"name"=>"address", "form_labels"=>[{"text"=>"foo"}], "format"=>"json", "controller"=>"forms", "action"=>"create", "form"=>{"name"=>"address"}} 

and error is:

activerecord::associationtypemismatch: formlabel(#70237358584300) expected, got hash(#70237286721880) 

the error in line:

collection :form_labels 

it needs be:

collection :form_labels, decorator: formlabelrepresenter, class: formlabel 

see https://github.com/apotonick/roar-rails/issues/125#issuecomment-172175231


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -