ActiveRecord::UnknownAttributeError

纵然是瞬间 提交于 2019-12-04 07:45:00

ActiveRecord::UnknownAttributeError means that you're missing a field in the database. Looks like you missed a field when you were setting up your polymorphic relationship, or you forgot to run your migrations.

See also: http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

try to create a file names app/uploaders/photo_uploader.rb

# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base
  # Include RMagick or MiniMagick support:
  include CarrierWave::RMagick
  # include CarrierWave::MiniMagick
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper
  include CarrierWave::MimeTypes
  process :set_content_type
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  def extension_white_list
     %w(jpg jpeg gif png)
  end
# process :resize_to_fit => [800, 800]

  version :thumb do
    process :resize_to_limit => [50, 50]
  end
end

then in your model add

mount_uploader :image, PhotoUploader
mount_uploader :image2, PhotoUploader

you probably have this

/config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.storage = :fog
  config.fog_credentials = {
    :provider => 'AWS',
    :aws_access_key_id => ENV['CARRIER_WAVE_ACCESS_KEY'],
    :aws_secret_access_key => ENV['CARRIER_WAVE_SECRET_ACCESS_KEY']
  }
  config.cache_dir = "#{Rails.root}/tmp/uploads"
  config.fog_directory = ENV['CARRIER_WAVE_BUCKET']
  config.fog_attributes = { 'Cache-Control'=>'max-age=315576000' }
  #config.fog_public = false # optional, defaults to true
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!