簡體   English   中英

使用回形針和angularjs上傳文件

[英]Upload file with paperclip and angularjs

我正在嘗試在我的rails應用程序中實現此Angularjs上傳:

角度文件上傳

這是我的photos_controller:

def create
@photo = current_user.photos.new(photo_params)

respond_to do |format|
  if @photo.save
    format.html { redirect_to @photo, notice: 'Photo was successfully created.' }
    format.json { render action: 'show', status: :created, location: @photo }
  else
    format.html { render action: 'new' }
    format.json { render json: @photo.errors, status: :unprocessable_entity }
  end
end
end

def photo_params
  params.require(:photo).permit(:album_id, :user_id, :title, :description, :path)
end

我認為我已經解決了。 當我嘗試上傳時,出現以下錯誤:

param is missing or the value is empty: photo

Extracted source (around line #92):
9091929394          
# Never trust parameters from the scary internet, only allow the white list through.
def photo_params
  params.require(:photo).permit(:album_id, :user_id, :title, :description, :path)
end
 end

我認為我需要將發送的數據格式化為這樣的格式,不是嗎?

{"photo"=>{"tmpname"=>"253", "etc"=>"1"}}

終端日志:

終端日志

我的html輸入:

<input type="file" nv-file-select="" name="photo[path]" id="photo_path" uploader="uploader" multiple  /><br/>

我的回形針列是path

我沒有在這個角度腳本中做到這一點。

我沒有代表要評論,但是通常此錯誤來自命名問題,請確保您的字段是按照Rails約定命名的,例如“ photo [path]”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM