Rails 5 CarrierWave宝石在生产中有效,但未开发中

时间:2019-01-05 21:26:42

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

宝石和Ruby版本

红宝石'2.5.3','轨道','〜> 5.2.1','载波','〜> 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 %>

1 个答案:

答案 0 :(得分:2)

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

config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.ignore_integrity_errors = false
  config.ignore_processing_errors = false
  config.ignore_download_errors = false
end