简体   繁体   English

Rails 5 CarrierWave Gem在生产中工作但不在开发中

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

Gem & Ruby Versions 宝石和Ruby版本

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 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 team.rb

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

teams_controller.rb 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.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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Rails 6 中:视差在开发中有效但不在生产中 - In Rails 6: Parallax works in development but not in production Rails代码在开发中有效,但在生产中无效 - Rails code works in development but not in production Rails应用程序Carrierwave上传了开发工作,但停止了生产工作 - Rails app Carrierwave uploads work on development but stop working on production Ruby On Rails 5.0.5 CarrierWave Gem适用于Update而不适用于Create - Ruby On Rails 5.0.5 CarrierWave Gem works on Update not on Create Rails:检测用户代理是否在开发中工作但不在生产中? - Rails: Detecting user agent works in development but not production? Rails 4-服务器在开发模式下工作,但不在生产模式下工作 - Rails 4 - server works in development mode, but not in production Rails Ajax Spinner正在开发中,但未在生产中工作 - rails ajax spinner works in development but not production 方法在开发中有效,但在生产中不起作用Rails MongoDB - Method works in development but not production Rails MongoDB Rails 3:caches_page在开发中起作用,而不在生产中起作用 - Rails 3: caches_page works in development and not in production Rails Log Formatter在开发中可用,但不能在生产中使用 - Rails Log Formatter works in Development, but not Production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM