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

前端 未结 5 731
走了就别回头了
走了就别回头了 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:40

    Use following things it working for me but you should have account on Amazon for s3 storage and correct endpoint you can refer following

    code.`gem 'aws-sdk', '~> 2'
    gem 'aws-s3'
    gem 'aws-sdk-v1'
    gem 'paperclip'
    
    class Ckeditor::Picture < Ckeditor::Asset
    
      AWS_CONFIG = YAML.load(ERB.new(File.read("#{Rails.root}/config/aws.yml")).result)[Rails.env]
    
      has_attached_file :data,
                        s3_credentials: {
                            access_key_id: AWS_CONFIG['access_key_id'],
                            secret_access_key: AWS_CONFIG['secret_access_key'],
                            bucket: AWS_CONFIG['bucket'],
                        },
                        s3_host_name: 's3.amazonaws.com',
                        :s3_endpoint => 's3.amazonaws.com',
                        storage: :s3,
                        s3_headers:     { "Cache-Control" => "max-age=31557600" },
                        s3_protocol:    "https",
                        bucket:         AWS_CONFIG['bucket'],
                        url: ':s3_domain_url',
                        path: '/:class/:attachment/:id_partition/:style/:filename',
                        default_url:   "/:class/:attachment/:id/:style/:basename.:extension",
                        default_style: "medium"
    
      validates_attachment_size :data, :less_than => 2.megabytes
      validates_attachment_presence :data
    
      def url_content
        url(:content)
      end
    end
    

    `

    comment this line require "ckeditor/orm/active_record" from /config/initializers

    finally put this line in <%= f.cktext_area :body %> view file.

提交回复
热议问题