1

我目前在为我的 Rails 4 应用程序配置 Figaro 时遇到问题。每当我尝试运行 RSpec 或 rake db:migrate 时,都会遇到以下错误:

method_missing': undefined method{}:Figaro::Env 的 aws_access_key'

以下是完整的错误消息供参考:

Louiss-MacBook-Pro:beautifulnow louismedina$ rspec
/Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/figaro-0.7.0/lib/figaro/env.rb:9:in `method_missing': undefined method `aws_access_key' for #<Figaro::Env:0x007fc1b17749d8> (NoMethodError)
    from /Users/louismedina/Desktop/MindtonicMedia/beautifulnow/config/initializers/aws.rb:1:in `<top (required)>'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:223:in `load'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:223:in `block in load'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:223:in `load'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/engine.rb:608:in `each'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/engine.rb:608:in `block in <class:Engine>'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/initializable.rb:30:in `run'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/initializable.rb:44:in `each'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `call'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /Users/louismedina/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/application.rb:215:in `initialize!'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/railties-4.0.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/louismedina/Desktop/MindtonicMedia/beautifulnow/config/environment.rb:5:in `<top (required)>'
    from /Users/louismedina/Desktop/MindtonicMedia/beautifulnow/spec/spec_helper.rb:3:in `require'
    from /Users/louismedina/Desktop/MindtonicMedia/beautifulnow/spec/spec_helper.rb:3:in `<top (required)>'
    from /Users/louismedina/Desktop/MindtonicMedia/beautifulnow/spec/controllers/admin/admin_controller_spec.rb:1:in `require'
    from /Users/louismedina/Desktop/MindtonicMedia/beautifulnow/spec/controllers/admin/admin_controller_spec.rb:1:in `<top (required)>'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
    from /Users/louismedina/.rvm/gems/ruby-2.1.5@beautifulnow-rails4/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

有人对此有任何指导吗?谢谢。

4

2 回答 2

0

我似乎已经解决了这个问题。在我的“application.yml”文件中,我继续为这些变量提供了伪值,以便停止未定义的方法错误。

例如:

aws_access_key: '123456789'
aws_access_secret: '123456789'
aws_bucket: '123456789'
于 2015-03-04T02:42:21.357 回答
0

在 Figaro 0.7 之前,如果您尝试访问不存在的密钥,Figaro.env.my_non_existant_key您会得到一个异常。该异常具有误导性,因为 figaro 使用 Ruby 的元编程特性并且可以在运行时定义方法(因此Figaro.env["my_key1"]您可以调用方法而不是调用Figaro.env.my_key1)。

从 Figaro 1.0 开始,如果您调用,Figaro.env.my_non_existant_key您将获得nil返回值。如果您想确保在密钥不存在时引发异常,您可以使用带有 'bang' 的新语法Figaro.env.my_non_existant_key!

于 2015-07-21T04:23:05.143 回答