Skip to content

File uploads #33

Description

@bramj

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:

class PostForm < Rectify::Form
  extend CarrierWave::Mount
  mount_uploader :image, ImageUploader

  attribute :image
end

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.

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 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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions