簡體   English   中英

Rails 5 CarrierWave Gem在生產中工作但不在開發中

[英]Rails 5 CarrierWave Gem Works in Production But Not In Development

寶石和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

團隊/ _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 %>

您可以設置初始化程序以在開發期間檢查錯誤:

config/initializers/carrierwave.rb

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM