使用载波将图像保存在轨道上的红宝石中并反应图像值为空的问题

问题描述

从反应到后端的数据流还可以,我有204状态代码。在控制台中,我看到图像参数被检测到。

在2020-09-13 17:25:50 +0200开始对:: 1进行POST“ /培训” (0.1ms)选择sqlite_version(*) 由TrainingController#create处理为HTML 参数:{“ description” =>“ test”,“ image” =>“ data:image / png ...(长消息)

最后我看到这些操作

(0.1ms)  begin transaction
↳ app/controllers/training_controller.rb:20:in `create'

Training Create (0.2ms)  INSERT INTO "trainings" ("description","image","created_at","updated_at") VALUES (?,?,?)  [["description","test"],["image",nil],["created_at","2020-09-13 15:25:50.715990"],["updated_at","2020-09-13 15:25:50.715990"]]

↳ app/controllers/training_controller.rb:20:in `create'
(3.9ms)  commit transaction

↳ app/controllers/training_controller.rb:20:in `create'
No template found for TrainingController#create,rendering head :no_content
Completed 204 No Content in 10ms (ActiveRecord: 4.2ms | Allocations: 4126)

现在我们看到我们的对象图像为零,我不知道为什么。 这是我的训练控制器和图片上传

  • 训练控制器

    class TrainingController

    before_action :set_training,only: [:show,:edit,:update]
    
    def index
        @training = Training.all
        Training.order("created_at DESC")
        render json: @training
    end
    
    def show
    end
    
    def new
        @training = Training.new
    end
    
    def create
        training = Training.new(training_params)
        training.save
    end
    
    def edit
    end
    
    def update
        @training.update_attributes(training_params)
    end
    
    private
    
    def training_params
        params.require(:training).permit(:description,:image)
    end
    
    def set_training
        @training = Training.find(params[:id])
    end
    

结束

  • ImageUploader
  attr_accessor :description,:image
  storage :file
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end


what is bad?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)