Home CarrierWave not work with Cloudinary
Reply: 0

CarrierWave not work with Cloudinary

user4843
1#
user4843 Published in September 19, 2018, 3:16 am

In user.rb

class User < ApplicationRecord mount_uploader :picture, PictureUploader end

In picture_uploader.rb

class PictureUploader < CarrierWave::Uploader::Base

include Cloudinary::CarrierWave

storage :file

# This is a sensible default for uploaders that are meant to be mounted:

def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end

end

In environement.rb

require_relative 'application'

initialize the Rails application

Rails.application.initialize!

require 'carrierwave/orm/activerecord'

In _form.html.erb

<%= form.label :picture %>

<%= form.file_field :picture, id: :user_picture %>

In migration

class CreateUsers < ActiveRecord::Migration[5.1]

def change

create_table :users do |t|

  t.string :email

  t.string :picture

  t.timestamps

end

end

end

Finally User.picture_url is an url on Cloudinary but there isn't any image uploaded in this url.

And it works if I type in rails c Cloudinary::Uploader.upload('/home/my_image.jpg')

share|improve this question

2 Answers 2

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298592 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO