Duplicate an association in ruby on rails

1

I have a question. I'vesentthetableI'vealreadydone,butIhaveaproblem,inthecaseof"Isolate's name" "catx" I have two "gene's name" associado, "catxx" e o "catxxx" , but I'm putting both in the same line and I would like to duplicate the line, one for "catxx" and one for the "catxxx". How can I, I can not find the solution. The code I have is:

  <tbody>
    <% if @resists.any? == true%>
    <% @resists.each do |resist| %>
      <tr>
        <td><%= resist.isolated.organism.tax_org if resist.isolated%>
        <td><%= resist.isolated.organism.name if resist.isolated%>
        <td><%= resist.isolated.name if resist.isolated%>
        <td><%= resist.isolated.disease if resist.isolated%>
        <td><%= resist.drug.name%>
        <td><%= resist.drug.reference%>
        <td><%= resist.drug.atc%>
        <td><%if resist.isolated %>
        <% @genes.each do |gene| %>
          <%if resist.isolated.id == gene.isolated_id%>
            <%= gene.name%>
          <%end%>
       <%end%>
       <%end%>
     </td>

@genes, go get the genes all.

I'm doing

<% @genes.each do |gene| %>
          <%if resist.isolated.id == gene.isolated_id%>
            <%= gene.name%>
          <%end%>
       <%end%>

Because an isolate can have multiple genes, and as such, if you do resist.isolated.gene.name it will give me error because it has more than one. But as I am doing it puts me in the same line the genes all of that isolate and I wanted to put each gene in a different line, duplicating the isolate, of course. For example:

123 xpto catx cenas12 navnav 2111 catxx
123 xpto catx cenas12 navnav 2111 catxxx
    
asked by anonymous 16.04.2015 / 19:18

1 answer

0

Assuming that in your Resist.rb model you have:

has_many :genes

and in your Gene.rb

belongs_to :resist

Just by the view:

    <% resist.genes.each do |gene| %>
      <%= gene.name%>
    <%end%>
   </td>
    
06.01.2016 / 01:15