【问题标题】:Can't upload images with Rails and Paperclip无法使用 Rails 和 Paperclip 上传图像
【发布时间】:2015-03-10 18:45:50
【问题描述】:

我在我的 Rails 应用程序中使用 Paperclip 来处理图片上传。但是,由于某种原因,每次我尝试创建一个带有附加图像的模型实例时,都会遇到 Rails 500 错误。

奇怪的是,重新启动应用程序(通过 Upstart)然后重新提交表单允许我成功上传图像,但它似乎没有“接受”:任何后续上传仍然给我 500 错误。

生产日志没有帮助,甚至没有显示为创建实例而发出的 POST 请求。

我的 Upstart 配置文件:

description 'site.com'
author 'Daniel J. <>'

start on [2345]
stop on runlevel [016]

env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env RAILS_ENV=production
env SECRET_KEY_BASE=''
env DEVISE_SECRET_KEY=''
env POSTGRESQL_PASSWORD=''

setuid www-data
setgid www-data

chdir /var/www/site/current

pre-start exec bundle exec unicorn_rails -D -c /var/www/site/current/config/unicorn.rb --env production
post-stop exec kill `cat /var/www/site/current/tmp/pids/unicorn.pid`

我的 nginx 文件:

upstream app {
    server 127.0.0.1:3000;
}

server {
    listen               80               default;
    server_name          site.com;
    charset              utf-8;
    client_max_body_size 75M;
    root                 /var/www/site/current/public;

    location ~ ^/(assets)/ {
        gzip_static on;
        expires     max;
        add_header  Cache-Control public;
    }

    location / {
        try_files $uri/index.html $uri @app;
        error_page 404 /404.html;
        error_page 403 /403.html;
        error_page 422 /422.html;
        error_page 500 502 503 504 /500.html;
    }

    location = /favicon.ico {
        expires max;
        add_header Cache-Control public;
    }

    location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app;
    }
}

还有我的独角兽配置文件​​:

listen 3000
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 30
preload_app true
working_directory '/var/www/site/current'
stderr_path 'log/unicorn-error.log'
stdout_path 'log/unicorn-access.log'

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing.  Wait for master to send QUIT.'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

【问题讨论】:

    标签: ruby-on-rails paperclip


    【解决方案1】:

    我发现这是因为盒子上的内存不足造成的。添加交换文件后(使用此处的说明:https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04),我就能够成功上传文件。

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 2016-07-30
      • 2019-08-22
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 2013-12-29
      • 2011-01-14
      • 1970-01-01
      相关资源
      最近更新 更多