ruby on rails - I want to show data from two tables in a single view -


i have 2 tables: 1 named um_org_data , other addresses.

the problem want show data um_org_data addresses addresses has foreign key um_org_datum_id.

here code of view in want show data 2 tables together:

<p id="notice"><%= notice %></p>   <div class="container">   <div class="row">       <div class="span3 pull-right">         <div class="well">           <h2>heading</h2>           <p>sample text</p>         </div>        </div>       <div class="span9">     <h2>organization details</h2>      <table class="table table-hover">       <tr>         <th col span="1" style="width: 200px">             </i>&nbsp;&nbsp;&nbsp;organization name:         </th>         <td><%= @um_org_datum.org_name %></td>       </tr>       <tr>         <th col span="1" style="width: 250px">             </i>&nbsp;&nbsp;&nbsp;organization description:         </th>         <td><%= @um_org_datum.org_description %></td>       </tr>       <tr>         <th col span="1" style="width: 250px">           </i>&nbsp;&nbsp;&nbsp;web domain:         </th>         <td><%= @um_org_datum.webdomain %></td>       </tr>       <tr>         <th col span="1" style="width: 200px">           <%= fields_for :address_attributes |p| %>             <%= p.label 'office address' %><br />                       </th>         <td><%= p.address.offc_addr %></td>         <% end %>       </tr>       <tr>         <th col span="1" style="width: 200px">             </i>&nbsp;&nbsp;office phone number:         </th>         <td><%= @um_org_datum.offc_ph %></td>       </tr>     </table>      <div class="control-group">       <div class="controls">               <a class="btn" href="/um_org_data" style="text-color:black">view all</a>          </div>     </div> </div> </div> </div> 

i don't use join query in controller don't know how use join query. if problem needs join query, please tell me syntax , have change in view form show attributes of both tables.

table name: um_org_data , attributes: id, oeg_name, org_description, webdomain

table name: adrresses , attributes: id, offc_addr, um_org_datum_id

thanks in advance!

do have 1:n association? right?

definitely remove fields_for...you not in form!

change this:

  <tr>     <th col span="1" style="width: 200px">       <%= fields_for :address_attributes |p| %>         <%= p.label 'office address' %><br />                   </th>     <td><%= p.address.offc_addr %></td>     <% end %>   </tr> 

to this:

  <tr>     <th col span="1" style="width: 200px">office address</th>     <%= @um_org_datum.addresses.each |p| %>      <td><%= p.office_addr %></td>     <% end %>   </tr> 

check out markup, logic should clear now..


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -