我正在使用带有paperclip的rails jquery upload。
我的表更新为created_at
和uploaded_at
,但file_name,file_size和所有为空。我看不到上传的文件。
这是我使用的宝石
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
答案 0 :(得分:0)
摆脱所有上传内容并更改它:上传所以
params.require(:upload).permit(:post_id,:upload)