Answer the question
In order to leave comments, you need to log in
[RoR] How to get the previous paperclip image if the form is not valid?
There is a form with image validation for size and type. If the validation fails, then I need to return the old value of the form, but it turns out that a new image arrives that has not been uploaded to the server and, as a result, the photo preview shows a non-existent file. A normal model attribute can be obtained by adding the _was postfix. This does not work with paperclip.
before_post_process :skip_if_invalid
def skip_if_invalid
unless self.valid?
self.image = self.image_was # И теперь image_tag(model.image.url) покажет предыдущую картинку
return false
end
end
Answer the question
In order to leave comments, you need to log in
I can suggest using this trick , then even if the validation fails, the new image will remain.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question