gpt4 book ai didi

ruby-on-rails - 突然ArgumentError : invalid byte sequence in UTF-8 while seeding

转载 作者:太空宇宙 更新时间:2023-11-03 18:06:11 25 4
gpt4 key购买 nike

在开发我的 Rails 应用程序时,我尝试了一些裁剪图像的方法,我从 Rails Casts #182 开始,回到我以前拥有的,然后回到这个 blog post ,在完成所有设置后,我决定重新启动我的数据库并为它做种,但是当我尝试为我的数据库做种时,我得到了 ArgumentError: Invalid byte sequence in UTF-8

在一些小的研究之前和之后我从未遇到过这个错误我发现这是由于某些字符无法被 ruby​​ 读取,但是,在浏览我的代码之后我发现我之前的没有什么区别我从裁剪图像开始,在进一步检查后我还没有找到原因。

我还没有学习如何阅读和跟踪 rails/rake 错误也无济于事,这是我得到的:

rails aborted!
ArgumentError: invalid byte sequence in UTF-8
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.1/lib/active_support/core_ext/object/blank.rb:118:in `==='
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.1/lib/active_support/core_ext/object/blank.rb:118:in `blank?'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/sanitized_file.rb:131:in `is_path?'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/sanitized_file.rb:97:in `size'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/sanitized_file.rb:140:in `empty?'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/cache.rb:120:in `cache!'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/mounter.rb:44:in `block in cache'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/mounter.rb:42:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/mounter.rb:42:in `map'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/mounter.rb:42:in `cache'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/mount.rb:300:in `main_image='
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-1.1.0/lib/carrierwave/orm/activerecord.rb:70:in `main_image='
/usr/local/rvm/gems/ruby-2.3.0/gems/activemodel-5.0.1/lib/active_model/attribute_assignment.rb:46:in `public_send'
/usr/local/rvm/gems/ruby-2.3.0/gems/activemodel-5.0.1/lib/active_model/attribute_assignment.rb:46:in `_assign_attribute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activemodel-5.0.1/lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
/usr/local/rvm/gems/ruby-2.3.0/gems/activemodel-5.0.1/lib/active_model/attribute_assignment.rb:39:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activemodel-5.0.1/lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
/usr/local/rvm/gems/ruby-2.3.0/gems/activemodel-5.0.1/lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/core.rb:319:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/inheritance.rb:65:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/inheritance.rb:65:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/persistence.rb:50:in `create!'
/home/ubuntu/workspace/db/seeds.rb:60:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/engine.rb:549:in `load_seed'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/database_tasks.rb:268:in `load_seed'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.1/lib/active_record/railties/databases.rake:196:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
/home/ubuntu/workspace/bin/rails:9:in `require'
/home/ubuntu/workspace/bin/rails:9:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
/home/ubuntu/workspace/bin/spring:15:in `require'
/home/ubuntu/workspace/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

我的主要问题是这个错误究竟发生在哪里?到目前为止,我已经通过经验了解到它可能是 seeds.rb 或模型(在本例中是 event.rb)但是我没有看到任何不同我之前让他们都工作过,我什至能够上传图像并为它们播种没问题,直到我从 Rails Cast 中实现和删除代码并在博客文章中实现代码,解决方案的任何方向都会有很大帮助.

这是模型的种子,它事先运行良好。

Event.create!(
name: " 1",
spanish_description: "El mejor programa para este sábado con los peques ! #kids #gratis #petfriendly. En Kuchitril. De 6 a 10 pm. #localmarket #tendencias #buenavibra. #corranlavoz!",
english_description: "El mejor programa para este sábado con los peques ! #kids #gratis #petfriendly. En Kuchitril. De 6 a 10 pm. #localmarket #tendencias #buenavibra. #corranlavoz!",
place_name: "mamita's",
place_type: "beach club",
address: "Calle 28 Norte Mza 10, Lote 8, Centro",
county: 'meh',
city: "Playa del Carmen",
state: "Quintana Roo",
postal_code: 77710,

user_id: 1,
main_image: File.open(File.join(Rails.root, 'test.jpg')),
sub_images: [File.open(File.join(Rails.root, 'chinchi.jpg'))],


eventdates_attributes:[{
start_date: Time.now.in_time_zone("Eastern Time (US & Canada)"),
finish_date: Time.now.in_time_zone("Eastern Time (US & Canada)"),
start_hour: "08:00am",
finish_hour: "11:00am",
}],

tickets_attributes:[{
ticket_type: "Solo una vez",
price: 100,
currency: "mxn",
quantity: 150,
description: "Un boleto muy divertido!"
}, {
ticket_type: "Otra vez",
price: 150,
currency: "mxn",
quantity: 150,
description: "Un boleto muy divertido!"
}]
)

重要编辑: 所以我决定只返回到以前的提交只是为了不再处理这个问题,并且由于某种原因错误不断弹出,这让我相信存在问题对于我正在使用的平台,即 Cloud9,我还读到这不是 Rails 5.0 上应该发生的问题

最佳答案

我找到了问题的原因,我正在使用 mount_uploaders 进行单个上传,使上传成为一个数组,从而产生了错误。将其更改为 mount_uploader 是解决方案,您确实必须注意这些细节,嗯,吸取教训。我建议关闭这个问题,除非它对新手有点用处。

关于ruby-on-rails - 突然ArgumentError : invalid byte sequence in UTF-8 while seeding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44917605/

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