我有 3 个models
。和。_ question
_ 我正在使用图像。并且可以有。answer
photo
paperclip
save
Questions
answers
multiple images
但是,我在为模型ROLLBACK
保存图像时得到了。为模型保存图像时answer
我没有得到。我觉得我有问题。ROLLBACK
question
model associations
#photo model
class Photo < ApplicationRecord
belongs_to :question
belongs_to :answer
has_attached_file :image :path => ":rails_root/public/img/:filename", validate_media_type: false
do_not_validate_attachment_file_type :image
end
#answer model
class Answer < ApplicationRecord
belongs_to :question
has_many :photos
end
#question model
class Question < ApplicationRecord
has_many :answers
has_many :photos
end
我的控制器:
p.answers.each do |a|
new_answer = q.answers.create(body: a[:body])
if a[:images]
a[:images].each do |e|
new_answer.photos.create(image: URI.parse('www.abc.com/'+e))
end
end
end
有什么想法吗?