I have problem with ckeditor in my Rails project - ruby-on-rails

I use tutorial - https://github.com/galetahub/ckeditor/
And add cktext_area in _form
<%= f.label :body %>
<%= f.cktext_area :body %>
But it is not displayed
I use
gem 'carrierwave'
gem 'mini_magick'
In application.js require adding, routes modified, but not working at all, and use command
rails generate ckeditor:install --orm=active_record --backend=carrierwave.
Help!!!
assets.rb
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( ckeditor/*)
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
Rails.application.config.assets.precompile += %w[bootswatch.scss]
# Precompile additional assets.
# application.js, application.scss, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

Related

Rails won't precompile the assets-fonts folder

I kept getting a 404 on my application, only to realize that it is looking for a font: /assets/fonts/footable.woff
So I figured I'd just create the fonts folder within my app/assets folder, and then re-run RAILS_ENV=production rake assets:precompile
I did this, and when I do an ls to public/assets/, there is still no fonts folder.
Here's my config/application.rb
module MyRailsApp
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# 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.time_zone = "Central Time (US & Canada)"
config.active_record.default_timezone = :local # Or :utc
config.eager_load_paths += Dir["#{config.root}/lib/custom_rb/**/"]
config.assets.enabled = true
config.assets.paths << Rails.root.join("app", "assets", "images", "iCheck")
config.assets.paths << Rails.root.join("app", "assets", "fonts")
# For sidekiq
#config.active_job.queue_adapter = :delayed_job
config.active_job.queue_adapter = :sidekiq
end
end
and here's my config/initializers/assets.rb file:
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
I have also restarted apache, and it's still not there.
What am I doing wrong?

Add all .css files to precompile?

I want to include all css files to precompile. Right now Im using #import to include other css into application.css. But I want to load specific css file according to the controller with:
<%= stylesheet_link_tag params[:controller] %>
It gave me an error, telling me to add the css to the precompiler. Say I add this to config/initializers/assets.rb:
Rails.application.config.assets.precompile += %w( pages.css )
Now it works, but only for that particular controller. I could just go manually add each css file for each controllers. It will work like that, but there must be a better way.
Im using bootstrap so I cant use:
*= require_
I have tried both (not at the same time):
Rails.application.config.assets.precompile += %w( *.css *.js)
Rails.application.config.assets.precompile = %w( *.css *.js)
but now I got this error:
Undefined variable: "$alert-padding-y".
Which I guess comes from bootstrap. But it was working before I try to add files to precompile.
=====
Edit: I tried what Daniel Westendorf post. Putting this code in the assets.rb:
Rails.application.config.assets.precompile = []
Dir[Rails.root.join("app", "assets", "**", "*.css")].each do |file|
Rails.application.config.assets.precompile << file
end
But I got this error:
Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( application.css )` to `config/initializers/assets.rb` and restart your server
I tried to fix it by adding both the css and js (it asked for it later):
Rails.application.config.assets.precompile += %w( application.css application.js )
But I still ended up with the same error anyway:
Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( pages.css )` to `config/initializers/assets.rb` and restart your server
This is generally against the better conventions of the web. One larger, cached, network request will perform better for you than many smaller, individual, network requests.
You could, however, find all the .css files in your assets directory, and add each one to the precompile array. Something like:
Rails.application.config.assets.precompile = []
Dir[Rails.root.join("app", "assets", "**", "*.css")].each do |file|
Rails.application.config.assets.precompile << file
end
I used this code. It works perfectly fine for me.
Add this code in config/initializers/assets.rb
# for css files
Dir[Rails.root.join("app", "assets", "**", "*.css")].each do |file|
Rails.application.config.assets.precompile << file
end
# for js files
Dir[Rails.root.join("app", "assets", "**", "*.js")].each do |file|
Rails.application.config.assets.precompile << file
end

Rails 5 Assets Not Loading in Production

I recently updated a few packages in my Rails application and now my assets aren't being served. Instead, I get the following error:
Failed to load resource: the server responded with a status of 404 (Not Found)
My assets are precompiled:
assets.rb
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += %w(ckeditor/*)
Rails.application.config.assets.precompile += %w(ckeditor/config.js)
Rails.application.config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb )
application.rb
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
Before telling me to turn on compiling my assets, please understand that this is
a horrible idea. Thank you for any advice
UPDATE: I got it to work by adding:
config.assets.digest = true
to my config/environments/staging.rb file. Weird how I didn't need it before
At times you need to add both of these configurations in staging.rb or whichever environment you want the changes to reflect on.
config.assets.compile = true #set to false by default
config.assets.digest = true

Asset filtered out and will not be served rails 4.1.1

Asset filtered out and will not be served: add Rails.application.config.assets.precompile += %w( login.js ) to config/initializers/assets.rb and restart your server
I ge the above error when i try to run my application.
<%= javascript_include_tag "applicatin", "login" %>
I don't see any file name asests.rb in config/initializers.
You need to create config/initializers/assets.rb and add that line to it, like so:
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( login.js )
Then restart your server and it should work.The code above is all you need in the assets.rb file for now.

Rails - Loading assets through the Asset Pipeline

I am trying to set up asset pipeline on a older rails app that i have so that i can start using CoffeeScript. i am using ruby 1.9.3-p327 and Rails 3.2.13. I used to stash all my JS, CSS and my images in the public/ folder. This is what i have done so far ->
I moved them all to app/assets, i added the manifest files for both JS and CSS call //= require_tree ..
Added the following gems
group :assets do
gem 'coffee-rails'
gem 'uglifier'
gem 'sass-rails'
gem 'therubyracer'
end
Removed all my javascript_include_tags except for = javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'
Added the following to my config/application.rb file
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
Within the config/environments/development.rb file set
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
I added to the config/environments/production.rb
# Compress JavaScripts and CSS
config.assets.compress = true
# Choose the compressors to use
# config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :yui
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
I re-read the section on the Asset Pipeline just to see if i messed up anything. But so far none of the assets are pulling through from app/assets the only one that is working is the jquery.min.js that i have coming in through include_tag i have tried removing it and trying again no dice.
I have tried bundle exec rake assets:clean, and bundle exec rake assets:precompile, both of which run without issues. and have bundled since adding the gems for the assets, and restarted pow each time.
I am not sure if i am going through this all wrong or i have missed a step? any one gone through this before and tips or clues would be much appreciated.
You said you removed all the javascript_include_tag statements. Assuming you named the manifests app/assets/javascripts/application.js and app/assets/stylesheets/application.css, you'll need to include those in your layout:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
Otherwise, Rails won't know to load your manifest files
Also, you shouldn't be using rake assets:precompile in development. If you do, then anytime you change a JS/CSS file, you'll have to recompile the assets before your changes show up.

Resources