gpt4 book ai didi

ruby-on-rails - 测试环境 - 回形针错误

转载 作者:行者123 更新时间:2023-11-28 20:57:50 24 4
gpt4 key购买 nike

我正开始为一个应用程序编写测试,但我无法让测试环境正常工作。我的系统有用于文件上传的 Paperclip,它在任何尝试启动服务器甚至初始化新公司记录时都会出错!一个例子:

# Company.rb line 3
has_attached_file :photo,
:styles => {:medium => "200x300>", :thumb => "100x150>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/photos/:style/:id/:basename.:extension"

# console
ruby-1.9.2-p0 :001 > Company.new
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=
from /Users/san/Documents/san/app/vendor/plugins/paperclip/lib/paperclip.rb:232:in 'has_attached_file'
from /Users/san/Documents/san/app/app/models/company.rb:3:in '<class:company>'
from /Users/san/Documents/san/app/app/models/company.rb:1:in '<top (required)>'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'load'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:454:in 'block in load_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in 'new_constants_in'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:453:in 'load_file'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:340:in 'require_or_load'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:491:in 'load_missing_constant'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in 'block in const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'each'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in 'const_missing'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in 'const_missing_from_s3_library'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in 'const_missing'
from (irb):1
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in 'start'
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in '<top (required)>'
from script/rails:6:in 'require'

您知道导致此冲突的原因以及我该如何解决吗?


我通读了 Paperclip 文档,发现需要添加:

require 'paperclip/matchers'
Spec::Runner.configure do |config|
config.include Paperclip::Shoulda::Matchers
end

spec_helper.rb。仍然出现同样的错误!

最佳答案

我想那是什么 s3.yml 不包含当前 Rails 环境的 key ,可能是 test?加一个。这应该可以解决它!

关于ruby-on-rails - 测试环境 - 回形针错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7185493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com