1

I usually always used Carrierwave with Rails <=4, but am now working on a Rails 5 project. I can't upload images anymore and I am getting multiple errors (Tried in ActiveAdmin (undefined method map and Seed File). Does anyone know how where the error is?

Versions used:

Ruby 2.4.1p111
Rails 5.02
Carrierwave 1.1.0
ActiveAdmin from Github Master Repo

As usual I generated my Uploaders and mounted them to my model.

uploaders/StoreImageUploader.rb

class StoreImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Create different versions of your uploaded files:
  version :thumb do
    process resize_to_fit: [250, 250]
  end

end

models/store.rb

class Store < ApplicationRecord
  mount_uploaders :image, StoreImageUploader
  serialize :image, JSON # If you use SQLite, add this line.
  belongs_to :organization
  has_many :orders
end

Usually ActiveAdmin detects that mounted uploaders and sets the image:string field to :file, automatically, but not this time.

I manually adjusted the active admin file.

admin/store.rb

ActiveAdmin.register Store do
permit_params :name , :image
  form(:html => { :multipart => true }) do |f|
    f.inputs "Store" do
      f.input :name
      f.input :image, :as => :file
    end
    f.button "Create"
  end
end

When uploading I get following error:Active Admin Upload

zer02
  • 3,963
  • 4
  • 31
  • 66

1 Answers1

0

Solved, It was a typo error mount_uploaders

zer02
  • 3,963
  • 4
  • 31
  • 66