ruby-on-rails - nil 的未定义方法“匹配”:NilClass 在保存带有载波附件的对象时
问题描述
控制器似乎正在平稳地移动:
Pict Create (0.8ms) INSERT INTO "picts" ("usercontent_id", "image", "caption", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["usercontent_id", 94], ["image", "croc1.jpg"], ["caption", "emotional rescue"], ["user_id", 11], ["created_at", "2019-05-13 20:11:03.353852"], ["updated_at", "2019-05-13 20:11:03.353852"]]
↳ app/controllers/picts_controller.rb:36
(0.6ms) ROLLBACK
但回滚save
命令(下面的第 3 行)
@pict = Pict.new(pict_params)
authorize @pict
@pict.save
我删除了所有验证(尽管在 rails 5.2 中,belongs_to 被强制执行——我仍然通过设置进行了测试optional: true
),包括一个文件大小验证器......结果总是一样的。
坦率地说,我什至无法想象 nil 除了适用于什么之外@pict
,但它的所有属性都有适当的参数,并通过 Pundit 策略进行访问控制。
因此,我假设载波引擎有问题。carrierwave-aws
也安装和相同
CarrierWave.configure do |config|
设置用作现有的功能应用程序。该模型声明
mount_uploader :image, ImageUploader
谁反过来:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :aws
参数确实显示了一个图像文件被放置在一个临时 bin 中。
{"utf8"=>"✓",
"authenticity_token"=>"/ZY1FmOBBlVUdfayK3w7ws+4JgrbLt7U9gjvdyniOIqPMfvB10TUYEgvlDyyTTN9SCOu2zbYdb39Ydd37XdXvg==",
"pict"=>
{"nazione_id"=>"15",
"image"=>
#<ActionDispatch::Http::UploadedFile:0x00007f72d76516b0
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"pict[image]\"; filename=\"croc1.jpg\"\r\n" + "Content-Type: image/jpeg\r\n",
@original_filename="croc1.jpg",
@tempfile=#<File:/tmp/RackMultipart20190513-9509-f934ua.jpg>>,
"caption"=>"emotional rescue",
"regione_id"=>""},
"usercontent_point"=>"Mitchell street darwin",
"commit"=>" Add ",
"locale"=>"en"}
是什么导致了undefined method 'match' for nil:NilClass
错误?
更新
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:82:in `block in partition_matching_region'
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:81:in `each'
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:81:in `find'
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:81:in `partition_matching_region'
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:70:in `get_partition'
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:23:in `signing_region'
aws-partitions (1.151.0) lib/aws-partitions/endpoint_provider.rb:99:in `signing_region'
aws-sdk-s3 (1.36.1) lib/aws-sdk-s3/plugins/s3_signer.rb:20:in `block in <class:S3Signer>'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:70:in `call'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:213:in `block in resolve_defaults'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:57:in `each'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:57:in `each'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:212:in `resolve_defaults'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:205:in `value_at'
aws-sdk-core (3.48.4) lib/seahorse/client/configuration.rb:189:in `block in resolve'
解决方案
undefined method 'match' for nil:NilClass
表示该方法试图在空的东西上运行。
正如一条评论所建议的,这可能是一个糟糕的配置。
另一个假设是没有什么可以匹配的。缺少整个配置块。该文件可能位于错误的目录中或不存在。
这种特殊情况对deploy.rb
开发服务器的配置错误,没有指向材料文件的符号链接
推荐阅读
- python - 尝试安装 postgis 时出现错误:“postgis_lib_version”或附近的语法错误
- java - 在java中使用while循环的星号金字塔
- javascript - 如何在 D3 中重用两个(或更多)链式转换序列
- pseudocode - 下面写的伪代码对问题是否正确(写一个伪代码来确定给定的数字是否是素数)?
- python - 如何在pycharm中运行程序时检测用户键盘按下
- java - 布尔条件始终评估为真
- ruby-on-rails - 如何进一步重构 ruby 哈希
- java - 程序编译时的错误
- urn - 国家代码的标准 URN?
- java - 文件拆分并写入多个文件