CarrierWave :: Crop :: ProcessingError(无法裁剪 - :en不是有效的区域设置)

时间:2017-07-04 21:24:31

标签: ruby-on-rails nginx carrierwave

我正在开发一个rails项目,我在其上有一个带有字段的产品模型来上传图片。我使用了carrierwave gem进行上传,项目位于运行nginx的服务器上。

我需要在项目内的路径public/uploads上传图片。在开发环境中,一切正常,但在生产时,我上传图片时网站会崩溃。

我已经使用命令tails /var/log/nginx/error.log检查了服务器上的生产日志,但出于某种原因,它只是在POST / PATCH操作之前向我显示。

这是我的product型号:

class Product < ApplicationRecord
  mount_uploader :picture, PictureUploader

end

这是我的picture uploader文件:

class PictureUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick

  process crop: [400, 400]

  # Choose what kind of storage to use for this uploader:
  storage :file

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    'uploads'
  end

  def extension_whitelist
    %w(jpeg jpg png)
  end

  def content_type_whitelist
    /image\//
  end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  def filename
    "#{secure_token}.#{file.extension}" if original_filename.present?
  end

  protected
  def secure_token
    var = :"@#{mounted_as}_secure_token"
    model.instance_variable_get(var) || model.instance_variable_set(var, SecureRandom.uuid)
  end

end

这是我对网站的nginx配置:

server {
    listen 8081;
    server_name 127.0.0.1;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/project/current/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /home/deploy/.rbenv/versions/2.4.1/bin/ruby;
}

提前非常感谢:)

修改

我看错了日志。生产日志位于/var/www/project/current/log

这是我得到的错误:

D, [2017-07-04T16:50:19.330282 #1341] DEBUG -- : [c7b9956c-786f-440c-bc38-e13718f3493e]    (0.1ms)  BEGIN
D, [2017-07-04T16:50:19.331113 #1341] DEBUG -- : [c7b9956c-786f-440c-bc38-e13718f3493e]    (0.2ms)  ROLLBACK
I, [2017-07-04T16:50:19.331277 #1341]  INFO -- : [c7b9956c-786f-440c-bc38-e13718f3493e] Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.7ms)
F, [2017-07-04T16:50:19.331669 #1341] FATAL -- : [c7b9956c-786f-440c-bc38-e13718f3493e]   
F, [2017-07-04T16:50:19.331691 #1341] FATAL -- : [c7b9956c-786f-440c-bc38-e13718f3493e] CarrierWave::Crop::ProcessingError (Failed to crop - :en is not a valid locale):
F, [2017-07-04T16:50:19.331704 #1341] FATAL -- : [c7b9956c-786f-440c-bc38-e13718f3493e]   
F, [2017-07-04T16:50:19.331716 #1341] FATAL -- : [c7b9956c-786f-440c-bc38-e13718f3493e] app/controllers/products_controller.rb:39:in `block in update'
[c7b9956c-786f-440c-bc38-e13718f3493e] app/controllers/products_controller.rb:38:in `update'

显然,这是区域设置文件的问题。我还使用carrierwave-crop-on-fly gem来上传图片,这似乎是错误的一部分。

我在mi application.rb上有这个:

config.i18n.default_locale = :es
config.i18n.available_locales = :es
config.i18n.enforce_available_locales = true

如果我找到答案,我会更新问题

1 个答案:

答案 0 :(得分:0)

在添加en.yml文件并将其包含在语言环境中之后,下一个错误是:translation missing: en.errors.messages.mini_magick_processing_error

原来在服务器上没有安装Imagemagick。

要解决此问题,您需要在远程服务器上运行:sudo apt-get install imagemagick

自己回答kenneth信用证。