简体   繁体   English

Carrierwave - 添加S3 / Fog进行生产后的开发上传问题

[英]Carrierwave - development upload issues after adding S3/Fog for production

I got my production rails 3 app setup to use Fog/S3 for storage while running on Heroku. 我得到了我的生产rails 3应用程序设置,以便在Heroku上运行时使用Fog / S3进行存储。 In the process, I made a few changes to /config/initializers/carrierwave.rb . 在此过程中,我对/config/initializers/carrierwave.rb进行了一些更改。 Here's what it looks like: 这是它的样子:

CarrierWave.configure do |config|

  if Rails.env.test? || Rails.env.development?
    config.root = Rails.root
    config.storage = :file
  else
    config.storage = :fog
    config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => ENV['MY_ID'],                        # required
    :aws_secret_access_key  => ENV['MY_KEY']                        # required
    }
      config.fog_directory  = 'my-app'                     # required
      config.fog_public     = false                                   # optional, defaults to true
      #config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
  end
end

Here's my image_uploader : 这是我的image_uploader

class ImageUploader < CarrierWave::Uploader::Base
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

Uploads are working fine in production. 上传工作正常。 Files are being uploaded to the correct destination in development, but I get this error when viewing an uploaded image: 文件正在开发中上传到正确的目的地,但在查看上传的图像时出现此错误:

ActionController::RoutingError (No route matches [GET] "/uploads/vendor/image/24/StoreB.png"):

I'm unsure of how to fix this. 我不确定如何解决这个问题。 Am I missing something in my uploader? 我在上传器中遗漏了什么吗? Help please? 请帮助? Let me know if you need more info. 如果您需要更多信息,请告诉我。 Thanks in advance! 提前致谢!

EDIT Code example that throws error: 编辑抛出错误的代码示例:

<% @stores.each do |s| %>
        <div class="row">
                <div class= "col-xs-9 horz-cent">
                        <%= link_to image_tag("#{s.vendor.image}"), user_show_store_path(s) %>
                </div>
        </div>
<% end %>

Set config.root as below config.root设置如下

 config.root = Rails.root.join('public')

Currently the files are getting uploaded in Rails.root directory which are non accessible from the browser as they are not in public directory. 目前,文件正在Rails.root目录中上传,这些文件无法从浏览器访问,因为它们不在public目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM