Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to wrapp your phone_nos into your addresses within the form, and not in the organization.</p> <p>Change this block:</p> <pre><code> &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Office Address&lt;/label&gt; &lt;div class="controls"&gt; &lt;%= f.link_to_add "&lt;i class='icon-plus'&gt;&lt;/i&gt;".html_safe, :addresses%&gt; &lt;%= f.fields_for :addresses do |task_form| %&gt; &lt;div class="input-prepend"&gt; &lt;%= task_form.text_field :offc_addr, :label =&gt; false, :placeholder =&gt; 'Office Address'%&gt; &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Telephone&lt;/label&gt; &lt;div class="controls"&gt; &lt;%= f.link_to_add "&lt;i class='icon-plus'&gt;&lt;/i&gt;".html_safe, :phone_nos%&gt; &lt;%= f.fields_for :phone_nos do |task_form| %&gt; &lt;div class="input-prepend"&gt; &lt;%= task_form.text_field :offc_ph, :label =&gt; false, :placeholder =&gt; 'Office Address'%&gt; &lt;/div&gt; &lt;div class="input-prepend"&gt; &lt;%= task_form.text_field :offc_ext, :label =&gt; false, :placeholder =&gt; 'Office Extension'%&gt; &lt;/div&gt; &lt;div class="input-prepend"&gt; &amp;nbsp;&amp;nbsp; &lt;%= task_form.link_to_remove "&lt;i class='icon-remove'&gt;&lt;/i&gt;".html_safe%&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="input-prepend"&gt; &amp;nbsp;&amp;nbsp; &lt;%= task_form.link_to_remove "&lt;i class='icon-remove'&gt;&lt;/i&gt;".html_safe%&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>to this one:</p> <pre><code> &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Office Address&lt;/label&gt; &lt;div class="controls"&gt; &lt;%= f.link_to_add "&lt;i class='icon-plus'&gt;&lt;/i&gt;".html_safe, :addresses%&gt; &lt;%= f.fields_for :addresses do |task_form| %&gt; &lt;div class="input-prepend"&gt; &lt;%= task_form.text_field :offc_addr, :label =&gt; false, :placeholder =&gt; 'Office Address'%&gt; &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Telephone&lt;/label&gt; &lt;div class="controls"&gt; &lt;%= task_form.link_to_add "&lt;i class='icon-plus'&gt;&lt;/i&gt;".html_safe, :phone_nos%&gt; &lt;%= task_form.fields_for :phone_nos do |phone_no| %&gt; &lt;div class="input-prepend"&gt; &lt;%= phone_no.text_field :offc_ph, :label =&gt; false, :placeholder =&gt; 'Office Address'%&gt; &lt;/div&gt; &lt;div class="input-prepend"&gt; &lt;%= phone_no.text_field :offc_ext, :label =&gt; false, :placeholder =&gt; 'Office Extension'%&gt; &lt;/div&gt; &lt;div class="input-prepend"&gt; &amp;nbsp;&amp;nbsp; &lt;%= phone_no.link_to_remove "&lt;i class='icon-remove'&gt;&lt;/i&gt;".html_safe%&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="input-prepend"&gt; &amp;nbsp;&amp;nbsp; &lt;%= task_form.link_to_remove "&lt;i class='icon-remove'&gt;&lt;/i&gt;".html_safe%&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>For more information about accepts_nested_attributes_for check out the railscasts from ryan bates. <a href="http://railscasts.com/episodes?utf8=%E2%9C%93&amp;search=nested+model+form" rel="nofollow">http://railscasts.com/episodes?utf8=%E2%9C%93&amp;search=nested+model+form</a></p> <p>To check out the API docs: <a href="http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html" rel="nofollow">http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html</a></p> <p>Btw for such basic questions, railscasts.com was always a good point to start for me.</p> <p><strong>UPDATE: To show all phone_nos within the addresses:</strong></p> <p>Simple loop also through the adresses phone_nos</p> <pre><code>&lt;tr&gt; &lt;th col span="1" style="width: 200px"&gt;Office Address: &lt;/th&gt; &lt;td&gt; &lt;% if @um_org_datum.addresses %&gt; &lt;% @um_org_datum.addresses.each do |i| %&gt; &lt;%= i.offc_addr %&gt;&lt;br/&gt; &lt;% i.phone_nos.each do |phone_no| %&gt; &lt;%= phone_no.offc_ph %&gt;&lt;br/&gt; &lt;%= phone_no.offc_ext %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre>
 

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