You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works well when instantiating the PostForm from the model, but becomes complicated when using from_params. So specifically when a validation fails, you render :edit again with PostForm initialized from_params. Now, you get the page again, but the image we just selected is gone.
Also, since the form object can be from_params, you cannot rely on getting the actually file like f.object.image.url, since you're not submitting the actual file every time. So now I add attribute :image_url so I can show a link to it if the file is already uploaded.
I hope that made sense, do you have any experience with Rectify + file uploads?
The text was updated successfully, but these errors were encountered:
Hi @bramj! I don't know if you still have this issue, but I'm using Carrierwave + form objects successfully in my project.
First, I have the mount_uploader :image, ImageUploader line in my model. Then, in my form object I define the file attributes without any explicit type:
attribute:name,Stringattribute:image
With that, I can successfully use MyForm.from_params(params) from the controller.
@mrcasals , not exactly . It works, but it doesn't works with preview urls ( If validation of form fails, I want to show a preview of image), so, on my app I must cache it manually
classBookForm < Rectify::Formattribute:imageattribute:image_urlattribute:image_cachedefcache_imagereturnifimage.blank?b=Book.newb.image=imageifimage.present?b.remote_image_url=remote_image_urlifremote_image_url.present?self.image_url=b.image.url# relative path for previewself.image_cache=b.image_cacheendend
Hi @andypike,
The thing I've been struggling most with is the combination of form objects + file uploads.
So a I'm trying to add a picture to a blog post with CarrierWave:
This works well when instantiating the
PostForm
from the model, but becomes complicated when usingfrom_params
. So specifically when a validation fails, you render:edit
again withPostForm
initializedfrom_params
. Now, you get the page again, but the image we just selected is gone.This sort of thing can normally be fixed by saving a cached version of the image https://github.com/carrierwaveuploader/carrierwave#making-uploads-work-across-form-redisplays. But if our form is not valid, we never save anything to the model, so I guess this goes against the whole idea of form objects.
Also, since the form object can be
from_params
, you cannot rely on getting the actually file likef.object.image.url
, since you're not submitting the actual file every time. So now I addattribute :image_url
so I can show a link to it if the file is already uploaded.I hope that made sense, do you have any experience with Rectify + file uploads?
The text was updated successfully, but these errors were encountered: