jppag
jppag

Reputation: 37

Rails 4 not displaying conditions when uploading images with carrierwave

I am doing a website for a PR agency, and they have multiple clients (called cliente). Each of these clients has an image gallery (called cliente_photos) of their own. I am using carrierwave and active_admin to upload through an admin. In the active_admin, I am able to set for with client I want the new uploaded picture to be related with. But on my views, All clients show all images. I assume it is an array conditions problem, but I can't get that to work.

My index view looks like this:

 <div class="image-grid mt-60">
     <% Cliente.all.each do |client| %>
        <% client.cliente_photos.each do |photo| %>
           <div class="mb-5 pull-left">
              <%= image_tag photo.imagem.url %>
           </div>
        <% end %>
     <% end %>
 </div>

When I try to use conditionals like:

`<div class="image-grid mt-60">
   <% Cliente.all.each do |client| %>
     <% client.cliente_photos.where("cliente_id = ?", params[:cliente_id]).each do |photo| %>
       <div class="mb-5 pull-left">
          <%= image_tag photo.imagem.url %>
       </div>
     <% end %>
   <% end %>
</div>`

The images disappear from all clients.

Any ideas?

Upvotes: 1

Views: 155

Answers (1)

PinnyM
PinnyM

Reputation: 35533

If you start with Cliente.all, you should expect all client images. If that's not what you wanted, why not filter on the one you do want?

<div class="image-grid mt-60">
  <% client = Cliente.find(params[:cliente_id]) %>
  <% client.cliente_photos.each do |photo| %>
       <div class="mb-5 pull-left">
          <%= image_tag photo.imagem.url %>
       </div>
  <% end %>
</div>

Upvotes: 1

Related Questions