Ckeditor not displaying in production Rails - javascript

So I updated Ckeditor to 4.2. After I did this, Ckeditor no longer appears in production. Instead, I get the following error in the console:
Uncaught TypeError: CKEDITOR.style.customHandlers[e.type] is not a constructor
I've consulted a few sources, including this post, which claimed the issue was in precompilation. I've edited my application.rb to include Ckeditor in precompilation, but it still doesn't work.
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module DeployTest
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w( ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.active_record.default_timezone = :local
config.time_zone = 'Eastern Time (US & Canada)'
end
end
Weirdly enough, when I turn config.assets.debug = true, Ckeditor starts working again, but my CSS turns off.
Why does config.assets.debug work? Why does it turn off my CSS? And how can I get a permanent solution for ckeditor?

Using ckeditor gem from git solved this issue for me
gemfile:
gem 'ckeditor', github: 'galetahub/ckeditor'
https://github.com/galetahub/ckeditor/issues/719

Related

Cannot disable rails assets pipeline

I have a rails '4.2.11.1' application. I want to dissable assets compilation, minifying, pipeline in development. in order to use indium debugger
The rails app seems to be set up with sprokets. so in my config/application.rb I changed to this:
# Enable the asset pipeline
config.assets.enabled = false
also in config/environmetns/development.rb I have this setup:
# Do not compress assets
config.assets.compress = false
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
config.serve_static_files = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
but nothing happens and I get the files:
assets/stixs.self-7246a54effa0c5edaa806b9c4fbc6ba4617c0d80bef8c236f9a4cbcfcf7f0be7.js
finally I get this files not minifyed, or compresed but how can I get that rails work with serving the files in app/assets/javascripts in de delopment environment
Technique Sprockets uses for fingerprinting is to insert a hash of the content into the name
Add this in your development.rb
config.assets.digest = false
I hope that work for you.

Why do CKEDITOR uploaded images give 404 errors in rails production site?

I am using ckeditor and when uploading images on the production site its fine but when I make a change to the site and deploy with Capistrano it shows 404 errors for the images.
In my:
production.rb I have:
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/*)
Then in my
application.js
//= require ckeditor/override
//= require ckeditor/init
In my
lib/tasks/ckeditor.rake I have this:
require 'fileutils'
desc "Create nondigest versions of all ckeditor digest assets"
task "assets:precompile" do
fingerprint = /\-[0-9a-f]{32}\./
for file in Dir["public/assets/ckeditor/**/*"]
next unless file =~ fingerprint
nondigest = file.sub fingerprint, '.'
FileUtils.cp file, nondigest, verbose: true
end
end
Does anyone know what causes this error?
It is because where CKEditor gem is storing the assets is not inside the symlinked folder that all your releases share. In my setup public/system is a symlink to a shared folder that all production releases share. When the admin uploads the image via CKeditor it needs to get placed inside that folder so it is shared. I did this by making my own Ckeditor::AttachmentFile < Ckeditor::Asset model in /models/ckeditor/attachment_file.rb
In that file I have:
has_attached_file :data,
:url => "/system/ckeditor_assets/attachments/:id/:filename",
:path => ":rails_root/public/system/ckeditor_assets/attachments/:id/:filename"
def store_dir
"public/system/ckeditor_assets/attachments/#{model.id}"
end
Which moves the ckeditor files into my symlinked system folder so they can be shared between releases. You will also have to do something similar for Ckeditor::Picture < Ckeditor::Asset
This may not be the preferred method but hopefully leads you in the right direction.

Heroku Rails 4 not referencing my JavaScript assets location correctly

My local development runs fine, rendering javascript_include_tag "some-script" as referencing /assests/some-script.js correctly.
In Heroku, it references /javascripts/some-script.js
I'm using gem 'rails_12factor' in production in my Gemfile
Do I need to change any asset configuration settings? Like precompiling assets? I'm aware there are several config settings, but I'm unsure when to use them, in the past I've been fine without modifying them (like this suggestion).
It's just odd it references the /javascripts folder...
Also, to note, I am not currenty using javascript_include_tag "application" in layout/application.html.erb I am importing scripts manually using javascript_include_tag "some-script" in specific view erb files
Secondly, /assets/some-script.js comes up as a 404, so this must means my assests aren't available, which could be a second issue.
Any ideas?
This answer helped me resolve my issue. I had to manually add the js files to the assets precompile list in config/environments/production.rb like so:
config.assets.precompile += %w( some-script.js )
config.assets.precompile += %w( some-script2.js )
...
When I use a script in a view javascript_include_tag "some-script" works.

Disable Asset Minification in Rails Production

In order to debug javascript in my heroku production environment, I need to disable asset compression (or at least compression of javascript). I tried config.assets.compress = false along with config.assets.debug = true, and the compressed assets were still used. I then deleted the compressed assets, at which point no assets were rendered at all. I added config.assets.enabled = false, which did not help. I tried copying the uncompressed assets into various directories, including the application root, public, and public/assets (the latter two using both the folders "images, "javascripts", and "stylesheets", and putting the assets directly into the folders without the three subfolders). I was eventually able to get the javascripts to work by changing the html to directly reference all of the javascript files. But the CSS and images still are not working.
I would have thought that my original config.assets.compress = false should have worked. Any ideas what I did wrong?
I came up with this workaround after reading the docs:
create a module that does nothing to compress js / css here: lib/modules/no_compression.rb
class NoCompression
def compress(string)
# do nothing
string
end
end
configure your assets to (not) be compressed with your do-nothing compressor
config.assets.compress = true
config.assets.js_compressor = NoCompression.new
config.assets.css_compressor = NoCompression.new
Under Rails 4 just commenting out the line
# config.assets.js_compressor = :uglifier
in config/environments/production.rb worked for me. Looks like default is no compresson.
I also need to debug my js so I tried ncherro's solution. The problem was that it would still throw
rake aborted!
uninitialized constant NoCompression
So I just put the NoCompression class in the production.rb file
# Compress JavaScripts and CSS
class NoCompression
def compress(string)
# do nothing
string
end
end
config.assets.compress = true
config.assets.js_compressor = NoCompression.new
config.assets.css_compressor = NoCompression.new
Comment out the uglifier and add config.assets.debug = true. This worked for me.
Compress JavaScripts and CSS:
config.assets.js_compressor = :uglifier
Debug mode disables concatenation and preprocessing of assets. But this option may cause significant delays in view rendering with a large number of complex assets:
config.assets.debug = true
Also worth noting... In addition to ncherro solution you will need to do the following:
make sure to put your new module somewhere where it will be loaded by default. Was lib/extras in my case.
run rake assets:clean to clean your existing assets.
run rake assets:precompile to compile your assets using the new compressor.
restart your app... i use touch tmp/restart.txt
Happy debugging ;)
With Rails 4 on Heroku you need to do two things. First as #geekQ mentioned, comment out the js_compressor line in config/environments/production.rb
# config.assets.js_compressor = :uglifier
Second, you need to consider Heroku's asset pipeline cache for Rails 4. Any file with the same MD5 as the version in the cache will not be recompiled. The previous (possibly compressed) version will be served. Any file you edit will have a new MD5 and be recompiled.
You can also purge the entire asset cache with the Heroku Repo plugin to the Heroku toolbelt. Install that, then use the command
heroku repo:purge_cache
Deploy a new version after purging the cache and all your assets will be recompiled.
I had to update Rails.application.config.assets.version in config/initializers/assets.rb for the production.rb changes to take effect.
Find and comment out these line in environments/production.rb:
config.assets.js_compressor = ...
config.assets.css_compressor = ...
Looks like this MAY have been a bug in Rails. From the changelog for upcoming rails 3.2.9, is this what you were running into?
Respect config.digest = false for asset_path
Previously, the asset_path internals only respected the :digest option, but ignored the global config setting. This meant that config.digest = false could not be used in conjunction with config.compile = false this corrects the behavior.
http://weblog.rubyonrails.org/2012/10/29/ann-rails-3-2-9-rc1-has-been-released/
Do you think that could be related?

javascript not running on heroku with rails 3.1

I've migrated a rails 3.0 app to 3.1 on Heroku. It's running on the cedar stack and everything is fine except that the app's javascript won't run. The application.js file is compiled and looks just as it should. It's accessible by going to myapp.com/assets/application.js. It just doesn't get run!
If I run the app locally, the javascript works, so I suspect that there must be some simple configuration issue that I'm missing. Here's my production.rb file:
FloridaBirdTrail::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end
edit
Replacing the contents of production.rb with that of development.rb has allowed at least some of my javascript to run (gmap3 isn't working, for some reason). But which of the settings is making the difference?
Open your application.rb file and make sure your Bundler require statement looks like the following:
Bundler.require *Rails.groups(:assets)
By default it looks like
# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
Manually precompiling worked for me.
bundle exec rake assets:precompile before you push to heroku.
Were you sure to switch Heroku to the Cedar stack? Here are some docs for upgrading
http://devcenter.heroku.com/articles/rails31_heroku_cedar#upgrading_from_previous_rails_31_releases
http://devcenter.heroku.com/articles/cedar
I had some Javascript problems (server-side on Heroku, locally everything was fine) that went away when I
* moved all my Javascript into a separate file instead of application.js
* removed require_tree from application.js and instead called up every javascript I wanted by name
* removed bootstrap.js from my app/assets/javascript folder
My guess is that compilation somehow screws things up.
I hope you did a local pre-compilation of assets before your latest Heroku push (as advised in one of the responses above).
Please check if your system is blocking the execution of JavaScripts. For this, open up the console while you are on your Heroku app, and check for exceptions. In case you see exceptions related to JavaScripts being blocked, that could be the issue. In my case, the same happened, and unfortunately, I was not able to do anything about it, as I didn't have admin privileges.

Categories

Resources