Forum: Ruby on Rails Nested RESTful Routes and creating a object from XML

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
787da65626a11552602f41351c5c7839?d=identicon&s=25 Chris Williams (cdwillie76)
on 2007-07-28 22:05
I am trying to create a new model from XML that contains has a has_many
relationship.  Is this possible without having to write code to parse
the XML or to doing multiple POSTS?  I can do a post with XML that
doesn't contain any of the has_many elements and it works fine.  It is
when I add the items from the has_many relationship that I get a bunch
of errors.

Here are the examples I am trying

This works...
<manual-track>
  <color>orange</color>
  <comment>This is track 3</comment>
  <rfi-event-id>RFI 3</rfi-event-id>
  <submitter>Joe</submitter>
</manual-track>

This doesn't
<manual-track>
  <color>orange</color>
  <comment>This is track 3</comment>
  <rfi-event-id>RFI 3</rfi-event-id>
  <submitter>Blow</submitter>
  <positions>
    <position>
      <lat type="float">20.0</lat>
      <lon type="float">25.0</lon>
    </position>
    <position>
      <lat type="float">30.0</lat>
      <lon type="float">35.0</lon>
    </position>
  </positions>
</manual-track>

Error from cURL about ActiveRecord::AssociationTypeMismatch in Manual
tracksController#create

this fails too...
<manual-track>
  <color>orange</color>
  <comment>This is track 3</comment>
  <rfi-event-id>RFI 3</rfi-event-id>
  <submitter>Blow</submitter>
  <position>
    <lat type="float">20.0</lat>
    <lon type="float">25.0</lon>
  </position>
  <position>
    <lat type="float">30.0</lat>
    <lon type="float">35.0</lon>
  </position>
</manual-track>

NoMethodError in Manual tracksController#create
  undefined method `position=' for #&lt;ManualTrack:0x47ec8dc&gt;

Any suggestions of what I need to do?
Thanks!
CW
This topic is locked and can not be replied to.