2014-11-07 23 views
0

我使用carrierwave gem來存儲用戶在Rails引擎中上傳到S3我登錄到在線商店應用程序礦。本地一切正常,我檢查S3以確保我的文件正在上傳。Rails應用程序可以正常使用S3在本地使用carrierwave,在Heroku上崩潰,並顯示錯誤消息'Unable to autoload constant'

我將我的應用程序部署到Heroku,部署成功。我還在Heroku上設置了我的AWS訪問密鑰,密鑰和存儲桶變量。但是,當我嘗試打開我的應用程序頁面時,出現「應用程序錯誤」頁面。當我看到我的Heroku的日誌,我注意到以下行:

/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.8/lib/active_support/dependencies.rb:464:in `load_missing_constant': Unable to autoload constant Prodeng::ProductImageUploader, expected /app/prodeng/app/uploaders/prodeng/product_image_uploader.rb to define it (LoadError) 

Prodeng是我安裝在我的應用我的Rails引擎的命名空間。我真的不確定爲什麼會發生這種情況,但這也是我第一次創建Rails引擎並將其安裝到應用程序中。

這裏是我的product_image_uploader.rb(prodeng /應用程序/上傳/ prodeng/product_image_uploader.rb)文件在我的Rails引擎:

class ProductImageUploader < CarrierWave::Uploader::Base 

    # Include RMagick or MiniMagick support: 
    include CarrierWave::RMagick 
    # include CarrierWave::MiniMagick 

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

    # 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/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    # Provide a default URL as a default if there hasn't been a file uploaded: 
    # def default_url 
    # # For Rails 3.1+ asset pipeline compatibility: 
    # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 
    # 
    # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 
    # end 

    # Process files as they are uploaded: 
    # process :scale => [200, 300] 
    # 
    # def scale(width, height) 
    # # do something 
    # end 

    # Create different versions of your uploaded files: 
    version :thumb do 
    process :resize_to_fit => [200, 150] 
    end 

    # Add a white list of extensions which are allowed to be uploaded. 
    # For images you might use something like this: 
    # def extension_white_list 
    # %w(jpg jpeg gif png) 
    # end 

    # Override the filename of the uploaded files: 
    # Avoid using model.id or version_name here, see uploader/store.rb for details. 
    # def filename 
    # "something.jpg" if original_filename 
    # end 

end 

這裏是我的Rails發動機內部我carrierwave.rb文件(/ prodeng /app/config/initializers/carrierwave.rb)

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    :provider    => 'AWS',       
    :aws_access_key_id  => ENV["AWS_ACCESS_KEY"],      
    :aws_secret_access_key => ENV["AWS_SECRET_KEY"]       
    } 
    config.fog_directory = ENV["AWS_BUCKET"]      
end 

這裏是我的prodeng.gemspec文件

$:.push File.expand_path("../lib", __FILE__) 

# Maintain your gem's version: 
require "prodeng/version" 

# Describe your gem and declare its dependencies: 
Gem::Specification.new do |s| 
    s.name  = "prodeng" 
    s.version  = Prodeng::VERSION 
    s.authors  = ["TODO: Your name"] 
    s.email  = ["TODO: Your email"] 
    s.homepage = "TODO" 
    s.summary  = "TODO: Summary of Prodeng." 
    s.description = "TODO: Description of Prodeng." 

    s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] 
    s.test_files = Dir["test/**/*"] 

    s.add_dependency "rails", "~> 4.0.8" 

    s.add_dependency "carrierwave" 
    s.add_dependency "rmagick" 

    s.add_development_dependency "sqlite3" 
end 

如果我遺漏了解決這個問題所需的任何東西,我很抱歉。任何幫助或指向正確的方向將不勝感激。謝謝!

編輯:我忘了,包括我的應用程序的Gemfile中

source 'https://rubygems.org' 
ruby '2.0.0' 

gem 'rails', '4.0.8' 
gem 'bootstrap-sass', '~> 3.2.0' 
gem 'sprockets', '2.11.0' 
gem 'bcrypt-ruby', '3.1.2' 
gem 'prodeng', :path => './prodeng' 
gem 'figaro' 
gem 'fog' 

group :development, :test do 
    gem 'sqlite3', '1.3.8' 
    gem 'rspec-rails', '2.13.1' 
end 

group :test do 
    gem 'selenium-webdriver', '2.35.1' 
    gem 'capybara', '2.1.0' 
    gem 'factory_girl_rails', '4.2.0' 
end 

gem 'sass-rails', '4.0.3' 
gem 'uglifier', '2.1.1' 
gem 'coffee-rails', '4.0.1' 
gem 'jquery-rails', '3.0.4' 
gem 'turbolinks', '1.1.1' 
gem 'jbuilder', '1.0.2' 

group :doc do 
    gem 'sdoc', '0.3.20', require: false 
end 

group :production do 
    gem 'pg', '0.15.1' 
    gem 'rails_12factor', '0.0.2' 
end 
+0

你的類名是Prodeng :: ProductImageUploader嗎? (缺少命名空間) – Swards 2014-11-07 06:12:14

+0

這正是問題所在。我怎麼錯過了?非常感謝! – sma 2014-11-07 18:09:44

回答

0

由於Swards在評論中指出,我創造我的ProductImageUploader上課的時候離開了我的引擎的命名空間。這個類應該是這樣寫的:

class Prodeng::ProductImageUploader < CarrierWave::Uploader::Base 
相關問題