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

蓝咒 提交于 2019-12-07 05:25:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!