我正在使用这个CKEditor gem:https://github.com/galetahub/ckeditor
我已按照自述文件中的说明操作,但当我尝试放置f.cktext_area
时,我会得到一些404:
GET http://localhost:5000/ckeditor/config.js?t=DAED 404 (Not Found) ckeditor.js?body=1:78
GET http://localhost:5000/ckeditor/skins/moono/editor.css?t=DAED 404 (Not Found) ckeditor.js?body=1:78
GET http://localhost:5000/ckeditor/lang/en.js?t=DAED 404 (Not Found) ckeditor.js?body=1:78
Uncaught TypeError: Cannot set property 'dir' of undefined ckeditor.js?body=1:214
我已经rails generate ckeditor:install --orm=active_record --backend=paperclip
和rake db:migrate
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
位于application.rb
mount Ckeditor::Engine => '/ckeditor'
位于routes.rb
而//= require ckeditor/init
在我的JS ......
我还重启了我的开发服务器,但我仍然得到这些404.
在我的rake routes
:
ckeditor /ckeditor Ckeditor::Engine
Routes for Ckeditor::Engine:
pictures GET /pictures(.:format) ckeditor/pictures#index
POST /pictures(.:format) ckeditor/pictures#create
picture DELETE /pictures/:id(.:format) ckeditor/pictures#destroy
attachment_files GET /attachment_files(.:format) ckeditor/attachment_files#index
POST /attachment_files(.:format) ckeditor/attachment_files#create
我错过了什么吗?
修改
我应该补充一点,localhost:5000/assets/ckeditor/config.js
确实有效,/assets/
前面的其余内容也是如此...为什么ckeditor.js
不会使用正确的资产路径?
答案 0 :(得分:2)
我不记得我在哪里找到了解决方案(Github上有人发帖)。
这对我有用:
添加此/lib/tasks/ckeditor.rake
:
require 'fileutils'
desc "Create nondigest versions of all ckeditor digest assets"
task "assets:precompile" => :environment do
fingerprint = /\-([0-9a-f]{32})\./
for file in Dir["public/assets/ckeditor/**/*"]
# Skip file unless it has a fingerprint
next unless file =~ fingerprint
# Get filename of this file without the digest
# (example) public/assets/ckeditor/config.js
nondigest = file.sub fingerprint, '.'
# Create a filename relative to public/assets
# (example) public/assets/ckeditor/config.js => ckeditor/config.js
filename = nondigest.sub 'public/assets/', ''
filename = filename.sub /.gz$/, '' # Remove .gz for correct asset checking
# Fetch the latest digest for this file from assets
latest_digest = Rails.application.assets.find_asset(filename).try(:digest)
# Debug information
puts '---- ' + file + ' ----'
# Compare digest of this file to latest digest
# [1] is the enclosed capture in the fingerprint regex above
this_digest = file.match(fingerprint)[1]
if (this_digest == latest_digest)
# This file's digest matches latest digest, copy
puts 'Matching digest, copying ' + file
FileUtils.cp file, nondigest, verbose: true
else
# This file's digest doesn't match latest digest, ignore
puts 'Latest digest: ' + latest_digest
puts 'This digest: ' + this_digest
puts 'Non-matching digest, not copying ' + file
end
# Debug information
puts '---- end ----'
end
end
答案 1 :(得分:0)
您可以尝试将其放在 config / application.rb
上 class Application < Rails::Application
...
config.assets.precompile += %w( ckeditor/* )
end