我目前在为我的Rails 4应用程序配置Figaro时遇到问题。每当我尝试运行RSpec或rake db:migrate时,我都会遇到以下错误:
method_missing': undefined method
aws_access_key' for {}:Figaro :: Env
以下是完整的错误消息供参考:
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'
有人对此有任何指导吗?感谢。
答案 0 :(得分:0)
例如:
aws_access_key: '123456789'
aws_access_secret: '123456789'
aws_bucket: '123456789'
答案 1 :(得分: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!
的新语法。