2017-01-14 65 views
0

我安装了carrierwave宝石和雾宝石,使用亚马逊s3。但是,在执行完所有步骤后,我尝试运行rails s -p $PORT -b $IP,因为我正在使用cloud9。服务器无法启动!仅供参考,我使用postgresql作为我的数据库。安装雾化宝石服务器后无法启动

下面是错误的一部分:

=> Booting WEBrick 
=> Rails 4.2.5 application starting in development on http://0.0.0.0:8080 
=> Run `rails server -h` for more startup options 
=> Ctrl-C to shutdown server 
Exiting 
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- fog (LoadError) 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require' 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency' 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require' 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave/uploader/configuration.rb:121:in `eager_load_fog' 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave/uploader/configuration.rb:136:in `fog_credentials=' 
     from /home/ubuntu/workspace/config/initializers/carrierwave.rb:2:in `block in <top (required)>' 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave/uploader/configuration.rb:158:in `configure' 
     from /usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.0.0/lib/carrierwave.rb:14:in `configure' 

这里我image_uploader:

class ImageUploader < CarrierWave::Uploader::Base 


    storage :fog 
    # storage :fog 
    include CarrierWave :MimeTypes 
    process :set_content_type 


    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 


end 

carrierwave.rb

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    provider:    'AWS',      # required 
    aws_access_key_id:  ENV["S3_ACCESS_KEY"],      # required 
    aws_secret_access_key: ENV["S3_SECRET_KEY"]      # required 
    } 
    config.fog_directory = ENV["S3_BUCKET"]       # required 
end 

编辑

Gemfile.lock的:

GEM 
    remote: https://rubygems.org/ 
    specs: 
    actionmailer (4.2.5) 
     actionpack (= 4.2.5) 
     actionview (= 4.2.5) 
     activejob (= 4.2.5) 
     mail (~> 2.5, >= 2.5.4) 
     rails-dom-testing (~> 1.0, >= 1.0.5) 
    actionpack (4.2.5) 
     actionview (= 4.2.5) 
     activesupport (= 4.2.5) 
     rack (~> 1.6) 
     rack-test (~> 0.6.2) 
     rails-dom-testing (~> 1.0, >= 1.0.5) 
     rails-html-sanitizer (~> 1.0, >= 1.0.2) 
    actionview (4.2.5) 
     activesupport (= 4.2.5) 
     builder (~> 3.1) 
     erubis (~> 2.7.0) 
     rails-dom-testing (~> 1.0, >= 1.0.5) 
     rails-html-sanitizer (~> 1.0, >= 1.0.2) 
    activejob (4.2.5) 
     activesupport (= 4.2.5) 
     globalid (>= 0.3.0) 
    activemodel (4.2.5) 
     activesupport (= 4.2.5) 
     builder (~> 3.1) 
    activerecord (4.2.5) 
     activemodel (= 4.2.5) 
     activesupport (= 4.2.5) 
     arel (~> 6.0) 
    activesupport (4.2.5) 
     i18n (~> 0.7) 
     json (~> 1.7, >= 1.7.7) 
     minitest (~> 5.1) 
     thread_safe (~> 0.3, >= 0.3.4) 
     tzinfo (~> 1.1) 
    acts_as_votable (0.10.0) 
    arel (6.0.4) 
    autoprefixer-rails (6.6.1) 
     execjs 
    bcrypt (3.1.11) 
    binding_of_caller (0.7.2) 
     debug_inspector (>= 0.0.1) 
    bootstrap-sass (3.3.7) 
     autoprefixer-rails (>= 5.2.1) 
     sass (>= 3.3.4) 
    builder (3.2.3) 
    byebug (9.0.6) 
    carrierwave (1.0.0) 
     activemodel (>= 4.0.0) 
     activesupport (>= 4.0.0) 
     mime-types (>= 1.16) 
    climate_control (0.1.0) 
    cocaine (0.5.8) 
     climate_control (>= 0.0.3, < 1.0) 
    coffee-rails (4.1.1) 
     coffee-script (>= 2.2.0) 
     railties (>= 4.0.0, < 5.1.x) 
    coffee-script (2.4.1) 
     coffee-script-source 
     execjs 
    coffee-script-source (1.12.2) 
    concurrent-ruby (1.0.4) 
    css_convertor (1.0.3) 
    debug_inspector (0.0.2) 
    devise (4.2.0) 
     bcrypt (~> 3.0) 
     orm_adapter (~> 0.1) 
     railties (>= 4.1.0, < 5.1) 
     responders 
     warden (~> 1.2.3) 
    erubis (2.7.0) 
    execjs (2.7.0) 
    font-awesome-rails (4.7.0.1) 
     railties (>= 3.2, < 5.1) 
    globalid (0.3.7) 
     activesupport (>= 4.1.0) 
    haml (4.0.7) 
     tilt 
    i18n (0.7.0) 
    jbuilder (2.6.1) 
     activesupport (>= 3.0.0, < 5.1) 
     multi_json (~> 1.2) 
    jquery-rails (4.2.2) 
     rails-dom-testing (>= 1, < 3) 
     railties (>= 4.2.0) 
     thor (>= 0.14, < 2.0) 
    jquery-ui-rails (5.0.5) 
     railties (>= 3.2.16) 
    json (1.8.6) 
    kaminari (0.17.0) 
     actionpack (>= 3.0.0) 
     activesupport (>= 3.0.0) 
    loofah (2.0.3) 
     nokogiri (>= 1.5.9) 
    mail (2.6.4) 
     mime-types (>= 1.16, < 4) 
    mime-types (3.1) 
     mime-types-data (~> 3.2015) 
    mime-types-data (3.2016.0521) 
    mimemagic (0.3.2) 
    mini_portile2 (2.1.0) 
    minitest (5.10.1) 
    multi_json (1.12.1) 
    nested_form (0.3.2) 
    nokogiri (1.7.0.1) 
     mini_portile2 (~> 2.1.0) 
    orm_adapter (0.5.0) 
    paperclip (5.1.0) 
     activemodel (>= 4.2.0) 
     activesupport (>= 4.2.0) 
     cocaine (~> 0.5.5) 
     mime-types 
     mimemagic (~> 0.3.0) 
    pg (0.18.4) 
    rack (1.6.5) 
    rack-pjax (1.0.0) 
     nokogiri (~> 1.5) 
     rack (>= 1.1) 
    rack-test (0.6.3) 
     rack (>= 1.0) 
    rails (4.2.5) 
     actionmailer (= 4.2.5) 
     actionpack (= 4.2.5) 
     actionview (= 4.2.5) 
     activejob (= 4.2.5) 
     activemodel (= 4.2.5) 
     activerecord (= 4.2.5) 
     activesupport (= 4.2.5) 
     bundler (>= 1.3.0, < 2.0) 
     railties (= 4.2.5) 
     sprockets-rails 
    rails-deprecated_sanitizer (1.0.3) 
     activesupport (>= 4.2.0.alpha) 
    rails-dom-testing (1.0.8) 
     activesupport (>= 4.2.0.beta, < 5.0) 
     nokogiri (~> 1.6) 
     rails-deprecated_sanitizer (>= 1.0.1) 
    rails-html-sanitizer (1.0.3) 
     loofah (~> 2.0) 
    rails-i18n (4.0.9) 
     i18n (~> 0.7) 
     railties (~> 4.0) 
    rails_12factor (0.0.3) 
     rails_serve_static_assets 
     rails_stdout_logging 
    rails_admin (1.1.1) 
     builder (~> 3.1) 
     coffee-rails (~> 4.0) 
     font-awesome-rails (>= 3.0, < 5) 
     haml (~> 4.0) 
     jquery-rails (>= 3.0, < 5) 
     jquery-ui-rails (~> 5.0) 
     kaminari (~> 0.14) 
     nested_form (~> 0.3) 
     rack-pjax (>= 0.7) 
     rails (>= 4.0, < 6) 
     remotipart (~> 1.3) 
     sass-rails (>= 4.0, < 6) 
    rails_serve_static_assets (0.0.5) 
    rails_stdout_logging (0.0.5) 
    railties (4.2.5) 
     actionpack (= 4.2.5) 
     activesupport (= 4.2.5) 
     rake (>= 0.8.7) 
     thor (>= 0.18.1, < 2.0) 
    rake (12.0.0) 
    rdoc (4.3.0) 
    remotipart (1.3.1) 
    responders (2.3.0) 
     railties (>= 4.2.0, < 5.1) 
    sass (3.4.23) 
    sass-rails (5.0.6) 
     railties (>= 4.0.0, < 6) 
     sass (~> 3.1) 
     sprockets (>= 2.8, < 4.0) 
     sprockets-rails (>= 2.0, < 4.0) 
     tilt (>= 1.1, < 3) 
    sdoc (0.4.2) 
     json (~> 1.7, >= 1.7.7) 
     rdoc (~> 4.0) 
    simple_form (3.4.0) 
     actionpack (> 4, < 5.1) 
     activemodel (> 4, < 5.1) 
    spring (2.0.0) 
     activesupport (>= 4.2) 
    sprockets (3.7.1) 
     concurrent-ruby (~> 1.0) 
     rack (> 1, < 3) 
    sprockets-rails (3.2.0) 
     actionpack (>= 4.0) 
     activesupport (>= 4.0) 
     sprockets (>= 3.0.0) 
    thor (0.19.4) 
    thread_safe (0.3.5) 
    tilt (2.0.5) 
    turbolinks (5.0.1) 
     turbolinks-source (~> 5) 
    turbolinks-source (5.0.0) 
    tzinfo (1.2.2) 
     thread_safe (~> 0.1) 
    uglifier (3.0.4) 
     execjs (>= 0.3.0, < 3) 
    warden (1.2.6) 
     rack (>= 1.0) 
    web-console (2.3.0) 
     activemodel (>= 4.0) 
     binding_of_caller (>= 0.7.2) 
     railties (>= 4.0) 
     sprockets-rails (>= 2.0, < 4.0) 

PLATFORMS 
    ruby 

DEPENDENCIES 
    acts_as_votable (~> 0.10.0) 
    autoprefixer-rails 
    bootstrap-sass (~> 3.3, >= 3.3.7) 
    byebug 
    carrierwave (~> 1.0) 
    coffee-rails (~> 4.1.0) 
    css_convertor (~> 1.0, >= 1.0.3) 
    devise (~> 4.2) 
    haml (~> 4.0, >= 4.0.7) 
    jbuilder (~> 2.0) 
    jquery-rails 
    paperclip (~> 5.1) 
    pg (~> 0.18.2) 
    rails (= 4.2.5) 
    rails-i18n (~> 4.0, >= 4.0.8) 
    rails_12factor 
    rails_admin (~> 1.0) 
    sass-rails (~> 5.0) 
    sdoc (~> 0.4.0) 
    simple_form (~> 3.3, >= 3.3.1) 
    spring 
    turbolinks 
    uglifier (>= 1.3.0) 
    web-console (~> 2.0) 

RUBY VERSION 
    ruby 2.3.0p0 

BUNDLED WITH 
    1.12.5 

这是我的初始设置/ Carrierwave.rb:

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    :provider => 'AWS',      # required 
    :aws_access_key_id => ENV["S3_ACCESS_KEY"],      # required 
    :aws_secret_access_key => ENV["S3_SECRET_KEY"]      # required 
    } 
    config.fog_directory = ENV["S3_BUCKET"]       # required 
end 

让我知道,如果需要更多的信息,并提前感谢!

+0

你可以显示你的Gemfile中引用了“雾”的部分吗?它是否也在Gemfile.lock中引用? – tompave

+0

@tompave我只是添加它,请检查出来 – hekmat

+0

我通过终端手动添加它,'gem install fog' – hekmat

回答

1

看起来fog没有在您的Gemfile.lock中列出。

确保在您的Gemfile的根级补充一点:

gem 'fog', '~> 1.38' 

然后运行:

bundle install 

并提交更改。

重新启动应用程序,它应该工作。

+0

同样的问题,它没有工作! – hekmat

+0

这就是我现在得到的 '正在退出 /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:244:in' validate_options':缺少必需的参数:aws_access_key_id,aws_secret_access_key(ArgumentError) from /usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb: 268:在'handle_settings' from/usr/local/rvm/gems/ruby​​-2.3.0/gems/fog-core-' – hekmat

+0

好的,所以你报告的问题已经解决了。你遇到的新错误是一个完全不同的问题。你需要确保你的'ENV'包含你所引用的变量。 – tompave