Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax上传未插入Rails 3中数据库的POST数据_Ajax_File_Ruby On Rails 3_Upload - Fatal编程技术网

Ajax上传未插入Rails 3中数据库的POST数据

Ajax上传未插入Rails 3中数据库的POST数据,ajax,file,ruby-on-rails-3,upload,Ajax,File,Ruby On Rails 3,Upload,我花了很长时间从我的POST数组中获取一个参数并将其插入MySQL数据库。该文件被提交到RAILS 3控制器,该控制器应提取文件名并将其用作SQL语句中的值。这是我的控制器: def upload @item= Item.new(params[:qqfile]) Rails.logger.info("PARAMS: #{params.inspect}") # if params array contains :qqfile unless params[:qqfil

我花了很长时间从我的POST数组中获取一个参数并将其插入MySQL数据库。该文件被提交到RAILS 3控制器,该控制器应提取文件名并将其用作SQL语句中的值。这是我的控制器:

def upload
    @item= Item.new(params[:qqfile])
    Rails.logger.info("PARAMS: #{params.inspect}")
    # if params array contains :qqfile
    unless params[:qqfile].empty?
      # model should:
      # copy file to uploads directory
      render_success
      if @item.save

      else
        render :text => 'database did not save'
      end
      # redirect to render success action
    else
      render :text => '{success:false}'
    end
  end
日志显示查询正在运行,但具有空值:

Started POST "/item/upload?qqfile=1eCH6.jpg" for 127.0.0.1 at Fri Jan 07 09:16:0
9 -0700 2011
  Processing by ItemController#upload as HTML
  Parameters: {"qqfile"=>"1eCH6.jpg"}
PARAMS: {"qqfile"=>"1eCH6.jpg", "controller"=>"item", "action"=>"upload"}
Rendered text template (0.0ms)
  SQL (0.0ms)  INSERT INTO `items` (`name`, `qqfile`, `created_at`, `updated_at`
) VALUES (NULL, NULL, '2011-01-07 16:16:10', '2011-01-07 16:16:10')
Completed 200 OK in 359ms (Views: 16.0ms | ActiveRecord: 0.0ms)

钥匙在数组中。我不明白为什么控制器没有将其值用于SQL查询中的值。

我强烈建议将其用于文件上载。处理上传可能是一件痛苦的事情,而回形针让它变得容易多了。

在这种情况下,它是一种ajax上传,在提交实际表单之前进行。回形针是伟大的,当谈到通用文件上传。。。但是,当您使用进度条执行ajax时,它就不是那么好了。