Rails应用的种子cloudinary照片 [英] seed cloudinary photos for rails app

查看:82
本文介绍了Rails应用的种子cloudinary照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些cloudinary的照片,我想做个种子(在我的rails应用中)。
我正在使用Carrierwave。

I have some cloudinary's photos and I would like to make a seed (in my rails app). I'm using Carrierwave.

在种子中,我尝试放置cloudinary的url图片:

In my seed, I try to put the cloudinary's url image :

Course.create! ({
  photo: "fismpnq3zma80dc2ovjt.jpg"
)}

但这是不行我该怎么办?

But it's don't work. What can I do ?

如果我通过控制台询问:

If I ask by console :

pry(main)> c = Course.first
....
pry(main)> c.photo

@cache_id=nil,
@file=nil,
@filename=nil,
....
@model=#<Way:0x00007f80e7a3a9c0
photo:nil,
....
@mounted_as=:photo,
@versions=nil>


推荐答案

为了使用 create 方法,则需要先验证参数(通过签名),然后SDK才能保存它们。

In order to use the create method, the parameters need to be verified (by signature) before the SDK will save them.

例如:

resource_type = "image" 
type = "upload"
version = 1234567890
public_id = "fismpnq3zma80dc2ovjt"
format = "jpg"
signature = Cloudinary::Utils.api_sign_request({:public_id=>public_id, 
:version=>version}, Cloudinary.config.api_secret)
photo = "#{resource_type}/#{type}/v#{version}/#{public_id}.#{format}## 
{signature}"
Course.create!({ photo: photo )}

请告诉我它是否对您有用。

Please let me know if it works for you.

-Yakir

这篇关于Rails应用的种子cloudinary照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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