spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
814 stars 257 forks source link

tinymce-3 branch on Rails 4 keeps trying to load fingerprinted assets #158

Open amysutedja opened 9 years ago

amysutedja commented 9 years ago

We're in the middle of a significant Rails 4 transition, but we don't yet have the ability to move to TinyMCE 4, so we're using the tinymce-3 branch, which should be Rails 4-compatible.

However, when TinyMCE loads with the Advanced theme, it's missing the icons, and the Javascript console displays the error:

Failed to load resource: GET http://app.zorin.local/assets/tinymce/themes/advanced/img/icons-68206bc530f3a7006dc8f5cf57005b7e.gif 404 (Not Found)

Based on my understanding, tinymce-rails attempts to skip the asset pipeline entirely, and just copies the undigested files directly to public/assets. Since this is the case, why is TinyMCE trying to load the digested version of icons.gif versus the undigested version?

spohlenz commented 9 years ago

I can't reproduce this here :disappointed:. Are you able to upload a test Rails app to a GitHub repo that exhibits the problem?

amysutedja commented 9 years ago

Okay, after a bunch of looking into it, I was able to solve the problem.

We had a setting in our assets.rb file that looked like this.

Rails.application.config.assets.precompile += %w(png jpg jpeg gif)

This is to solve an issue in which Rails 4 apparently does not precompile images by default. However, we didn't realize that this also caused tinymce-rails image assets to also be precompiled. Since the tinymce-rails gem adds functionality to rake assets:precompile to delete all digested assets, we ended up with a bunch of unresolvable references to digested assets in the manifest.

The solution was to change the line to the following:

Rails.application.config.assets.precompile += [/(?!.*tinymce).*(png|jpg|jpeg|gif)$/]
spohlenz commented 9 years ago

I'm glad you found a solution that works but I hope you can give me a little more feedback to help find the root cause.

This is to solve an issue in which Rails 4 apparently does not precompile images by default.

By default, Rails 4 should precompile application.js, application.css and any non-js/css files within app/assets. tinymce-rails adds tinymce.js only to the precompile list.

Since the tinymce-rails gem adds functionality to rake assets:precompile to delete all digested assets, we ended up with a bunch of unresolvable references to digested assets in the manifest.

tinymce-rails (both 3.x & 4.x) extend the assets:precompile task to do the following:

a) copies the vendored TinyMCE assets to public/assets b) adds files from a) to the asset manifest c) renames any digested files within public/assets/tinymce/ to their non-digested versions d) updates the manifest with the new filenames from c)

It sounds like d) may not be happening correctly in your case. Do you have any other asset-related gems installed that may be interfering with the manifest during precompilation?

amysutedja commented 9 years ago

Hmm, interesting. The only ones I'm aware of are sass-rails and compass-rails. Would it help to have the Gemfile.lock and assets.rb files that we're using?

spohlenz commented 9 years ago

Yes please, that should hopefully shed some light on what's happening.

amysutedja commented 9 years ago

Okay, I've uploaded the relevant info to this Gist. Note that I've redacted some sensitive data from the files.

https://gist.github.com/amysutedja/e28525fef7ac2e28e2cc

spohlenz commented 9 years ago

Thanks @amysutedja.

In your tinymce/themes/advanced/skins/tddc/*.css source files, are there any references to icons.gif that use the asset helpers (e.g. image-url("tinymce/themes/advanced/img/icons.gif"), etc.)?

amysutedja commented 9 years ago

Yes, there are indeed. One example:

a.browse span {
  display: block;
  width: 20px;
  height: 18px;
  background: asset-url('tinymce/themes/advanced/skins/default/img/icons.gif') -860px 0;
  border: 1px solid #FFF;
  margin-left: 1px;
}

I take it that this css file being added to the precompile list is causing icons.gif to be digested?

spohlenz commented 9 years ago

Yes, that is almost certainly where the problem lies.

I will spend some more time figuring out how this can be addressed. Unfortunately it's not quite as simple as not removing the digested file, since both versions need to exist and both need to be in the manifest (which I'm not sure is possible).