Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to associate direct upload fields with a model using Cloudinary in Rails?

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?

like image 691
hlh Avatar asked Oct 06 '22 12:10

hlh


1 Answers

You can use the following syntax:

<%= post_form.cl_image_upload(:picture) %>
like image 54
Tal Lev-Ami Avatar answered Oct 10 '22 17:10

Tal Lev-Ami