空文件上传rails jquery uploader

时间:2013-09-17 17:08:49

标签: jquery jquery-file-upload jquery-fileupload-rails

我正在使用带有paperclip的rails jquery upload。 我的表更新为created_atuploaded_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

1 个答案:

答案 0 :(得分:0)

摆脱所有上传内容并更改它:上传所以

params.require(:upload).permit(:post_id,:upload)