Images are not uploaded only when updated

Asked 2 years ago, Updated 2 years ago, 129 views

Prerequisites/What you want to achieve

I'm creating an app with Ruby on Rails.
There is a model that allows you to register images, but once you delete the image and start with nothing, you can register the image normally.
Once an image is registered and updated to change to another image, the image disappears and is new
The image you want to register has not been uploaded.
I have never experienced this situation since I have created several apps in the same way, and I think the settings are different from the ones I created before, but I've looked around the settings, but I'm in trouble because it doesn't heal at all.
Could you please let me know if there is anyone who seems to understand that this area is suspicious?
If there is a lack of information, please let me know.Thank you for your cooperation.

Problems/Error Messages you are experiencing

There are no specific error messages.

Source Codes Affected

Controller

class BadgesController <ApplicationController
  def create
    @badge=Badge.new(badge_params)
    [email protected]
      flash[:success] = "You have registered a new badge!"
      redirect_to home_path
    else
      render controller: 'badges', action: 'new'
    end
  end

  default update
    @badge=Badge.find (params[:id])

    [email protected](badge_params)
      # Redirect to top page if saved successfully
      flash[:success] = "Edited badge."
      redirect_to home_path
    else
      # Return to edit screen if save fails
      render controller: 'badges', action: 'edit'
    end
  end

  private
    def badge_params
      params.require(:badge)
        .permit(:name,:image,:remove_image,:image_cache)
    end
end

DB Definition

 create_table: badges do | t |
      t.string —name
      t.string —image
      t.boolean:remove_image
      t.string —image_cache

      t.timestamps
    end

uploader.rb

#encoding:utf-8

class ImageUploader<CarrierWave::Uploader::Base
  includeCarrierWave::MiniMagick

  if Rails.env.production?
    includeCloudinary::CarrierWave
  else
    storage:file
  end

  def public_id
    model.id
  end

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

  process:resize_to_fit=>[250,250]

  def extension_white_list
    %w(jpg jpeg gif png)
  end

end

Tried

If you run it on the development environment (Cloud 9), you can update the image successfully (because you are not using Cloudinary).
I was wondering if Mini Magick was not good, and once I deleted and updated Mini Magick, the situation remained the same.
The situation remained the same when I remade it in Rails 4.2.5.
Re-create the Heroku app, add Cloudinary as a new add-on, and add CLOUDINARY_NAME, CLOUDINARY_API_KEY, etc.
I registered with Heroku again, but it didn't go away.

Supplementary information (e.g. language/FW/tool version)

Ruby on Rails 5.0.0.1
Heroku
Registering images with Cloudinary+CarrierWave+MiniMagic

ruby-on-rails heroku

2022-09-30 21:23

3 Answers

The above symptoms appear to be caused by Heroku.

Heroku's dyno file system is called ephemeral filesystem and
Cannot hold persistent data such as upload data.


To enable file upload while utilizing Heroku Upload data must be stored in a different location than in dyno.
Specifically, please consider Amazon S3.

By the way, CarrierWave seems to be able to use Amazon S3 in a simple procedure.
Note: Using Amazon S3


2022-09-30 21:23

It may not matter, though.
If you are using carrierwave.
Model

 create_table: badges do | t |
  t.string —name
  t.string —image
  t.boolean:remove_image
  t.string —image_cache

  t.timestamps
end

You don't need this part.

t.boolean:remove_image
  t.string —image_cache

Why don't you delete it?


2022-09-30 21:23

The contents of the html.erb file are not written, but
Is the image pasting specified in image_tag?
If it is not imagae_tag, the above phenomenon seems to occur.
I'm sorry if the answer is wrong or wrong.


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.