0
votes

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')

2

2 Answers

3
votes

The Cloudinary's hot line anwser :

"please comment out lines 10 and 15-17" in /app/uploader/pictures_uploader.rb

# storage :file

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

And it works.

0
votes

Have you in your app/assets/javascript/application.jsadded

//= require cloudinary/jquery.cloudinary

and in app/views/layouts/application.html.erb

    <%= yield(:after_js) %>
    <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
    <%= cloudinary_js_config %>

And in application.yml ( you will find yours in your cloudinary settings)

CLOUDINARY_URL: "cloudinary:/`/768932967533141:wF2ZZZrTuQ6R2Ynf_1mH3zk@dtrucdxbug"
#this a fake url ;-)

You problem is more in your show.html.erb :)

  <%= cl_image_tag(@user.picture.path, :secure => true,
                    :width => 100, :height => 150, :crop => :fill) %>

The setting here is just an exemple but you need @user.picture.path to display your picture :)

More info here https://cloudinary.com/documentation/rails_image_manipulation