使用paperclip和angularjs上传文件

时间:2014-08-02 12:51:12

标签: javascript ruby-on-rails angularjs ruby-on-rails-4 paperclip

我试图在我的rails应用程序中实现此Angularjs上传:

Angular File upload

这是我的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"}}

终端日志:

terminal log

我的html输入:

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

我的带有回形针的专栏是path

我在这个角度剧本中没有得到我的表现。

1 个答案:

答案 0 :(得分:0)

我还没有代表评论,但通常这个错误来自命名问题,请确保您的字段按照约定命名,例如“photo [path]”