lundi 29 juin 2015

Rails: CKEditor, paperclip, and s3 errors

I tried adding the editor to my rails app using amazons3 and paperclip but im having errors. If I cant get this to work, what other editors are available that would work? Here is the error I got below

ArgumentError in Ckeditor::PicturesController#create
missing required :bucket option

Extracted source (around line #218):
216
217
218
219
220
221

        @bucket = @options[:bucket] || s3_credentials[:bucket]
        @bucket = @bucket.call(self) if @bucket.respond_to?(:call)
        @bucket or raise ArgumentError, "missing required :bucket option"
      end

      def s3_interface

I'm not sure what to do as I followed these steps.

gem 'paperclip'
gem 'ckeditor'

then bundled

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

rake migrated

mount Ckeditor::Engine => "/ckeditor"

added this to application.js

//= require ckeditor/init

added this to the view page

    <%= f.cktext_area :content, :class => "form-control" %>


These are the files created and their configuration

/Ckeditor/Picture.rb

class Ckeditor::Picture < Ckeditor::Asset
  has_attached_file :data,
                    :url  => ":s3_domain_url",
                    :path =>         "/:class/:attachment/:id_partition/:style/:filename",
                    :styles => { :content => '800>', :thumb => '118x100#' }

  validates_attachment_presence :data
  validates_attachment_size :data, :less_than => 2.megabytes
  validates_attachment_content_type :data, :content_type => /\Aimage/

  def url_content
    url(:content)
  end
end

/Ckeditor/attachment_file.rb

  class Ckeditor::AttachmentFile < Ckeditor::Asset
  has_attached_file :data,
                    :url => "/ckeditor_assets/attachments/:id/:filename",
                    :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"

  validates_attachment_presence :data
  validates_attachment_size :data, :less_than => 100.megabytes
  do_not_validate_attachment_file_type :data

  def url_thumb
    @url_thumb ||= Ckeditor::Utils.filethumb(filename)
  end
end

/Ckeditor/asset.rb

class Ckeditor::Asset < ActiveRecord::Base
  include Ckeditor::Orm::ActiveRecord::AssetBase
  include Ckeditor::Backend::Paperclip
end


I use these lines of code in development.rb and production.rb and I haven't had any issues with paperclip before with s3.

config.paperclip_defaults = {
:storage => :s3,
:s3_protocol => 'http',
:bucket => ENV['AWS_BUCKET'],
:s3_credentials => {
  :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
  :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
    }

This is the paperclip.rb file

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

Aucun commentaire:

Enregistrer un commentaire