gpt4 book ai didi

ruby-on-rails - Rails事件记录重复并保存失败

转载 作者:行者123 更新时间:2023-12-04 05:42:28 25 4
gpt4 key购买 nike

我有这个错误:Errno::ENOENT in PicturethingsController#update_profile
No such file or directory - /Users/Baz/rails/myapp/public/uploads/picturething/picture/49/cat.jpg
我正在尝试复制standardpicture记录并将其保存到@ character.profilepicture。我也无法获取@ character.profilepicture保存到数据库(从进入rails控制台后的检查中我知道)。

这是令人反感的方法:

picturethings_controller.rb:

def update_profile
@character = Character.find_by(callsign: params[:callsign])
standardpicture = Picturething.find_by(id: params[:picid])
@character.build_profilepicture
@character.profilepicture.save!
@character.profilepicture = standardpicture.dup
@character.profilepicture.save!
@character.profilepicture.picture.recreate_versions!
@character.profilepicture.picture = @character.profilepicture.picture.profile
respond_to do |format|
format.html do
redirect_to @character.sociable
end
format.js
end
end

character.rb:
has_many :standardpictures, class_name: "Picturething",
inverse_of: :character,
foreign_key: "character_standard_id",
dependent: :destroy
has_one :profilepicture, class_name: "Picturething",
inverse_of: :character,
foreign_key: "character_profile_id",
dependent: :destroy

picturething.rb:
mount_uploader :picture, CharacterpicUploader

最佳答案

@character.profilepicture = standardpicture.dup

问题在于它仅复制ActiveRecord对象的属性,但不会复制磁盘上的实际图片,因此当您这样做时
@character.profilepicture.picture = @character.profilepicture.picture.profile

它会引发 No such file or directory错误。尝试使用 this gem帮助您在AR记录之间复制CarrierWave附件。

关于ruby-on-rails - Rails事件记录重复并保存失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31387982/

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