gpt4 book ai didi

ruby-on-rails - Rails 5 CarrierWave Gem 可用于生产,但不能用于开发

转载 作者:行者123 更新时间:2023-12-04 06:30:17 26 4
gpt4 key购买 nike

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

团队.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 %>

最佳答案

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

config/initializers/carrierwave.rb

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

关于ruby-on-rails - Rails 5 CarrierWave Gem 可用于生产,但不能用于开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54056424/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com