Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Can you try the following?</p> <pre><code>class Publication &lt; ActiveRecord::Base attr_accessible :title, :publication_contributors_attributes has_many :publication_contributors has_many :authors, through: :publication_contributors, source: :contributor, conditions: { publication_contributors: { contributor_type: 'Author' } } has_many :translators, through: :publication_contributors, source: :contributor, conditions: { publication_contributors: { contributor_type: 'Translator' } } accepts_nested_attributes_for :publication_contributors end class Contributor &lt; ActiveRecord::Base attr_accessible :name has_many :publications, through: :publication_contributors has_many :publication_contributors end class PublicationContributor &lt; ActiveRecord::Base attr_accessible :contributor_type belongs_to :publication belongs_to :contributor accepts_nested_attributes_for :contributor end &lt;%= form_for @publication, :remote =&gt; true do |f| %&gt; &lt;%= f.label :title %&gt;: &lt;%= f.text_field :title %&gt; &lt;%= f.fields_for :publication_contributors do |pc_form| %&gt; &lt;%= pc_form.hidden_field :contributor_type %&gt; &lt;%= pc_form.fields_for :contributor do |c_form| %&gt; &lt;%= c_form.label :name, "Author" %&gt;: &lt;%= c_form.text_field :name %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;%= f.submit %&gt; &lt;% end %&gt; </code></pre> <p>UPDATE: controller code</p> <pre><code>@publication.publication_contributors.build @publication.publication_contributors.each do |pc| pc.build_contributor end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload