Lily
May 31, 2018, 12:44am
1
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appointment.rut_paciente%></td>
<td><%= appointment.fecha %></td>
<td><%= appointment.id_medico %></td>
<td><%= appointment.bloque %></td>
I’m trying to show only some fields from the table appointment, in this case, only those where “appointment.rut_paciente” is not 0. How can I do it?
blatyo
May 31, 2018, 12:50am
2
<%= if appointment.rut_paciente != 0 %>
HTML
<% end %>
Lily
May 31, 2018, 1:02am
3
Thanks! But I already tried that and it doesn’t work :c
<%= for appointment <- @appointments do %>
<%= if appointment.rut_paciente != 0 %>
<tr>
<td><%= appointment.rut_paciente%></td>
<td><%= appointment.fecha %></td>
<td><%= appointment.id_medico %></td>
<td><%= appointment.bloque %></td>
<% end %>
…
<%= if appointment.rut_paciente != 0 do %>
i.e. the do
is missing
1 Like
Lily
May 31, 2018, 1:15am
5
Same error :c Thanks anyway
Do you have a module called Medica.AppointmentView
? You should be getting a compile error if the EEx is invalid. I would add the do
that peerreynders mentioned and do a mix clean
, followed by a mix compile
. If there’s an error you should get a compiler error.
That error usually means that you have a compilation error. You should look at the output from your Phoenix server for the details. You can also try restarting your Phoenix server since that will nicely print out any compilation errors.
Lily
May 31, 2018, 1:26am
8
Thanks! I’ll paste the compilation error:
== Compilation error in file web/views/appointment_view.ex ==
** (SyntaxError) web/templates/appointment/index.html.eex:18: syntax error before: do__EEX__
(eex) lib/eex/compiler.ex:96: EEx.Compiler.generate_buffer/4
(eex) lib/eex/compiler.ex:54: EEx.Compiler.generate_buffer/4
(phoenix) lib/phoenix/template.ex:378: Phoenix.Template.compile/2
(phoenix) lib/phoenix/template.ex:186: anonymous fn/3 in Phoenix.Template.“MACRO-before_compile ”/2
(elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix) expanding macro: Phoenix.Template.before_compile /1
web/views/appointment_view.ex:1: Medica.AppointmentView (module)
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
Lily
May 31, 2018, 1:27am
9
Yes, there is. And it is a compilation error, I hope we can solve this.
blatyo
May 31, 2018, 1:28am
10
Paste the lines around that line in the template
Lily
May 31, 2018, 1:30am
12
<h2 align="center">Modo Administrador</h2>
<h2>Lista de Horas Pedidas</h2>
<table class="table">
<thead>
<tr>
<th>R.U.T. Paciente</th>
<th>Fecha</th>
<th>ID Médico</th>
<th>Bloque</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for appointment <- @appointments do %>
<%= if appointment.rut_paciente != 0 do%>
<tr>
<td><%= appointment.rut_paciente%></td>
<td><%= appointment.fecha %></td>
<td><%= appointment.id_medico %></td>
<td><%= appointment.bloque %></td>
<% end %>
<td class="text-right">
<span><%= link "👁", to: appointment_path(@conn, :show, appointment), class: "btn btn-default btn-xs" %></span>
<span><%= link "🖉", to: appointment_path(@conn, :edit, appointment), class: "btn btn-default btn-xs" %></span>
<span><%= link "✖", to: appointment_path(@conn, :delete, appointment), method: :delete, data: [confirm: "¿Está Seguro?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "Pedir Hora", to: appointment_path(@conn, :new), class: "btn btn-success" %></span>
<span><%= link "Médicos", to: medico_path(@conn, :index), class: "btn btn-primary" %></span>
<span><%= link "Restricción de Horas", to: bnodisponibles_path(@conn, :index), class: "btn btn-primary" %></span>
<span><%= link "Regresar", to: page_path(@conn, :index), class: "btn btn-danger" %></span>
Lily
May 31, 2018, 1:31am
14
This one!
<%= if appointment.rut_paciente != 0 do%>
Thanks for the help <3
blatyo
May 31, 2018, 1:33am
15
Not sure if this is it, but add a space after do
Lily
May 31, 2018, 1:39am
16
Thanks, it actually compiled now
But it still doesn’t do what I need, I don’t know why
I need the column that has a 0 in Rut Paciente to not be seen:
blatyo
May 31, 2018, 1:42am
17
What is the type of the data there? String or Number?
Since it didn’t hide, I suspect you want appointment.rut_paciente != "0"
3 Likes
Lily
May 31, 2018, 1:44am
18
IT WOOOORKED!!! Oh my God, I love you <3
I previously tried ‘0’, and it didn’t work, but now I tried “0” as you said and it worked!!!
1 Like
blatyo
May 31, 2018, 1:45am
19
In elixir '0'
is a character list and "0"
is a string/binary. Unless you’re using an erlang api that asks for it, you pretty much always want a string/binary.
blatyo
May 31, 2018, 1:50am
20
It’s also worth noting that you can filter items in your for comprehension. So, you could just have this line:
<%= for appointment <- @appointments,
appointment.rut_paciente != 0 do %>
<tr> ... </tr>
<% end %>
4 Likes
Lily
June 4, 2018, 4:23pm
21
Excuse me, @blatyo : Is there any way to manipulate each character of that string? Something like:
<%= if appointment.rut_paciente[0]!= “0” do %>
Please, help