How exactly DO you integrate ckeditor with Paperclip so it can upload image files?

前端 未结 5 732
走了就别回头了
走了就别回头了 2021-02-01 08:44

How do you get http://github.com/galetahub/rails-ckeditor working so you can upload image files? I don\'t think I\'ll use the s3 storage...

any help would be appreciate

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 09:51

    Rails 4.2.0 solution:

    How do you get http://github.com/galetahub/rails-ckeditor working so you can upload image files?

    As is, CKEditor allows you to embed existing image URLs, but for CKEditor and Paperclip to work together so you can upload images, you will need ImageMagick. As I understand, it handles uploading the image data, making an image URL reference for the uploaded image data and the embedding of the uploaded image data's URL.


    CKEditor

    Add gem "ckeditor" to your Gemfile

    then run the $ bundle install command.


    Add this to /app/assets/javascripts/application.js

    //= require jquery
    //= require jquery_ujs
    //= require turbolinks
    //= require ckeditor/init  <--------------- THIS
    //= require_tree . <----------------------- ABOVE THIS
    

    per: https://github.com/galetahub/ckeditor#how-to-generate-models-to-store-uploaded-files

    Add this to:

    /config/routes.rb
    I put it before the resources which utilize it

    mount Ckeditor::Engine => '/ckeditor'  
    

    Using "form_for" and having set up an "Article" model with a title:string and text:text /app/views/articles/_form.html.erb

      

    <%= f.label :text %>
    <%= f.cktext_area :text, rows: 10 %> # <-------- "cktext_area"

    Using "simple_form_for"

      
    <%= f.input :body, :as => :ckeditor, input_html: {:ckeditor => {:toolbar => 'FULL'}}, class: "form-control" %>

    Paperclip

    per: https://richonrails.com/articles/getting-started-with-ckeditor

    Add gem "paperclip" to your Gemfile and $ bundle install.

    Then run the following two commands:

    $ rails generate ckeditor:install --orm=active_record --backend=paperclip

    and

    $ rake db:migrate


    ImageMagick

    For macOS Sierra:

    $ brew install imagemagick
    

    For other ImageMagick install options: https://www.imagemagick.org/script/install-source.php

提交回复
热议问题