我正在使用带有回形针的rails jquery上传。我的表被更新,created_at
但uploaded_at
文件名、文件大小和全部为空。而且我看不到任何上传的文件。
这是我用的宝石
gem 'jquery-rails'
gem 'jquery-fileupload-rails'
gem 'paperclip'
这是我的 uploads_controller
def create
@image = Upload.new(upload_params)
respond_to do |format|
if @image.save
format.html {
render :json => [@image.to_jq_upload].to_json,
:content_type => 'text/html',
:layout => false
}
format.json { render json: {files: [@image.to_jq_upload]}, status: :created, location: @image }
else
format.html { render action: "new" }
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end
因为我使用的是rails,所以我使用了这个
private
def upload_params
params.require(:upload).permit(:post_id,:upload_file_name,:upload_file_size,:upload_content_type,:upload_updated_at)
end
这是我的上传模型
has_attached_file :upload, :styles => { :medium => "300x300>", :thumb => "100x100>" }
include Rails.application.routes.url_helpers
def to_jq_upload
{
"name" => read_attribute(:upload_file_name),
"size" => read_attribute(:upload_file_size),
"url" => upload.url(:original),
"delete_url" => upload_path(self),
"delete_type" => "DELETE"
}
end