upload pdf ruby on rails

0

I am in need of uploading pdf files to the system made in ruby on rails. I can do this with the images however with pdf files I can not.

I'm using carriwave. report_uploader.rb

class ReportUploader < CarrierWave::Uploader::Base
  include CarrierWave::Compatibility::Paperclip

  
  storage :file
  
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  
  def extension_whitelist
     %w(html ppt pdf docx xlsx csv txt)
  end

end

organ.rb

mount_uploader :report, ReportUploader

validates_processing_of :report
validate :file_size_validation


private
    def file_size_validation
      errors[:report] << "Tamanho deve ser menor que 500 Mb" if report.size > 0.5.megabytes
    end

organ_controller.rb

def uploader
    organ = Admin::Organ.find(params[:organ_id])
    organ.attachment = params[:file]

    render json: organ.save
  end

  def uploader_file
    organ_file = Admin::Organ.find(params[:organ_id])
    organ.report = params[:file]

    render json: organ_file.save
  end

I have a field called attachmet that is image, this works, I passed the files so they can see. there is still the angularjs configuration, it follows:

app.controller('OrgansEditController', ['$scope', '$http', '$location', 'Organ', 'FileUploader', function($scope, $http, $location, Organ, FileUploader) {
	$scope.loadOrgan = function (organ_id) {
    $scope.organ = Organ.get({id: organ_id});
  };

  var uploader = $scope.uploader = new FileUploader({
    url: '/admin/organs/uploader'
  });

  uploader.onBeforeUploadItem = function(item) {
    item.formData.push({organ_id: $scope.organ.id});
  };

  var uploader_file = $scope.uploader_file = new FileUploader({
    url: '/admin/organs/uploader_file'
  });

  uploader_file.onBeforeUploadItem = function(item) {
    item.formData.push({organ_id: $scope.organ.id});
  };

$scope.save = function() {
    $scope.uploader.uploadAll();
    $scope.uploader_file.uploadAll();
		Organ.update($scope.organ, function() {
      return window.location = '/admin/organs';
    });
    Organ.update_file($scope.organ, function() {
      return window.location = '/admin/organs';
    });
	};

This is the structure, when I send save it passes the form but does not save the field report.

    
asked by anonymous 04.04.2018 / 20:51

0 answers