如何在Rails中使用Cloudinary将直接上传字段与模型相关联? [英] How to associate direct upload fields with a model using Cloudinary in Rails?

查看:54
本文介绍了如何在Rails中使用Cloudinary将直接上传字段与模型相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Cloudinary及其Carrierwave插件,我可以在视图中编写一个表单,该表单会将图像上传到他们的云并将其绑定到名为 picture 的模型属性中,如下所示:

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

这有效。但是,在遵循文档以在Rails中直接上传。他们的示例使用了未绑定到模型的form_tag:

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

我正在寻找一些例子,例如<%= post_form。 some_upload_method(:picture)%> 。有人为自己的模型直接上传文件并知道我在找什么吗?

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?

推荐答案

以下语法:

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

这篇关于如何在Rails中使用Cloudinary将直接上传字段与模型相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆