Closed israelkeys closed 11 years ago
There are some issues needed to consider.
The value of CKEDITOR_BASEPATH will be fixed when ckeditor-jquery.js
is compiled by assets pipeline since it requires ckeditor/base_path.js.erb
.
1) If you only have one assets host, you may have config/environments/production.rb
config.action_controller.asset_host = "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
or with CDN
config.action_controller.asset_host = "//d1aar6ipvvlxt7.cloudfront.net"
and it is ok to have fixed asset host for CKEDITOR_BASEPATH with basepath.js.erb
<%
base_path = ''
base_path << Rails.application.config.action_controller.asset_host
base_path << Rails.application.config.assets.prefix
base_path << '/ckeditor/'
%>
var CKEDITOR_BASEPATH = '<%= base_path %>';
2) If you have dynamic assets hosts, you may have config/environments/production.rb
config.action_controller.asset_host = "http://asset%d.example.com"
You need to dynamic change assets host by javascript for CKEDITOR.basePath
not CKEDITOR_BASEPATH.
And basepath.js.erb
should not include Rails.application.config.action_controller.asset_host
.
<%
base_path = ''
base_path << Rails.application.config.assets.prefix
base_path << '/ckeditor/'
%>
var CKEDITOR_BASEPATH = '<%= base_path %>';
Otherwise it would produce wrong CKEDITOR_BASEPATH like http://asset%d.example.com/assets/ckeditor/
I also add this to https://github.com/tsechingho/ckeditor-rails/wiki/work-with-asset-host
If I simply put Rails.application.config.action_controller.asset_host
to CKEDITOR_BASEPATH, it may cause someone have wrong path. I don't think it's a good idea for now.
I would like to suggest israelkeys to create your own version of basepath.js.erb
in your rails application and put it under app/assets/javascripts/ckeditor/
.
The lib/assets/javascripts/ckeditor/basepath.js.erb
of ckeditor-rails would not be required if we have one in app/assets/javascripts/ckeditor/
by rails asset pipeline.
Ah good point - I failed to consider dynamic hosts in my rush to get it working.
Just double checking: This doesn't work with digested JS names on the CDN, right? CKEditor will still try to load config.js, and not config-abcdef12345.js?
@runemadsen right. CKEditor load config.js via javascript. I am not familiar how to deal this with CDN by javascript.
I ran into trouble using this gem when using Heroku and hosting assets on a AWS. Here is the change I made to get it going. Not sure if there is a cleaner way?