LoginSignup
2
3

More than 5 years have passed since last update.

rails + heroku で ckeditor を導入する

Posted at

※事前にrailsやckeditorなどをダウンロードした時点の状態でherokuにアップロードしていきます。ckeditorの導入などは

ruby on railsのckeditor gemの使い方をscaffoldを用いて解説する

などを参照。

環境

rails 5.0.7
ckeditor 4.2.4

lib/tasksフォルダ―にckeditor.rake fileを作る

以下のコードを作成しておく。

ckeditor.rb
require 'fileutils'

desc "Create nondigest versions of all ckeditor digest assets"
task "assets:precompile" do
  fingerprint = /\-[0-9a-f]{32}\./
  for file in Dir["public/assets/ckeditor/**/*"]
    next unless file =~ fingerprint
    nondigest = file.sub fingerprint, '.'
    FileUtils.cp file, nondigest, verbose: true
  end
end

[参考文献]https://github.com/galetahub/ckeditor/issues/307#issuecomment-22186377

config/application.rbでのconfig設定を追加する

application.rb
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/*)

[参考文献]https://github.com/galetahub/ckeditor/issues/307#issuecomment-22186377

次のコマンドを実行し、herokuにpushする。

rake assets:precompile
rake ckeditor
git push heroku master

僕の場合、これでherokuに反映されました。

終わりに

 オリジナルサイトを作成するうえで投稿機能を付けるためにckeditorを導入しましたがherokuにアップロードするとckeditorが正しく表示されないことでハマりました。rails 自体自分で勉強して4か月ほどで上記の記事は理解できませんでした。誰かの参考になればと思います。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3