如何在rails应用程序中编辑/销毁通过refile上传的附件?我可以从curl成功创建附件,但我无法弄清楚如何删除它们。我在这里阅读了关于删除附件的refile文档,https://github.com/refile/refile#removing-attached-files但是当我加载以下网址http://localhost:3000/api/csv_files/1/edit时,它正在向我的浏览器发送JSON响应,并且rails应用程序未呈现edit.html.erb
模板而不是它呈现edit.json.jbuilder
模板。
#csv_files_controller.rb
def edit
@csv_file = CsvFile.find(params[:id])
respond_to do |format|
format.html { render html: @csv_file.as_html(only: [:id]) }
format.json { render json: @csv_file.as_json(only: [:id]) }
# format.json { render action: 'edit'}
# else
# format.html { render action: 'edit' }
# format.json { render json: @csv_file.errors, status: :unprocessable_entity}
end
end
# DELETE /csv_files/1
# DELETE /csv_files/1.json
def destroy
@csv_file = CsvFile.find(params[:id])
if @csv_file.destroy
render :json => { :head => ok }, status: 200
else
render json: {error: "csv file could not be deleted."}, status: 422
end
end
private
def csv_params
# binding.pry
params.permit(:csv_file, :csv_file_filename, :csv_file_id, :csv_file_content_type, :remove_csv_file)
end
end