How can I edit / destroy an attachment uploaded via refile within a rails app? I can successfully create attachments from curl, but I can't figure out how to delete them. I read the refile documentation on removing attachments here, https://github.com/refile/refile#removing-attached-files but when I load the following URL http://localhost:3000/api/csv_files/1/edit it is sending a JSON response to my browser, and the rails app is not rendering the edit.html.erb
template instead it renders a edit.json.jbuilder
template.
# 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