Pergunta

I've got a load of clients in an each which I want to be able to loop(or show one) on different occassions. I thought I was clever and use a partial for a single client.

It seems that the partial is not being rendered though. If I just but some plain 'asd' in it or the real deal it shows nothing on my page either way.

I'm pretty sure there are clients present though.

Is there something wrong with my code?:

my clients/index.html.erb

<% @usersGroups.each do |group| %>
  <h1><%= group.name %></h1><br><br>
  <% if group.clients.length > 0 %>
    <% group.clients.each do |client| %>
      <% render partial: 'single_client', locals: {cl: client} %>
    <% end %>
  <% else %>
    Nog geen clienten in deze groep.
  <% end %>
<% end %>

and my clients/_single_client.html.erb

xx<%= cl %> xx
<%= link_to(cl.name, edit_client_path(cl)) %>
<br>
<% if cl.avatar %>
    <img src="<%= cl.avatar %>" width="80">
<% end %>
<br>
<%= cl.birthdate.strftime("%d-%m-%Y")%>
<br>
<% if cl.background %>
<div style="border: 1px solid #000; width: 30px; height: 30px; background: <%= cl.background %>"></div>
<% end %>

<br><br>
<%= link_to(cl.group.name, group_path(cl.group)) if cl.group %><br>
<%= link_to 'Verwijder', cl, method: :delete, data: { confirm: "Weet u zeker dat u #{cl.name} wil verwijderen?" } %>

I've tried using render 'single_client' aswell, to no avail.

Foi útil?

Solução

Instead of

<% group.clients.each do |client| %>
  <% render partial: 'single_client', locals: {cl: client} %>
<% end %>

try

<%= render partial: 'single_client', collection: group.clients %>

Outras dicas

Replace:

<% render partial

With:

<%= render partial
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top