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!
Related
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
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.
In my Rails app I have css and js that is unique to each action.
So users#new has its own css. It's named users_new.css.scss.
I deployed my app to Heroku, and Heroku isn't loading any of the assets. You can see the errors here. How do I fix this so Heroku correctly precompiles and loads the assets?
I read through Heroku's docs on using the asset pipeline, but didn't see any solution.
Precompilation
The problem is your timelines_index.js is not precompiled:
The way you can tell this is a problem is that when you call the asset in your layout (which I presume you're doing with the correct path helpers), Rails will automatically reference the latest precompiled version of that file (hence why application.js has the appended MD5 fingerprint)
I believe you'll need to add your custom files to your precompiled_assets array:
#config/environments/production.rb
Rails.application.config.assets.precompile += ['timelines_index.js']
This will give Rails the ability to precompile those assets individually, allowing you to call them in your layout:
#app/views/layouts/application.html.erb
<%= javascript_include_tag "timelines_index" %>
This will have to be done for all the custom asset files you wish to call in your layout.
Manifest
As mentioned by Anil, you may wish to use the manifest system of Rails to concatenate all your asset files into their respective application files.
This will quash the need to append the files to the Rails precompile array, allowing you to call a single file for your various assets:
#app/assets/javascripts/application.js
//= require_tree .
Add in your Gemfile
gem 'rails_12factor', group: :production
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
In my project I have third party JavaScripts and Css files inside the vendor/assets/javascripts and vendor/assets/stylesheets directories. In development mode I can refer to the assets within those directories using the javascript_include_tag and stylesheet_include_tag methods.
However those scripts do not get precompiled when I run the rake assets:precompile command and subsequently can't be accessed in production.
Could someone please say why are assets inside the vendor directory get ignored by the rake task?
I was able to answer my own question.
This wasn't obvious to me but it does make sense. Except for the application.css and application.js file all other .js/.css files get ignored by the precompile rake task. Therefore as long as your scripts and stylesheets are referenced using //= require name_of_script convention inside the application.js/.css files they will get appended to the relavant file fine.
However if you don't want certain scripts to be placed inside the application.js/.css files, then you need to explicitly tell Rails that you still want them to be precompiled using this line inside the config/environment/production.rb or other relavant runtime environment config file:
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( morris.min.js raphael.min.js )