galetahub / ckeditor

Ckeditor 4.x integration gem for rails
https://ckeditor.com/ckeditor-4/
MIT License
2.23k stars 876 forks source link

Wrong asset path being requested #919

Open russellbrown opened 2 years ago

russellbrown commented 2 years ago

Version 4.3.0, rails 5.2.7, sass 3.6.0, sass-rails 5.0.7, sassc 2.0.0, sassc-rails 2.1.0

For some reason ckeditor is requesting the wrong URL for icons_hidpi.png with the result that none of the button icons are visible. It happens in both development and production.

Expected request: /assets/ckeditor/skins/moono-lisa/icons_hidpi.png Actual request: /icons_hidpi.png

The request originates from the moono-lisa skin's editor.css where I would expect the compiled output to contain:

background:url(icons_hidpi.png?t=c264cac)...

However the actual compiled output includes a forward slash at the start, making it an absolute URL instead of relative:

background:url(/icons_hidpi.png?t=c264cac)...

The file itself is being served at the expected location in both development and production, so it isn't an issue with the png not being precompiled etc. window.CKEDITOR_BASEPATH is correct so that can't be the issue either. And I've tried clearing the assets cache but that made no difference.

All the other scripts are being loaded correctly and the editor is fully functional otherwise. I'm completely baffled - any ideas why this might be happening? Thank you.

javierm commented 2 years ago

We're also running into this issue when trying to upgrade from Rails 5.2.6 to Rails 5.2.6.3. With Rails 5.2.6, it correctly returns the URL without the slash at the start.

javierm commented 2 years ago

According to our tests, the issue seems to be related with upgrading sprockets from 4.0.2 to 4.0.3 (which we were including as part of the mentioned Rails upgrade).

russellbrown commented 2 years ago

Thanks @javierm - I downgraded sprockets-rails from 3.4.2 to 3.2.2 and now it's using the correct URL.

jakevose commented 2 years ago

We're having the same issue and regressing sprockets-rails fixed it for us as well. h/t

javierm commented 2 years ago

It's working for me with Sprockets 4.0.3 after upgrading to Rails 5.2.8.1. Instead of URLs like background:url(/assets/ckeditor/plugins/icons.png?t=...) (which I got with Rails 5.2.6.3 and Sprockets 4.0.3), now the application generates URLs like background:url(https://mydomain.com/assets/ckeditor/plugins/icons.png?t=...), and so the button icons are visible again.

PatrickKing commented 1 year ago

Ended up addressing this in an old app by adding a route with a redirect. This works around the problem if you can't update Sprockets.

# config/routes.rb

  get 'icons_hidpi.png', to: redirect('/assets/ckeditor/skins/moono-lisa/icons_hidpi.png')
dougjohnston commented 1 year ago

Just had this same issue and was able to track it to a move from sprockets-rails 3.2.2 to 3.4.2. More importantly, I noticed that 3.4.2 introduced a new config value to use the legacy asset url approach (https://github.com/rails/sprockets-rails/commit/67c74ece6de93109fcf725f6a56daeb0fc3cc6ee).

Setting that new config value fixed it for me:

# application.rb
config.assets.resolve_assets_in_css_urls = false
bjer commented 1 year ago

Ended up addressing this in an old app by adding a route with a redirect. This works around the problem if you can't update Sprockets.

# config/routes.rb

  get 'icons_hidpi.png', to: redirect('/assets/ckeditor/skins/moono-lisa/icons_hidpi.png')

This fixed it for me on an app running Rails 6.1.7.6

streeet25 commented 9 months ago

Ended up addressing this in an old app by adding a route with a redirect. This works around the problem if you can't update Sprockets.

# config/routes.rb

  get 'icons_hidpi.png', to: redirect('/assets/ckeditor/skins/moono-lisa/icons_hidpi.png')

This fixed it for me on an app running Rails 6.1.7.6

Also only this solution help to fix error on Rails 5.2.8.1 with only one difference i have error with 'icons.png'

# config/routes.rb
get 'icons.png', to: redirect('/assets/ckeditor/skins/moono-lisa/icons.png')