当我将carrierwave.rb添加到config / initializers /时,服务器rails未启动

时间:2015-02-07 22:20:14

标签: ruby-on-rails carrierwave

我正在努力让我的图片上传工作与S3,但当我创建 配置/初始化/ carrierwave.rb

并添加

CarrierWave.configure do |config|                                                                                                                                                                                 
  config.fog_credentials = {                                                                                                                                                                                      
    # Configuration for Amazon S3 should be made available through an Environment variable.                                                                                                                       
    # For local installations, export the env variable through the shell OR                                                                                                                                       
    # if using Passenger, set an Apache environment variable.                                                                                                                                                     
    #                                                                                                                                                                                                             
    # In Heroku, follow http://devcenter.heroku.com/articles/config-vars                                                                                                                                          
    #                                                                                                                                                                                                             
    # $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder                                          

    # Configuration for Amazon S3                                                                                                                                                                                 
    :provider              => 'AWS',                                                                                                                                                                              
    :aws_access_key_id     => ENV['S3_KEY'],                                                                                                                                                                      
    :aws_secret_access_key => ENV['S3_SECRET'],                                                                                                                                                                   
    #region                => ENV['S3_REGION']                                                                                                                                                                    
  }                                                                                                                                                                                                               

  # For testing, upload files to local `tmp` folder.                                                                                                                                                              
  #if Rails.env.test? || Rails.env.cucumber?                                                                                                                                                                      
  #  config.storage = :file                                                                                                                                                                                       
  #  config.enable_processing = false                                                                                                                                                                             
  #  config.root = "#{Rails.root}/tmp"                                                                                                                                                                            
  #else                                                                                                                                                                                                           
  #  config.storage = :fog                                                                                                                                                                                        
  #end                                                                                                                                                                                                            

  # To let CarrierWave work on heroku                                                                                                                                                                             
  config.cache_dir = "#{Rails.root}/tmp/uploads"                                                                                                                                                                  
  config.fog_directory    = ENV['S3_BUCKET_NAME']                                                                                                                                                                 

  # Generate http:// urls. Defaults to :authenticated_read (https://)                                                                                                                                             
  #config.s3_access_policy = :public_read                                                                                                                                                                         
  #config.fog_host         = "#{ENV['S3_ASSET_URL']}/#{ENV['S3_BUCKET_NAME']}"                                                                                                                                    
end                                                                                                                                                                                                               

rails s甚至没有启动

我得到了一堆错误......

=> Booting WEBrick                                                                                                                                                                                                
=> Rails 4.2.0 application starting in development on http://localhost:3000                                                                                                                                       
=> Run `rails server -h` for more startup options                                                                                                                                                                 
=> Ctrl-C to shutdown server                                                                                                                                                                                      
Exiting 
  

这   /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in   each' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in 阻止'           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in   instance_exec' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in 运行”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in   block in run_initializers' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:226:in阻止   tsort_each”           来自/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:348:in block (2 levels) in each_strongly_connected_component' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:418:in块(2   each_strongly_connected_component_from'中的等级)           来自/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:427:in   each_strongly_connected_component_from' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:417:in阻止   each_strongly_connected_component_from”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in   each' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in tsort_each_child”           来自/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:411:in call' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:411:in each_strongly_connected_component_from'           来自/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:347:in block in each_strongly_connected_component' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:345:in每个'           来自/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:345:in call' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:345:in each_strongly_connected_component'           来自/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:224:in   tsort_each' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:205:in tsort_each”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in   run_initializers' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/application.rb:352:in 初始化!”           来自/Users/atoder/Sites/rails_projects/post_app/config/environment.rb:5:in   <top (required)>' from /Users/atoder/Sites/rails_projects/post_app/config.ru:3:in需要”           来自/Users/atoder/Sites/rails_projects/post_app/config.ru:3:in block in <main>' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in instance_eval'           来自/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in   initialize' from /Users/atoder/Sites/rails_projects/post_app/config.ru:in新的”           来自/Users/atoder/Sites/rails_projects/post_app/config.ru:in <main>' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in eval'           来自/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in   new_from_string' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in parse_file”           来自/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:299:in   build_app_and_options_from_config' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:208:in 应用”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in   app' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:336:in wrapped_app”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:139:in   log_to_stdout' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:78:in 开始”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in   block in server' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in 点击”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in   server' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in run_command!”           来自/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in   <top (required)>' from /Users/atoder/Sites/rails_projects/post_app/bin/rails:8:in需要”           来自/ Users / atoder / Sites / rails_projects / post_app / bin / rails:8:in <top (required)>' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client/rails.rb:27:in load'           来自/usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client/rails.rb:27:in   call' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client/command.rb:7:in 称之为”           来自/usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client.rb:26:in   run' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/bin/spring:48:in ”           来自/usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/binstub.rb:11:in   load' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/binstub.rb:11:in ”           来自/usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in   require' from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in 需要”           来自/ Users / atoder / Sites / rails_projects / post_app / bin / spring:16:in''

1 个答案:

答案 0 :(得分:1)

好的我发现了问题...来自application.yml的设置没有加载..我通过将它添加到application.rb来修复它。

if File.exists?(File.expand_path('../application.yml', __FILE__))
  ENV.update YAML.load(File.read(File.expand_path('../application.yml', __FILE__))) 
end