![](/img/trans.png)
[英]Rails uninitialized constant error on heroku, twitter api, works fine locally
[英]Rails app works fine with S3 using carrierwave locally, crashes on Heroku with error message 'Unable to autoload constant'
我正在使用carrierwave gem将用户上传到S3的用户存储在我安装到我的在线商店应用程序的Rails引擎中。 本地一切正常,我检查了S3以确保文件已上传。
我将应用程序部署到了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引擎并将其安装在应用程序内部。
这是我的Rails引擎中的product_image_uploader.rb(prodeng / app / uploaders / prodeng / product_image_uploader.rb)文件:
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
正如Swards在评论中指出的那样,在创建ProductImageUploader类时,我省略了引擎的名称空间。 该类应该这样写:
class Prodeng::ProductImageUploader < CarrierWave::Uploader::Base
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.