Unexpected behaviour on embeds_many association

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I have a a model called "Issue", which embeds many "Articles":

      class Issue
      embedded_in :publication
      embeds_many :articles, :as => :articleable, :class_name => 'Article'

      accepts_nested_attributes_for :articles, :allow_destroy => true, :autosave => true
      end

      class Article
      embedded_in :articleable, polymorphic: true

      accepts_nested_attributes_for :article_image, :allow_destroy => true, :autosave => true
      end

      Everything seems to work fine, but then I try to loop through my articles in my view and an extra article gets build with nil values:

      <% issue.articles.each do |article| %>
      <p><%= article.title %></p>
      <% end %>

      I get:

      1. Some value
      2. nil

      Why in the world is this happening? When I query the exact same "Issue" in the database, then only get 1 article.

              Assignee:
              Unassigned
              Reporter:
              holgersindbaek
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: