宝石和红宝石版本
Ruby“2.5.3”、“Rails”、“~>5.2.1”、“CarrierWave”、“~>1.2”、“>=1.2.3”
当我在本地开发环境中上载图像时,我不会收到任何错误,也不会上载任何图像,但我的生产环境中的同一个应用程序会按原样上载图像。我已经仔细检查了我的设置,看不到任何不合适的地方,它在生产中工作的事实让我困惑。
图像上传器.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
团队管理员.rb
class TeamsController < ApplicationController
...
def team_params
params.require(:team).permit(:name, :title, :phone, :email, :bio, :image, :slug)
end
end
团队/\u 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 %>