spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
816 stars 258 forks source link

Precompiled assets in production mode #30

Closed davidkennedy-examtime closed 12 years ago

davidkennedy-examtime commented 12 years ago

In development mode, TinyMCE is working great, but in production mode, I seem unable to load precompiled TinyMCE assets. However, the assets are in my public/assets directory as expected. The page with the TinyMCE textareas does not render any textareas.

Detail: Command and logs:

bin/rake assets:precompile
RAILS_ENV=production bin/rails server thin

Started GET "/assets/tinymce/themes/advanced/editor_template.js?3.4.7" for 10.0.2.2 at 2012-01-07 16:09:06 +0000 
Served asset /tinymce/themes/advanced/editor_template.js - 404 Not Found (4ms)
ActionController::RoutingError (No route matches [GET] "/assets/tinymce/themes/advanced/editor_template.js"):

ls -l public/assets/tinymce/themes/advanced/editor_template.js 
-rw-r--r-- 1 dkennedy dkennedy 25166 2012-01-07 16:06 public/assets/tinymce/themes/advanced/editor_template.js

I am unclear if this is a routing issue on my part, but I don't see anything in the documentation about needing to tweak config/routes

Integration: as per instructions: Gem installed via bundler, in my app/assets/javascripts/application.js I have

//= require tinymce-jquery

On each page I require a page specific manifest.js which includes several files, including one with the TinyMCE javascript hook customised for my preferred buttons etc; I can see this manifest.js in my public/assets.

Versions: I'm using Rails 3.1.0, and Ruby 1.9.3. I've cleared out all gemsets etc, and have tried building the tinymce-rails Gem directly from GitHub.

Any advice?

davidkennedy-examtime commented 12 years ago

Aha, more information. If I go into my config/production.rb file, and edit the following setting, I am presented with a working set of pages; this is a possible workaround.

# Disable Rails's static asset server (Apache or nginx will already do this)
# OVERRIDDEN DEFAULT: set to 'true' to workaround TinyMCE issue?
config.serve_static_assets = true

However, I really do not want to have this set to 'true' in production if at all possible; it seems like a bad idea for scalability.

Also, I'm confused about why this is a workaround; I can see that there was a TinyMCE related JavaScript line in the header asking to GET the asset editor_template.js, but why wasn't this already precompiled and pulled into a header, ie, the JS functions are already loaded, why ask for them (I think)?

spohlenz commented 12 years ago

If you're running Apache, nginx or similar in your production environment, those assets will be accessible. Thin doesn't server static assets without the help of the static assets middleware. It is definitely better to have the static assets served by the web server if possible.

Also, I'm confused about why this is a workaround; I can see that there was a TinyMCE related JavaScript line in the header asking to GET the asset editor_template.js, but why wasn't this already precompiled and pulled into a header, ie, the JS functions are already loaded, why ask for them (I think)?

Whilst the main TinyMCE script can be precompiled into application.js, TinyMCE loads the majority of its themes, plugins, etc at runtime. This obviously isn't ideal for the asset pipeline, hence the workarounds in this gem.

davidkennedy-examtime commented 12 years ago

My apologies, you're right. My inexperience with Rails is showing. In a real production environment (EngineYard), everything is working fine, it's only in our production-on-a-laptop staging environment that the issue occured. Completely obvious once it's pointed out!

Thanks.