5
votes

With Cloudinary and their Carrierwave plugin I can write a form in my view that will upload an image to their cloud and bind it to a model attribute called picture, like so:

<%= form_for(@post) do |post_form| %>
  <%= post_form.hidden_field(:picture_cache) %>
  <%= post_form.file_field(:picture) %>
<% end %>

This works. But I can't figure out how to bind the attribute to the model while following their documentation for direct uploads in Rails. Their example uses a form_tag that isn't bound to a model:

<%= form_tag(some_path, :method => :post) do  %>
  <%= cl_image_upload_tag(:image_id) %>
    ...
<%= end %>

I'm looking for some example that's like <%= post_form.some_upload_method(:picture) %>. Any chance someone else has done this for direct uploads for their models and knows what I'm looking for?

1
I do this using an ajax request once the file is successfully uploadedapneadiving
In your case: When the upload is complete, your image's Cloudinary public ID will be added to your original form and submitted to your server. Use this public ID when you want to access the uploaded image in the future, either in its original form or after using Cloudinary's on-demand image transformations. You can also get the plugin to call a Javascript callback routine when uploading to Cloudinary is completed.apneadiving

1 Answers

4
votes

You can use the following syntax:

<%= post_form.cl_image_upload(:picture) %>