Note that there are some explanatory texts on larger screens.

plurals
  1. POstore values in multiple table with circular dependency in rails
    primarykey
    data
    text
    <p>I have created Three tables with attributes are following:</p> <p>Table name: <code>um_org_data</code> , attributes: <code>id, org_name, org_description, webdomain</code></p> <p>Table name: <code>addresses</code> , attributes: <code>id, offc_addr, um_org_datum_id</code></p> <p>Table name: <code>phone_nos</code> , attributes: <code>offc_ph, offc_ext, address_id</code></p> <p>Now I want that my organization with a name has multiple address means <code>Organization 1:M addresses</code> and address has multiple telephone numbers means <code>address 1:M telephone_no</code></p> <p>The code from my controllers are following: </p> <p>um_org_datum.rb</p> <pre><code>class UmOrgDatum &lt; ActiveRecord::Base attr_accessible :org_description, :org_name, :webdomain, :addresses, :addresses_attributes has_many :addresses accepts_nested_attributes_for :addresses end </code></pre> <p>addresses.rb</p> <pre><code>class Address &lt; ActiveRecord::Base attr_accessible :offc_addr belongs_to :um_org_datum has_many :phone_nos accepts_nested_attributes_for :phone_nos end </code></pre> <p>phone_no.rb</p> <pre><code>class PhoneNo &lt; ActiveRecord::Base attr_accessible :offc_ph, :offc_ext belongs_to :address end </code></pre> <p>as association with organization and addresses is working fine... but having problem in creating multiple telephone numbers.</p> <p>the code for my view is as following: </p> <pre><code>&lt;%= simple_nested_form_for(@um_org_datum) do |f| %&gt; &lt;%= f.error_notification %&gt; &lt;div class="container"&gt; &lt;div class="row"&gt; &lt;div class="span3 pull-right"&gt; &lt;div class="well"&gt; &lt;h2&gt;Heading&lt;/h2&gt; &lt;p&gt;Sample text&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="span9"&gt; &lt;%= simple_nested_form_for(@um_org_datum, :validate =&gt; true, :html =&gt; { :class =&gt; 'form-horizontal' }) do |f| %&gt; &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Organization Name&amp;nbsp;&lt;/label&gt; &lt;div class="controls"&gt; &lt;div class="input-prepend"&gt; &lt;%= f.text_field :org_name, required: true, :autofocus =&gt; true %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Orgazination Description&amp;nbsp;&lt;/label&gt; &lt;div class="controls"&gt; &lt;%= f.text_area :org_description, :cols =&gt; "100", :rows =&gt; "10" %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Web Domain&amp;nbsp;&lt;/label&gt; &lt;div class="controls"&gt; &lt;div class="input-prepend"&gt; &lt;%= f.text_field :webdomain, required: true, :autofocus =&gt; true %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &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; &lt;div class="control-group"&gt; &lt;label class="control-label"&gt;Office Phone Number&amp;nbsp;&lt;/label&gt; &lt;div class="controls"&gt; &lt;div class="input-prepend"&gt; &lt;%= f.text_field :offc_ph, required: true, :autofocus =&gt; true %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;% if @um_org_datum.id == nil%&gt; &lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt; &lt;% else %&gt; &lt;button class="btn btn-primary" type="submit"&gt;Update&lt;/button&gt; &lt;% end %&gt; &lt;a class="btn" href="/um_org_data" style="text-color:black"&gt;Cancel&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Now what i want to do is that i have three tables which are circular dependent on each other.... <code>organization</code> table which has primary key that uses in <code>addresses</code> table as foreign key and has own primary key which is used in <code>phone_nos</code> table as foreign key.</p> <p>I wants a form in which when click on + button under address show telephone label with + button where user can add multiple telephones against single address.. all is that.</p>
    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. 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