D
D
dzenn2016-10-28 16:43:56
Ruby on Rails
dzenn, 2016-10-28 16:43:56

How to add multiple images to admin and display them?

ActiveAdmin Admin.
You need to add more than one image, not many. With one, everything is quite simple, but with what is required, it does not work very well

ActiveAdmin.register Subcategory do
  
  permit_params :title, :image, :category_id, :description, :images
  
  index do
    selectable_column
    id_column
    column :category
    column :title
    column :body_text
    column (:images){ |category| image_tag(category.image_url, style: 'width: 100px') if category.image.present? }
    actions
  end
  
  filter :title
  filter :description
  filter :created_at
  
  form html: { multipart: true }  do |f|
    f.inputs  do
      f.input :category
      f.input :title
      f.input :description
      f.input :images, as: :file, input_html: { multiple: true}
    end
    f.actions
  end
  
  show do |cat|
    h3 cat.title
    h3 cat.description
    div.each do |arr_images| # добавления изображений
      image_tag arr_images.category.image_url(:thumb)
    end
  end
end

<% @subcategory.each do |cat| %>
        <div class="block" style="margin-bottom:20px">
          <div class="main-title" data-toggle="modal" data-target="#mdf-modal"><%= cat.title %></div>
          <p><%= cat.description %></p>

          <div class="col-md-3">
            <a href="<%= cat.image_url %>" data-lighter>
              <%= image_tag(cat.image_url, :alt => "ivm logo") %>
              <%= image_tag("zoom.png", :alt => "ivm logo", class: 'zoom') %>
            </a>
          </div>
          <div class="line"></div>
        </div>
        <% end %>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jarosluv, 2016-11-02
@jarosluv

First, try adding an image array to permit_params.

permit_params :title, :category_id, :description, images: []

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question