你怎么获得 http://github.com/galetahub/rails-ckeditor 工作,所以你可以上传图像文件?我不认为我会使用s3存储...
任何帮助,将不胜感激。
你怎么获得 http://github.com/galetahub/rails-ckeditor 工作,所以你可以上传图像文件?我不认为我会使用s3存储...
任何帮助,将不胜感激。
是的你可以。我假设您已经为S3设置了回形针。所以你只需在你的模型目录(app / model / ckeditor /)中编辑picture.rb和attachement_file.rb并替换这些行
has_attached_file :data,
:url => "/ckeditor_assets/attachments/:id/:filename",
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
与您的papeclip版本has_attached_file:
has_attached_file :data, :styles => { :content => '575>', :thumb => '80x80#' },
:storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => ":attachment/:id/:style.:extension",
:url => ":s3_domain_url"
而已。顺便说一句:这是Rails 3的例子。
是的你可以。我假设您已经为S3设置了回形针。所以你只需在你的模型目录(app / model / ckeditor /)中编辑picture.rb和attachement_file.rb并替换这些行
has_attached_file :data,
:url => "/ckeditor_assets/attachments/:id/:filename",
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"
与您的papeclip版本has_attached_file:
has_attached_file :data, :styles => { :content => '575>', :thumb => '80x80#' },
:storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => ":attachment/:id/:style.:extension",
:url => ":s3_domain_url"
而已。顺便说一句:这是Rails 3的例子。
我会跟着 自述 你提到的rails-ckeditor插件。如果您不需要SWFUpload,您可以简单地完成 集成CKEditor和Paperclip,通过编写自定义文件上传器和自定义文件浏览器,并通过指定URL和回调函数将它们连接到编辑器。
有一个例子总是有用的,作者已经做了一个 示例应用。不幸的是,它有一些错误。考虑以下几点使其运行
更改以下行 config/environment.rb
config.gem 'paperclip', :version => '2.3.3'
config.gem 'ckeditor', :version => '3.4.1'
删除文件 index.html
公开的;当众
添加到route / routes.rb的根路由
map.root :controller => "pages"
Rails 4.2.0解决方案:
你怎么获得 http://github.com/galetahub/rails-ckeditor 工作,所以你可以上传图像文件?
因此,CKEditor允许您嵌入现有的图像URL,但是对于CKEditor和Paperclip一起工作以便您可以上传图像,您将需要ImageMagick。据我了解,它处理上传图像数据,为上传的图像数据制作图像URL参考,以及嵌入上传的图像数据的URL。
加 gem "ckeditor"
到您的Gemfile
然后运行 $ bundle install
命令。
将其添加到/app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require ckeditor/init <--------------- THIS
//= require_tree . <----------------------- ABOVE THIS
每: https://github.com/galetahub/ckeditor#how-to-generate-models-to-store-uploaded-files
将此添加到:
/config/routes.rb
我把它放在了之前 resources
利用它
mount Ckeditor::Engine => '/ckeditor'
使用“的form_for“并设置了一个带有标题的”文章“模型:字符串和文本:文本 /app/views/articles/_form.html.erb
<p>
<%= f.label :text %><br>
<%= f.cktext_area :text, rows: 10 %> # <-------- "cktext_area"
</p>
使用“simple_form_for“
<div class="form-group">
<%= f.input :body, :as => :ckeditor, input_html: {:ckeditor => {:toolbar => 'FULL'}}, class: "form-control" %>
</div>
每: https://richonrails.com/articles/getting-started-with-ckeditor
加 gem "paperclip"
到您的Gemfile和 $ bundle install
。
然后运行以下两个命令:
$ rails generate ckeditor:install --orm=active_record --backend=paperclip
和
$ rake db:migrate
对于macOS Sierra:
$ brew install imagemagick
对于其他ImageMagick安装选项: https://www.imagemagick.org/script/install-source.php
除了Zaparka的回复,我不得不删除#{Rails.root},因为我得到了一个整体常量错误。所以我放了“/config/s3.yml”,这很有效。
使用以下对我有用的东西,但你应该在亚马逊上有s3存储帐户和正确的终端,你可以参考下面的内容
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
`
评论这一行 require "ckeditor/orm/active_record"
来自/ config / initializers
终于把这条线放进去了 <%= f.cktext_area :body %>
查看文件。