我使用Carrierwave上传图片,但我遇到了一些问题:这是来自heroku的日志:
Running `rake db:migrate` attached to terminal... up, run.2276
rake aborted!
NameError: uninitialized constant Carrierwave
/app/config/initializers/carrier_wave.rb:2:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:652:in `block in load_config_initializer'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:166:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:651:in `load_config_initializer'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `block in <class:Engine>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `tsort_each_child'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require_environment!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:443:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
WARNING: Toolbelt v3.36.4 update available.
以下是我的文件:
carrier_wave.rb:
if Rails.env.production?
Carrierwave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_ACCESS_KEY'],
:aws_secrety_access_key => ENV['S3_SECRET_KEY']
}
config.fog_directory = ENV['S3_BUCKET']
end
end
application.rb中:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require 'carrierwave'
Bundler.require(*Rails.groups)
module MagicRecipes
class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/app/uploaders)
config.serve_static_files = true
config.active_record.raise_in_transactional_callbacks = true
config.assets.initialize_on_precompile = false
end
end
picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_limit: [600, 600]
if Rails.env.production?
storage :fog
else
storage :file
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
这是我的Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.0'
gem 'pg', '~> 0.18.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'rails_12factor', '~> 0.0.3'
gem 'bootstrap-sass', '~> 3.3.4.1'
gem 'devise', '~> 3.4.1'
gem 'paperclip', '~> 4.2.1'
gem 'aws-sdk', '~> 1.59.1'
gem 'will_paginate', '~> 3.0.7'
gem 'pry', '~> 0.10.1'
gem 'will_paginate-bootstrap', '~> 1.0.1'
gem 'carrierwave', '~> 0.10.0'
enter code here
gem&#39; mini_magick&#39;,&#39;〜&gt; 3.8.0&#39;
enter code here
gem&#39; fog&#39;,&#39;〜&gt; 1.23.0&#39;
enter code here
gem&#39; sdoc&#39;,&#39;〜&gt; 0.4.0&#39;,group :: doc
组:开发,:测试做 宝石&#39; byebug&#39; gem&#39; web-console&#39;,&#39;〜&gt; 2.0&#39; 宝石春天&#39; 结束
我在gemfile中安装了宝石和版本。
我不知道是什么问题,我做了一整个研究,但我可以解决问题。
由于