Home Rails loop thru attachments and show the first
Reply: 0

Rails loop thru attachments and show the first

user997 Published in March 19, 2018, 12:57 am

I have implemented a basic search and I would like to show each result aligned with an image. I'm using the carrierwave gem on my app and trying loop thru attachments in order to show only the first one as thumbnail.

<div class="container">
  <div class="img-thumbnail" style="display: inline-block;">
    <% if @items.present? %>
        <% @items.each do |item| %>
        <% item.attachments.each do |attachment| %>
            <%= image_tag attachment.url(:mini).first unless attachment.blank? %>
            <% end %>
      <% end %>
   <% end %>

create_table "items", force: :cascade do |t|
  t.string "title"
  t.string "description"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.json "attachments"

But unfortunately the image does not show, no errors etheir just a blank thumbnail. Any ideas how to implement this?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.331486 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO