我正在关注一个关于使用dropzone、ruby on rails和Ajax开发像文件共享平台的 DropBox 的教程。我创建了一个 rails 应用程序,将 dropzone 集成到项目中,创建了回形针并上传了模型。在我编辑 UPLOADS_CONTROLLER.RB 文件之前,一切都很好,如下所示:
class UploadsController < ApplicationController
def new
@upload = Upload.new
end
def create
@upload = Upload.create(upload_params)
if @upload.save
render json: { message: "success" }, :status => 200
else
# you need to send an error header, otherwise Dropzone
# will not interpret the response as an error:
render json: { error: @upload.errors.full_messages.join(',')}, :status => 400
end
end
private
def upload_params
params.require(:upload).permit(:image)
end
end
编辑文件后,我重新加载了页面,但出现以下错误。我无法解决问题。谢谢你的帮助!
UploadsController 中的 TypeError #new
superclass mismatch for class Upload
Extracted source(第 3 行附近):
1 类 Upload ApplicationRecord
2 结束
3 类 Upload < ActiveRecord::Base
4 has_attached_file :image, :styles => { :medium => "300x300> ",:thumb => "100x100>" }
5
6 validates_attachment :image,
Application Trace | 框架跟踪 | Full Trace app/models/upload.rb:3:in new'<top (required)>'
app/controllers/uploads_controller.rb:3:in
链接到我提到的教程