0

I am trying to print data from a object "root" to a table, everythink work fine but not printing this name i dont know why.

Code :

<% root = NameOfDatabase.find_by_d_id(d.id) %>
            <%  logger.info root.inspect %>
            <% if root.nil? %>
           <td class="col-4"> <% "-" %> </td>
           <%  else %>
           <td class="col-4"> <% root.name %> </td>
           <% end %>

Picture: View

Log file :

...  
#<Name**** id: ****, d_id: ****, name: "Alice", dd_id: ****>
Completed in 99ms (View: 7, DB: 33) | 200 OK [https://*********/dd/search_ajax?option=active&query=s001]

As following in root we have data i want only print root.name in table !!

thanks you

Mhd Jawad
  • 15
  • 4

1 Answers1

1

You need to use <%= %> instead of <% %>

  1. <% %> will just evaluate the expression, it won't output the result to ERB template
  2. <%= %> will evaluate the expression and outputs to ERB template.

Try the below:

<% root = NameOfDatabase.find_by_student_id(student.id) %>
<%  logger.info root.inspect %>
<% if root.nil? %>
<td class="col-4"> <%= "-" %> </td>
<%  else %>
<td class="col-4"> <%= root.name %> </td>
<% end %>

Reference:

What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

user11350468
  • 1,189
  • 1
  • 3
  • 16