【问题标题】:Rails 5 CarrierWave Gem Works in Production But Not In DevelopmentRails 5 CarrierWave Gem 已投入生产,但尚未开发
【发布时间】:2019-06-01 01:22:50
【问题描述】:

Gem 和 Ruby 版本

ruby '2.5.3', 'rails', '~> 5.2.1', 'carrierwave', '~> 1.2', '>= 1.2.3'

当我在本地开发环境中上传图像时,我没有收到任何错误,也没有上传图像,但我在生产环境中的同一个应用程序会按应有的方式上传图像。我仔细检查了我的设置,没有发现任何不合适的地方,而且它在生产中工作的事实让我感到困惑。

image_uploader.rb

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

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

  def default_url(*args)
    "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  end

  version :thumb do
    process resize_to_fill: [500, 350]
  end

  def extension_whitelist
    %w(jpg jpeg gif png pdf)
  end

end

team.rb

class Team < ApplicationRecord
  ...
  mount_uploader :image, ImageUploader
  ...
end

teams_controller.rb

class TeamsController < ApplicationController
    ...
    def team_params
      params.require(:team).permit(:name, :title, :phone, :email, :bio, :image, :slug)
    end
end

teams/_form.html.erb

<%= form_with(model: team, local: true) do |form| %>
    ...
    <div class="form-group clearfix">
      <div class="col-md-12">
        <%= form.file_field :image %>
        <div style="max-width: 300px">
          <% if @team.image_url %>
            <h5>Current Image</h5>
            <%= link_to @team do %>
              <figure>
                <%= image_tag @team.image_url %>
              </figure>
            <% end %>
          <% end %>
        </div>
      </div>
    </div>
    ...
<% end %>

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 carrierwave


    【解决方案1】:

    您可以设置一个初始化程序来检查开发过程中的错误:

    config/initializers/carrierwave.rb
    
    CarrierWave.configure do |config|
      config.ignore_integrity_errors = false
      config.ignore_processing_errors = false
      config.ignore_download_errors = false
    end
    

    【讨论】:

    • 看起来像 ImageMagick/GraphicsMagick is not installed -- 我有一台新 MacBook,一定忽略了这个安装。谢谢你。我接受你的回答,因为它让我找到了解决方案。
    猜你喜欢
    • 2022-08-16
    • 2011-06-27
    • 2020-08-17
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多