Duplicate a ruby membership on Rails

Asked

Viewed 50 times

1

I’m having a doubt.inserir a descrição da imagem aqui I send the table I already made, but I have a problem in the case of "Isolate's name" "catx" have two "gene's name" associado, "catxx" e o "catxxx", but I’m putting the two in the same line and I’d like to duplicate the line, one for the "catxx" and one for the "catxxx". As I do, I’m not finding 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, get all the genes.

I’m making

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

because an isolate can have several genes, and as such, if I do so Resist.isolated.gene.name will give me error because it has more than one. But as I’m doing, it puts all the genes in that isolate in the same line, and I wanted to put each gene in a different line, doubling the isolate, of course. For example:

123 xpto catx cenas12 navnav 2111 catxx
123 xpto catx cenas12 navnav 2111 catxxx

1 answer

0

assuming that in your Resist.Rb model you have:

has_many :genes

and your Gene.Rb

belongs_to :resist

just put in the view:

    <% resist.genes.each do |gene| %>
      <%= gene.name%>
    <%end%>
   </td>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.