无法使用carrier_wave,s3和activeadmin导轨将图像保存到书中

问题描述

图书课

class Book < ApplicationRecord
  mount_uploader :photo,PhotoUploader
  has_many :images,dependent: :destroy
end

图片类别

class Image < ApplicationRecord
  mount_uploader :photo,PhotoUploader

  belongs_to :book,optional: true
end

PhotoUploader

class PhotoUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  storage :fog

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :medium do
    process resize_to_fit: [300,300]
  end
  version :small do
    process resize_to_fit: [140,140]
  end
  version :thumbnail do
    process resize_to_fit: [64,64]
  end

  def extension_whitelist
    %w(jpg jpeg gif png)
  end
end

schema.rb

  create_table "images",force: :cascade do |t|
    t.bigint "book_id",null: false
    t.string "photo"
    t.datetime "created_at",precision: 6,null: false
    t.datetime "updated_at",null: false
    t.index ["book_id"],name: "index_images_on_book_id"
  end

admin / books.rb

  permit_params :name,:price,:description,:published_year,:width,:heigth,:depth,:material,:category_id,:photo,author_ids: []

form(html: { multipart: true }) do |f|
    f.inputs do
      f.input :photo,required: true,as: :file
    end
    actions
  end

carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: 'AWS',aws_access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),aws_secret_access_key: ENV.fetch('AWS_ACCESS_KEY'),region: 'eu-north-1'
  }
  config.storage = :fog
  config.fog_directory = ENV.fetch('AWS_BUCKET')
end

我正在尝试使用activeadmin将我的图书照片上传到s3,但是它不起作用 我尝试了很多事情。这是最后的选择。 如果可以的话,我将非常感激:) 现在它引发错误: 未定义的方法“ photo_will_change!” for #Book:0x00007f5240c143e8您的意思是? depth_will_change! width_will_change!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)