【问题标题】:empty file upload rails jquery uploader空文件上传rails jquery上传器
【发布时间】:2013-09-17 17:08:48
【问题描述】:

我正在使用带有回形针的 rails jquery 上传。 我的表用created_atuploaded_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

【问题讨论】:

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


    【解决方案1】:

    摆脱所有上传的东西并改变它:上传所以

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

    【讨论】:

      猜你喜欢
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 2017-05-17
      • 1970-01-01
      • 1970-01-01
      • 2014-05-04
      相关资源
      最近更新 更多