Skip to main content

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

Gems / Libraries • Asked by Larry Qu

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'

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.