How To add Cloudinary With ckeditor in ruby on rails.How can we configure cloudinary with ruby on rails in heroku? How can we host image free in ruby on rails

Total Blog Views: 89

Blog Status: publish

Created By: swazahmad Created at: 07-11-2021

Tags:

You can refer the blog to configure the ckeditor in rails for adding the cloudinary with heroku you just need to the addons and need to add only one line

 you use Rails 3.x or later, edit your Gemfile, add the following line and run bundle.

 gem 'cloudinary'

include Cloudinary::CarrierWave #include the line in your uploader

 

By following above you can configure the Cloudinary in rails application with heroku

Configure cloudinary for ckeditor

Do the changes like below

You can resolve send it now cloudinary issue by chnaging the below files in ruby on rails application

app/models/ckeditor/attachment_file.rb

class Ckeditor::AttachmentFile < Ckeditor::Asset
  mount_uploader :data, CkeditorAttachmentFileUploader, mount_on: :data_file_name

  def url_thumb
    @url_thumb ||= Ckeditor::Utils.filethumb(filename)
  end
end
Change app/models/ckeditor/picture.rb 

class Ckeditor::Picture < Ckeditor::Asset
  mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name
  def url_content
    url(:content) || begin
      if persisted?
        reload
        url(:content)
      end
    end
  end
end

 

#Do the changes in app/uploaders/ckeditor_attachment_file_uploader.rb
require 'carrierwave'

class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
  include Ckeditor::Backend::CarrierWave
  # include Ckeditor::Backend::CarrierWave
  include Cloudinary::CarrierWave

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_white_list
    Ckeditor.attachment_file_types
  end
end


#Replace the picture uploader file app/uploaders/ckeditor_picture_uploader.rb
class CkeditorPictureUploader < CarrierWave::Uploader::Base
 include Cloudinary::CarrierWave
 CarrierWave.configure do |config|
   config.cache_storage = :file
 end

  # Create different versions of your uploaded files:
  version :thumb do
    process resize_to_fill: [118, 100]
  end

  version :content do
    process resize_to_limit: [800, 800]
  end

end

 

You can see the sample Image cloudinary with ckeditor below


swazahmad

Swaz is Practice Lead of ROR Developer. he's a Blogger, Mentor, and Rubyst. He has expertise in Javascript also . he's highly skilled in designing, developing and testing web applications. He enjoys being challenged and interesting with projects that need him to



Comments



  • swazahmad | almost 4 years ago
    Awesome Information Thanks For Sharing
Buy traffic for your website

About Shadbox

we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.

Services

Downloads