首页 文章

使用ruby on rails在heroku上运行回形针的问题

提问于
浏览
0

我正在使用paperclip在我的ruby on rails应用程序上进行一些图像上传 . 一切都在当地很好 .

当我部署到heroku时,上传似乎可以正常工作,但是当我查看我的项目时,显然上传已经失败了 - 请参阅Companylogo字段:

https://whats-on-today.herokuapp.com/events/2

请参阅表格并亲自尝试:

https://whats-on-today.herokuapp.com/events/new

这是我的gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

#add bootstrap css
gem "twitter-bootstrap-rails"
gem "therubyracer"
gem "less-rails"

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

#Add paperclip for image uploading - requires imagemagick - need rmagick for heroku?
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
gem 'rmagick'

gem "rake", '10.4.2'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

这些是heroku日志 - 我看到没有问题....

2015-01-25T22:01:35.176977+00:00 heroku[web.1]: Process exited with status 143
2015-01-25T22:01:38.410781+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 14913 -e production`
2015-01-25T22:01:43.197130+00:00 app[web.1]: [2015-01-25 22:01:43] INFO  ruby 2.0.0 (2014-11-13) [x86_64-linux]
2015-01-25T22:01:43.197109+00:00 app[web.1]: [2015-01-25 22:01:43] INFO  WEBrick 1.3.1
2015-01-25T22:01:43.197447+00:00 app[web.1]: [2015-01-25 22:01:43] INFO  WEBrick::HTTPServer#start: pid=3 port=14913
2015-01-25T22:01:43.641141+00:00 heroku[web.1]: State changed from starting to up
2015-01-25T22:01:45.345186+00:00 heroku[router]: at=info method=GET path="/events/events" host=whats-on-today.herokuapp.com request_id=3560f69e-1093-4993-a17c-5ce8d2ee8eb3 fwd="90.202.95.185" dyno=web.1 connect=2ms service=124ms status=404 bytes=1829
2015-01-25T22:01:45.584826+00:00 heroku[router]: at=info method=GET path="/events/events" host=whats-on-today.herokuapp.com request_id=a74abcc9-998e-4ed1-abbf-5770154ee91e fwd="90.202.95.185" dyno=web.1 connect=4ms service=15ms status=404 bytes=1829
2015-01-25T22:01:45.941976+00:00 heroku[router]: at=info method=GET path="/events" host=whats-on-today.herokuapp.com request_id=e492071a-85d9-4abc-a563-d7f47fa5059d fwd="90.202.95.185" dyno=web.1 connect=1ms service=72ms status=200 bytes=5296
2015-01-25T22:01:46.155824+00:00 heroku[router]: at=info method=GET path="/assets/application-2b56caae7bd0b485593c1fca2397cc26.css" host=whats-on-today.herokuapp.com request_id=717efe34-3d3d-4bcd-81cd-8f6ed3c4c68e fwd="90.202.95.185" dyno=web.1 connect=2ms service=86ms status=304 bytes=231
2015-01-25T22:01:46.187234+00:00 heroku[router]: at=info method=GET path="/assets/application-09164813eb76f663d73f61fbdd0dbbea.js" host=whats-on-today.herokuapp.com request_id=c2462f3b-728b-4a00-8675-699a14c57648 fwd="90.202.95.185" dyno=web.1 connect=0ms service=113ms status=304 bytes=231
2015-01-25T22:01:48.523726+00:00 heroku[router]: at=info method=GET path="/events/new" host=whats-on-today.herokuapp.com request_id=7179c102-4baa-4db4-b96b-5187ce63edf2 fwd="90.202.95.185" dyno=web.1 connect=3ms service=122ms status=200 bytes=12000
2015-01-25T22:02:08.602578+00:00 heroku[router]: at=info method=POST path="/events" host=whats-on-today.herokuapp.com request_id=cfa83d61-6335-4f69-aba6-300226da8d46 fwd="90.202.95.185" dyno=web.1 connect=1ms service=2146ms status=302 bytes=1057
2015-01-25T22:02:08.801389+00:00 heroku[router]: at=info method=GET path="/events/2" host=whats-on-today.herokuapp.com request_id=3b54580d-bbcf-44a2-9c4c-60a951f46917 fwd="90.202.95.185" dyno=web.1 connect=0ms service=90ms status=200 bytes=5557
2015-01-25T22:02:08.961458+00:00 heroku[router]: at=info method=GET path="/system/events/logos/000/000/002/original/.jpg?1422223328" host=whats-on-today.herokuapp.com request_id=99bad1d0-e9ae-4be3-8e4c-a2e4e2a13270 fwd="90.202.95.185" dyno=web.1 connect=1ms service=6ms status=404 bytes=1829
2015-01-25T22:02:08.954988+00:00 heroku[router]: at=info method=GET path="/assets/application-2b56caae7bd0b485593c1fca2397cc26.css" host=whats-on-today.herokuapp.com request_id=041af115-97ff-4d89-9e39-eb612cff5a72 fwd="90.202.95.185" dyno=web.1 connect=1ms service=7ms status=304 bytes=231
2015-01-25T22:02:09.068322+00:00 heroku[router]: at=info method=GET path="/assets/application-09164813eb76f663d73f61fbdd0dbbea.js" host=whats-on-today.herokuapp.com request_id=4c838874-33a1-4a0c-a823-b8e50af57d03 fwd="90.202.95.185" dyno=web.1 connect=1ms service=6ms status=304 bytes=231
2015-01-25T22:02:09.203374+00:00 heroku[router]: at=info method=GET path="/system/events/logos/000/000/002/original/.jpg?1422223328" host=whats-on-today.herokuapp.com request_id=4e30ba37-7545-47f7-9575-e02200fec206 fwd="90.202.95.185" dyno=web.1 connect=2ms service=8ms status=404 bytes=1829
2015-01-25T22:02:52.834418+00:00 heroku[router]: at=info method=GET path="/assets/application-09164813eb76f663d73f61fbdd0dbbea.js" host=whats-on-today.herokuapp.com request_id=f7f85d8c-d872-40ce-8068-33bf57167f67 fwd="90.202.95.185" dyno=web.1 connect=1ms service=6ms status=304 bytes=231
2015-01-25T22:02:52.688561+00:00 heroku[router]: at=info method=GET path="/events/" host=whats-on-today.herokuapp.com request_id=dbb5d10e-cea9-4add-89e7-5a0cca937cbb fwd="90.202.95.185" dyno=web.1 connect=2ms service=87ms status=200 bytes=5909
2015-01-25T22:02:52.837142+00:00 heroku[router]: at=info method=GET path="/assets/application-2b56caae7bd0b485593c1fca2397cc26.css" host=whats-on-today.herokuapp.com request_id=e39b298e-30de-42b6-a5de-00f97219f897 fwd="90.202.95.185" dyno=web.1 connect=1ms service=10ms status=304 bytes=231
2015-01-25T22:06:04.579739+00:00 heroku[router]: at=info method=GET path="/events/2" host=whats-on-today.herokuapp.com request_id=efa58555-c49c-4ea6-8f9c-970bc3672f12 fwd="90.202.95.185" dyno=web.1 connect=1ms service=40ms status=200 bytes=5135
2015-01-25T22:06:04.722708+00:00 heroku[router]: at=info method=GET path="/system/events/logos/000/000/002/original/.jpg?1422223328" host=whats-on-today.herokuapp.com request_id=d904339d-41b9-421f-889c-b19581517a16 fwd="90.202.95.185" dyno=web.1 connect=2ms service=6ms status=404 bytes=1829
2015-01-25T22:06:04.708682+00:00 heroku[router]: at=info method=GET path="/assets/application-2b56caae7bd0b485593c1fca2397cc26.css" host=whats-on-today.herokuapp.com request_id=926572f0-d5e6-4e95-998e-708581cb5563 fwd="90.202.95.185" dyno=web.1 connect=1ms service=5ms status=304 bytes=231
2015-01-25T22:06:04.717214+00:00 heroku[router]: at=info method=GET path="/assets/application-09164813eb76f663d73f61fbdd0dbbea.js" host=whats-on-today.herokuapp.com request_id=77373e30-4f30-4b30-b4fb-699682023e9a fwd="90.202.95.185" dyno=web.1 connect=1ms service=9ms status=304 bytes=231
2015-01-25T22:06:29.160729+00:00 heroku[router]: at=info method=GET path="/events/new" host=whats-on-today.herokuapp.com request_id=095b1c4f-b127-45f1-966a-d0e2e106ee41 fwd="90.202.95.185" dyno=web.1 connect=1ms service=93ms status=200 bytes=12000
2015-01-25T22:06:29.321758+00:00 heroku[router]: at=info method=GET path="/assets/application-2b56caae7bd0b485593c1fca2397cc26.css" host=whats-on-today.herokuapp.com request_id=cd6acd5d-9a95-401f-9599-b33d7c9b9ac3 fwd="90.202.95.185" dyno=web.1 connect=3ms service=7ms status=304 bytes=231
2015-01-25T22:06:29.350081+00:00 heroku[router]: at=info method=GET path="/assets/application-09164813eb76f663d73f61fbdd0dbbea.js" host=whats-on-today.herokuapp.com request_id=3dd3a871-2a7a-467c-9aaa-3929e551e74a fwd="90.202.95.185" dyno=web.1 connect=3ms service=4ms status=304 bytes=231

我相信我在文件存储模式下有Paperclip . 也许这在heroku上是不允许的....如果是这种情况 - 如何让Paperclip在我的pg数据库中存储文件?

1 回答

  • 0

    因为我相信你不能直接写到Heroku,这是我认为你的问题 . 因此,您必须使用文件存储系统 - 我一直使用Amazon s3进行图像存储 . 这将需要一些修改,但它很容易设置!您的第一步是获得免费的亚马逊s3帐户 - 至少在第一年 . 您需要将这些添加到gemfile中

    gem 'aws-sdk'
    

    在此之后,您需要在Amazon s3网站上创建一个存储桶,它将充当对象容器 . 然后你需要获得一个访问密钥和秘密访问密钥,你需要保持安全的地方!在配置/ 生产环境 中,你需要设置一些沿着这条线 .

    config.paperclip_defaults = {
                :storage => :s3,
                :s3_credentials => {
                  :bucket => ENV['AWS_BUCKET'],
                  :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
                  :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
                },
                :path => ":class/:id/:basename_:style.:extension",
                :url => ":s3_sg_url"
          }
    

    然后在config初始化程序中,需要创建一个名为paperclip.rb的文件,并且应该输入以下内容:

    Paperclip.interpolates(:s3_sg_url) do |att, style| 
    "#{att.s3_protocol}://s3-ap-southeast-1.amazonaws.com/#{att.bucket_name}/#{att.path(style)}"
    end
    

    有关更多信息和说明,我建议您阅读本文https://devcenter.heroku.com/articles/paperclip-s3

相关问题