Ruby on rails 更新属性不会';行不通
我有两个专栏:Ruby on rails 更新属性不会';行不通,ruby-on-rails,carrierwave,inherited-resources,Ruby On Rails,Carrierwave,Inherited Resources,我有两个专栏: background_image_id (which is a relation) background_image (which is a copy of that image, with various versions) 在更新之前的方法中,我必须将Carrierwave文件从Medium.find(background\u image\u id)复制到background\u image列中 我做不到。NIL被存储到数据库中。不知道为什么 控制器: def updat
background_image_id (which is a relation)
background_image (which is a copy of that image, with various versions)
在更新之前的方法中,我必须将Carrierwave文件从Medium.find(background\u image\u id)
复制到background\u image
列中
我做不到。NIL被存储到数据库中。不知道为什么
控制器:
def update
if params[:profile].blank? || params[:profile][:background_image_id].blank?
flash[:alert] = 'Please select image'
redirect_to edit_candidate_background_image_path
else
resource.background_image_id = params[:profile][:background_image_id]
if resource.save
flash[:notice] = 'Profile was updated'
else
flash[:alert] = "Can't update profile"
end
redirect_to edit_candidate_background_image_path
end
end
型号:
before_update :copy_background_image, if: :background_image_id_changed?
...
def copy_background_image
medium = Medium.find(background_image_id)
if medium.present?
self.background_image = medium.image.file
puts self.inspect # outputs a model where background_image is nil
puts self.background_image.inspect # outputs an uploader with correct image PRESENT
end
end
您有哪些上传程序选项?文件或S3(外部存储)已解决。谢谢