1

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
ipatch
  • 3,933
  • 8
  • 60
  • 99
  • If the response at the edit url comes back as json, then you are presumably submitting an ajax request. If you want the html response, then send a non-ajax request. – Les Nightingill Nov 10 '15 at 14:37
  • The question has little to be about refile, really. It is very probable that you are either requesting the .json through CURL or your APIController is set to respond by JSON by default. – Lomefin Dec 08 '15 at 18:45

0 Answers0