问题
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:
You can use the following syntax:
<%= post_form.cl_image_upload(:picture) %>
来源:https://stackoverflow.com/questions/14058000/how-to-associate-direct-upload-fields-with-a-model-using-cloudinary-in-rails