0

I have a basic file upload with carrierwave:

uploaders/image_uploader.rb:

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  storage :file
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

models/event.rb:

class Event < ActiveRecord::Base
  ...
  mount_uploader :picture, ImageUploader
end

I can upload an image with a form in the app (not the admin part) and it works fine. I see the image path in the picture field in ActiveAdmin.

But I cannot change the picture field directly in ActiveAdmin. I tried to create a new event with an image, or change an existing event. If an image was present, it stayed the same. If there were no image previously, no image were added. In short, I can view the picture field in ActiveAdmin, but I cannot change it. This is the case only for the picture field (I can change the other fields)

Note: No upload starts when I submit the form (I don't see the uploading xx% in the bottom left of chrome). I also tried other browers, same behaviour. I get no errors in the rails server console.

admin/events.rb:

ActiveAdmin.register Event do
  permit_params :user_id, :category_id, :name, :date, :description, :text, :picture

 # tried adding this, form still works, but image still doesn't work.
 form multipart: true do |f|
    f.inputs "Event details" do
      f.input :category_id
      f.input :name
      f.input :description
      f.input :picture, as: :file
    end
    f.actions
  end
end

Why can't I change the picture field in ActiveAdmin ?

Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236

2 Answers2

2

The problem was the same as in this question: File upload with Activeadmin Rails using paperclip

Changing admin/events.rb to this made the upload work:

ActiveAdmin.register Event do
  permit_params :user_id, :category_id, :name, :date, :description, :text, :picture

  form :html => { :enctype => "multipart/form-data" } do |f| # <--- changed
    f.inputs "Event details" do
      ...
    end
    f.actions
  end
end
Community
  • 1
  • 1
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
0

Issue #3577 was open for this on GitHub and a PR was merged earlier today.

Piers C
  • 2,880
  • 1
  • 23
  • 29