Rails 5 CarrierWave宝石在生产中有效,但未开发中 [英] Rails 5 CarrierWave Gem Works in Production But Not In Development

查看:50
本文介绍了Rails 5 CarrierWave宝石在生产中有效,但未开发中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

宝石与宝石Ruby版本

红宝石'2.5.3','rails','〜> 5.2.1','carrierwave','〜> 1.2', '> = 1.2.3'

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

在本地开发环境中上载图像时,没有收到错误,也没有图像上载,但是在生产环境中使用了相同的应用程序上载图片。我已经仔细检查了设置,看不到任何不正常的地方,并且它在生产环境中正常工作的事实使我感到困惑。

When I upload images in my local development environment, I receive no errors and no images are uploaded, but my same application in my production environment uploads images as it should. I've double checked my settings and cannot see anything out of place and the fact that it works in production has me confused.

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 %>


推荐答案

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

You could set a initializer to check for errors during development:

config/initializers/carrierwave.rb

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

这篇关于Rails 5 CarrierWave宝石在生产中有效,但未开发中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆