Paperclip/S3/Ckeditor 的“缺少必需的 :bucket 选项”
“missing required :bucket option” for Paperclip/S3/Ckeditor
我尝试使用 amazons3 和回形针将编辑器添加到我的 rails 应用程序,但我遇到了错误。如果我不能让它工作,还有哪些其他可用的编辑器可以工作?下面是我得到的错误
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
我在执行这些步骤时不确定该怎么做。
gem 'paperclip'
gem 'ckeditor'
然后捆绑
rails generate ckeditor:install --orm=active_record --backend=paperclip
rake 已迁移
mount Ckeditor::Engine => "/ckeditor"
将此添加到 application.js
//= require ckeditor/init
将此添加到查看页面
<%= f.cktext_area :content, :class => "form-control" %>
这些是创建的文件及其配置
/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
我在 development.rb
和 production.rb
中使用了这些代码行,并且在使用 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']
}
}
这是 paperclip.rb
文件
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
我假设您正在 heroku 中部署。所以需要为s3 bucket变量设置heroku环境变量:
heroku config:set S3_BUCKET_NAME='Your Bucket Name'
heroku config:set AWS_ACCESS_KEY_ID='Your AWS ID'
heroku config:set AWS_SECRET_ACCESS_KEY='Your AWS Secrete Key'
如果您在开发(本地)中,则需要定义此变量。否则从 development.rb
中删除配置代码
我尝试使用 amazons3 和回形针将编辑器添加到我的 rails 应用程序,但我遇到了错误。如果我不能让它工作,还有哪些其他可用的编辑器可以工作?下面是我得到的错误
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
我在执行这些步骤时不确定该怎么做。
gem 'paperclip'
gem 'ckeditor'
然后捆绑
rails generate ckeditor:install --orm=active_record --backend=paperclip
rake 已迁移
mount Ckeditor::Engine => "/ckeditor"
将此添加到 application.js
//= require ckeditor/init
将此添加到查看页面
<%= f.cktext_area :content, :class => "form-control" %>
这些是创建的文件及其配置
/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
我在 development.rb
和 production.rb
中使用了这些代码行,并且在使用 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']
}
}
这是 paperclip.rb
文件
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
我假设您正在 heroku 中部署。所以需要为s3 bucket变量设置heroku环境变量:
heroku config:set S3_BUCKET_NAME='Your Bucket Name'
heroku config:set AWS_ACCESS_KEY_ID='Your AWS ID'
heroku config:set AWS_SECRET_ACCESS_KEY='Your AWS Secrete Key'
如果您在开发(本地)中,则需要定义此变量。否则从 development.rb
中删除配置代码