我之前从未见过这个错误,undefined method 'attachment_will_change!' for #<Movie:0x00000106b16000>
可能与carrierwave有关。
电影模特中的参数。
def movie_params
params.require(:movie).permit(:title, :rating, :total_gross, :attachment)
end
初始化程序中的carrierwave.rb。
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'abc', # required
:aws_access_key_id => 'abcabc', # required
:aws_secret_access_key => 'abcabcabc', # required
}
config.fog_directory = 'abcabc' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
imageuploader
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fit => [50, 50]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
答案 0 :(得分:3)
正如我所说,您在attachment
表中缺少movies
属性。您必须添加attachment
列才能修复该错误。
未定义的方法&#39; attachment_will_change!&#39;
通过以下命令生成迁移文件
rails g migration AddAttachementToMovies attachement:string
它将生成类似这样的迁移文件
class AddAttachmentToMovies < ActiveRecord::Migration
def change
add_column :movies, :attachment, :string
end
end
然后执行rake db:migrate
<强> Source 强>