Ask A Question

Notifications

You’re not receiving notifications from this thread.

when use carrierwave to upload mutiple images in one product , the active_admin edit one product page error.

Larry Qu asked in Gems / Libraries

I want to add or upload multiple images in one product, but after I implement this , the active_admin edit product page error.

in products_controller.rb, permit the images , which type is json {images: []}.

    def product_params
      params.require(:product).permit(:name, :description, :price, :main_image, `{images: []}`)
    end

in products/_form.html.erb, I add multiple image upload tag <%= f.file_field :images, multiple: true, class: "form-control" %>

<%= form_for(product) do |f| %>
  <% if product.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:</h2>

      <ul>
      <% product.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field form-group">
    <%= f.label :name %>
    <%= f.text_field :name, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :description %>
    <%= f.text_area :description, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :price %>
    <%= f.text_field :price, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :main_image %>
    <%= f.file_field :main_image, class: "form-control" %>
  </div>

  <div class="field form-group">
    <%= f.label :images %>
    <%= f.file_field :images, multiple: true, class: "form-control" %>
  </div>

  <div class="actions">
    <%= f.submit "update", class: "btn btn-primary" %>
  </div>
<% end %>

when use active_admin to edit one product, error occured
http://localhost:3011/admin/products/4/edit

 Showing /Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/app/views/active_admin/resource/edit.html.arb where line #2 raised:

Unable to find input class JsonInput

Extracted source (around line #336):

        @input_class_finder.find(as)
      rescue Formtastic::InputClassFinder::NotFoundError
        raise Formtastic::UnknownInputError, "Unable to find input #{$!.message}"
      end

      # @api private

Rails.root: /data/ruby-apps/siziwang_travel
Application Trace | Framework Trace | Full Trace

formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:336:in `rescue in namespaced_input_class'
formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:333:in `namespaced_input_class'
formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:342:in `input_class'
formtastic (3.1.5) lib/formtastic/helpers/input_helper.rb:240:in `input'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:330:in `block in fieldset_contents_from_column_list'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:318:in `collect'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:318:in `fieldset_contents_from_column_list'
formtastic (3.1.5) lib/formtastic/helpers/inputs_helper.rb:297:in `inputs'
arbre (1.1.1) lib/arbre/rails/forms.rb:30:in `proxy_call_to_form'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/components/active_admin_form.rb:60:in `inputs'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/pages/form.rb:45:in `block in default_form_config'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/components/active_admin_form.rb:35:in `instance_eval'
/Users/yq/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-6966a84c950b/lib/active_admin/views/components/active_admin_form.rb:35:in `build'
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,842+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.