How to precompile Steal.js assets properly? - ruby-on-rails

I have used steal.js as one of my assets. Previously I use it directly from public folder(i.e without pre-compile). Now I need to move its file to vendor assets so that it can be precompiled.
For this I used gem execjs to precompile .ejs files and gem less-rails to precompile .less files.
After that I successfully precompile all the assets but unfortunately steal.js raise errors Uncaught TypeError: Cannot read property 'path' of undefined and system break up.
Can anyone help me fixing these issues ?

You can mention specific file to get precompiled in application.rb as follow:
config.assets.precompile += %w(
steal.js
)
Try adding this statement,It might help you

Related

Rails 3.2 Asset Precompile is skipping files

Stack
Ruby 1.9.3
Rails 3.2.12
Issue
We have precompilation issues with our application.
We're trying to remove config.server_static_files = true and config.assets.compile = true from our production configs, but are constantly missing assets whenever we precompiled. Even though these assets live in app/assets, while other files in the same directory are seen and compiled.
Ex:
app/assets/stylesheets/application.css
app/assets/stylesheets/some_slider_lib.css
app/assets/stylesheets/bootstrap.min.css
After precompiling
public/assets/application-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.css
public/assets/some_slider_lib-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.css
And the manifest.yml is also missing the bootstrap file among other assets.
Same thing with our vendor folder.
Attempts
The following is the only way that I've managed to precompiles everything.
config.assets.precompile += ["*.css", "*.scss", "*.js", "*.coffee"]
However, this feels like overkill. I thought all files within the asset pipeline would be compiled. Is this not what is suppose to happen?
Also tried rake assets:precompile --trace, but this was unhelpful.
If anyone could provide a little guidance, suggestions or more it would be deeply appreciated.
Thanks!

Rails assets not precompiling in production

I'm using Datetimepicker and Slider. I include them in my Gemfile
gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true
source 'https://rails-assets.org' do
# gem 'rails-assets-select2-bootstrap-css'
gem 'rails-assets-seiyria-bootstrap-slider'
end
In my application.js
//= require moment
//= require bootstrap-datetimepicker
//= require pickers
//= require seiyria-bootstrap-slider
This works great in development, but when I run RAILS_ENV=production rake assets:precompile on the server (capistrano deploy or by hand) these, and others don't seem to get pulled in. Chrome complains specifically about these two first.
I know I could put the line Rails.application.config.assets.precompile += %w( *.js ) and then do a =javascript_include_tag :XXXX, but this defeats the purpose of sprockets/manifest right?
My understanding with sprockets/manifest is when I require it in my application.js it'll be included with the deploy so the client hits the server less.
Is there something I'm missing?
EDIT
Traced the problem to the uglifier gem. When I remove/comment out config.assets.js_compressor = :uglifier and recompile the JS starts working again.
Any thoughts?
this is because things work differently in development as compared to production.
few thing to note:-
No CSS or JS files will be available to your app through the asset pipeline unless they are included in other files OR listed in the config.precompile directive.Only application.css and application.js are available by default of all the CSS and JS files.
Every file that is not a Javascript file or CSS file that is in the app/assets folder will be copied by Rails into the public/assets folder when you compile your assets.So if you want to add some web fonts, you could make an app/assets/fonts/ folder and put your fonts in there, these will then be copied to public/assets/fonts folder when you compile your assets. Note that your app/assets/stylesheets/fonts.css.scss file that references those fonts will NOT be copied over unless you either added it to the config.assets.precompile directive or required it from your application.css
for config.assets.compile...If it is set to "true" (which it is by default in development) then Rails will try to find a Javascript or CSS file by first looking in the public/assets directory and if it can't find it, will hunt through your app/assets folder looking for the file. If it finds it in app/assets it will go ahead and compile on the fly and then serve this asset up.
The problem with this is that you don't notice it happening in development, then you commit everything and push to production and BOOM, everything is broken with 500 errors because production has config.assets.compile set to "false".This prevents the app from "falling back" and trying to load the file directly instead of using the asset pipeline.
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
Why don't you just have this set to "true" in every environment? Well, because it is sloooooow. And you don't want slow in production
Run RAILS_ENV=production rake assets:clean assets:precompile
check public/assets directory and verify that assets are compiled..if its not empty...that means asset pipeline is working but path is not correct.use asset_helpers to set the path of assets in css files.

Rails 3.2.8 - not loading assets (development)

I have searched around and can't rectify the situation based on the responses to other similar questions. I seem to have broken the asset pipeline somehow but can't seem to figure out how.
None of my assets are being loaded at all; rails seems to just be ignoring my manifest files. When I inspect my page in firebug, only the 'non-compiled' text inside my manifest files (both js and css) is being displayed - almost as if the asset pipeline wasn't even enabled.
I deleted the contents of public/assets since I was adding a new file to the manifest which seemed to start this behavior.
Current configuration:
environments/development.rb
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
application.rb
# Enable the asset pipeline
config.assets.enabled = true
config.assets.manifest = config.root
# Add extra assets for precompiling
config.assets.precompile += ['admin.js', 'admin.css']
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
I had the same issue. You can still use Ruby 2.1.2, just upgrade rails to latest 3.2.x version - it's 3.2.22
Gemfile:
gem 'rails', '3.2.22'
And run:
$ bundle update rails
The issue was caused by using an incompatible version of ruby. I was using version 2.1.2 which lead to unusual behavior from the sprockets gem (which powers the asset pipeline). This was fixed by downgrading to ruby 1.9.3. I haven't done any experimentation for fear of breaking it again but maybe this has been addressed in later versions of sprockets. I am using sprockets 2.1.3.
See: Rails 3.2.8 Application.js and Application.css are not working as expcted
Always remember two things when you want to handle Rails asset pipleline:-
if you want all you newly created js/css to autoinclude in application.js/css,pls add them in...
ELSE
IF you dont wont to add in manifest file(application.js/css) then use precompile directive in yuur environment file.
config.assets.precompile=%w(custom.css,custom2.js...etc)
so make sure you have either of these...
===========for example=-=============
suppose you have new css/js file:-
custom.css inside
app/assets/stylesheets/
so you can include in
application.css
// = require 'custom'
OR
use precompile directive:-
config.assets.precompile += %w( custom.css )
and then reference it like you always do
stylesheet_link_tag "custom"
same applies for js also
I just spent a few hours troubleshooting this issue (in 2017!) and it turned out I just needed to remove the gem active_reload. Updating rails and ruby was having no effect for me. The thread where I found that gold is here:
https://github.com/rails/rails/issues/2715

Rails 4 Asset Pipeline With Lib and Vendor Folders

I was reading the documentation on Rails 4 and the Asset Pipeline when I got tripped up by this line:
If you are upgrading from Rails 3, please take into account that assets under lib/assets or vendor/assets are available for inclusion via the application manifests but no longer part of the precompile array
http://edgeguides.rubyonrails.org/asset_pipeline.html#asset-organization
What is the difference between being available for inclusion via the application manifest and being part of the precompile array? Does this mean that if I were to have a javascript file lib/vendor/cool_plugin.js I would get a 404 when I went to production even if I had //require cool_plugin in application.js?
From http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html:
In Rails 4.0, precompiling assets no longer automatically copies
non-JS/CSS assets from vendor/assets and lib/assets. Rails application
and engine developers should put these assets in app/assets or
configure config.assets.precompile.
so I believe you need to explicitly reference your vendor assets for them to get picked up during precompilation on production:
# production.rb
config.assets.precompile += %w( cool_plugin.js )

ActiveAdmin assets precompile error

ActiveAdmin is giving me an
Undefined mixin 'global-reset'.
error when it try to run
rake assets:precompile
ActiveAdmin is 0.3.4.
I have ActiveAdmin and an assets group in my Gemfile with sass, coffee-rails and uglifier.
I've just stumbled on this. The problem I had turned out to be in the config.assets.precompile directive in my production.rb file. I had a regular expression there, which was matching some assets from the activeadmin gem, that should not be matched for precompilation. Changing the option to the following worked for me:
# Needed for the ActiveAdmin's manifest assets.
config.assets.precompile += ['active_admin.css', 'active_admin.js']
The problematic code block I had was this:
# This one effectively turns every js/css file, which starts with
# a letter or a number, into an includeable asset manifest (similar to
# what application.js and application.css already are).
# You may want to omit this line for your application.
config.assets.precompile += [/^[a-z0-9]\w+\.(css|js)$/]
It was matching assets from the activeadmin gem and declaring them as standalone manifests and when the asset pipeline tried to complie them, this error was produced.
For more details on how the config.assets.precompile directive works in Rails, check out this Gist.
The problem is indeed, as #dimitar points out, the line with the catch all because the asset pipeline is trying to compile partials and since they aren't written to be compiled on their own, dependency issues appear.
Depending on your app, you might need that catch all, specially if you have many JS, CoffeScript and SCSS/SASS files in several child folders. In that situation you might encounter that rails complains because something isn't compiled for production when the catch all is removed.
The solution is to have a catch all that excludes the SASS partials, _filename.css.[scss|sass] and that would solve it (worked for me!). I also included some other tips from other activeadmin suggestions including exactly some ActiveAdmin dependencies to be compiled. Here's my code:
# Include all JS files, also those in subdolfer or javascripts assets folder
# includes for exmaple applicant.js. JS isn't the problem so the catch all works.
config.assets.precompile += %w(*.js)
# Replace %w( *.css *.js *.css.scss) with complex regexp avoiding SCSS partials compilation
config.assets.precompile += [/^[^_]\w+\.(css|css.scss)$/]
#Adding active_admin JS and CSS to the precompilation list
config.assets.precompile += %w( active_admin.css active_admin.js active_admin/print.css )
In your CSS file, you most likely have:
#include 'global-reset';
However, you are trying to import your global reset, so you should change that to:
#import 'global-reset';
Hope this helps!

Resources