Stuck while precompiling assets in Rails 3.2 - ruby-on-rails

I'm trying to put my first app into production and ran into the following when trying to precompile:
rake aborted!
Undefined variable: "$yellowCorp"
(in app/assets/stylesheets/_dialog.scss)
$yellowCorp is declared in
app/assets/stylesheets/_variables.css.scss
I've done quite a bit of reading and there seems to be quite a few people that have struggled with this. I've tried many solutions that have worked from them, but none work for me. In config/environments/production.rb I've tried
config.assets.precompile += %w(*.css.scss *.scss)
and
config.assets.precompile << [ "*.scss", "*.css", "*.js" ]
and
config.assets.precompile += [ "_variables.css.scss", "_dialog.scss" ]
...among others, but nothing changes, but nothing have gotten me past this point. Any help/advice would be greatly appreciated.
Thanks!

I imagine this problem stems from the order in which the files are compiled. It is compiling the dialog file before the variables.
What does your application.css.scss file look like?
Instead of requiring tree, you may have to specify the order in which to compile them:
#import "variables.css.scss"
#import "dialog.scss"

Related

Print the names of all assets in the Asset Pipeline?

I'm trying to debug why some assets are found and others not in the Asset Pipeline. i've tried a lot of obvious things (like typos, clearing tmp, clean/clobber).
Now I placed binding.pry right before where the image path is generated, and I'd like to view (print to the rails console / debugger) the name of every asset rails thinks is available.
How can I do that?
You can take a look at the manifest:
Rails.application.assets_manifest
# or just the files
# this is empty in some of my apps, no idea why, maybe cache or some
# lazy loading that I'm missing:
Rails.application.assets_manifest.assets
Or maybe loop through asset paths:
Rails.configuration.assets.paths.flat_map{ |path| Dir.glob("#{path}/*.{js,css}") }
Please note, this doesn't answer the question (how to view the available assets in the console/debugger), and therefore shall not be accepted as an answer, but it's a small start: showing how to view assets from the terminal:
rails webpacker:clean
rails webpacker:clobber
rails webpacker:compile
The last step will print all the available assets to the terminal.
Another way is to run bin/webpack from the terminal, and in the output will be each asset. Again, this doesn't provide the list from the console or debugger.

How to ignore a folder in Zeitwerk for Rails 6?

Simple question, but somehow the answer escapes me.
In moving to Rails 6 with Zeitwerk, I get:
Please, check the "Autoloading and Reloading Constants" guide for solutions.
(called from <top (required)> at APP_ROOT/config/environment.rb:7)
rails aborted!
Zeitwerk::NameError: wrong constant name Enforce-calls-to-come-from-aws inferred by Module from directory
APP_ROOT/app/junkyard/enforce-calls-to-come-from-aws
Possible ways to address this:
* Tell Zeitwerk to ignore this particular directory.
* Tell Zeitwerk to ignore one of its parent directories.
* Rename the directory to comply with the naming conventions.
Which seems great: that's a junk folder and should never be loaded, so ignoring it makes perfect sense.
The Zeitwerk docs at https://github.com/fxn/zeitwerk say
tests = "#{__dir__}/**/*_test.rb"
loader.ignore(tests)
loader.setup
is how you ignore a folder. Fair enough. But how do I find loader? The Rails guide on Zeitwerk autoloading (https://guides.rubyonrails.org/autoloading_and_reloading_constants.html) doesn't mention how to ignore folders directly, but does mention the autoloader stashed at Rails.autoloaders.main, so I figured that
Rails.autoloaders.main.ignore("#{__dir__}/junkyard/**/*.rb")
or
Rails.autoloaders.main.ignore("#{__dir__}/app/junkyard/**/*.rb")
would be the way to go. No luck. I've tried putting this in application.rb and in initializers/zeitwerk.rb and neither worked.
Any ideas where and how to ignore a folder with Zeitwerk within Rails?
PS: yes, I know I should just remove this from app, and I will. But the question still vexes.
I ran into this same issue, and it turns out it was complaining about a folder name.
Adding this to application.rb may work for you:
Rails.autoloaders.main.ignore(Rails.root.join('app/junkyard'))
I added this to config/initializers/zeitwerk.rb:
Rails.autoloaders.each do |autoloader|
autoloader.ignore(Rails.root.join('app/ui'))
...

Assets pipeline and vendor assets. How do you add them to be precompiled in Rails 4?

This is incredibly frustrating.
I have added a few CSS files to my vendor assets, and I cannot seem to get them to get precompiled, or at least FOUND by my production server.
The files are found in something like this:
/vendor/assets/stylesheets/cssfw/style.css
/vendor/assets/stylesheets/cssfw/app.css
/vendor/assets/stylesheets/cssfw/plugins.css
/vendor/assets/stylesheets/cssfw/custom.css
And they're loaded like this on my application.css
*= require cssfw/style.css
And inside style.css
#import url(app.css);
#import url(plugins.css);
#import url(custom.css);
This works fine in my development environment (obviously), but all of those 4 CSS files cannot be found anywhere in the assets in production.
I'm obviously missing to include something, but what?
If I use something like this in production.rb:
config.assets.precompile += %w( *.css )
I get a barrage of errors, cause then it goes through every single stylesheet I have in the /vendor/ directory. if I try to be specific (such as specifying style.css), the same initial errors persist, and style is nowhere to be found.
How are they supposed to be included exactly? Preferably, I wouldn't want to include ALL the vendor assets files, cause there's only a handful that I'm actually using, but the folder contains around 20 or so that I haven't yet configured.
I'm using Rails 4.1.6 with Ruby 2.1.0, on Apache Phusion Passenger.
The trick was in changing #import to *= require, cause #import isn't following the assets pipeline. I'm still unclear of why that happens, but I changed this in style.css, which after all was actually being loaded all this time.
In my application.css:
*= require cssfw/style # /vendor/cssfw/style.css
And in the first part of style.css:
/*
*= require cssfw/app # /vendor/cssfw/app.css
*= require cssfw/plugins # /vendor/cssfw/plugins.css
*= require cssfw/custom # /vendor/cssfw/custom.css
*= require cssfw/plugins/animate # /vendor/cssfw/plugins/animate.css
*= require cssfw/plugins/box-shadows # /vendor/cssfw/plugins/box-shadows.css
*/
This would make Rails to look for them in the proper places in the vendor pipeline, although I'm being forced to practically include the entire path, minus cssfw. If I leave it out, it works fine in development, but production cannot find them.
I didn't move anything else to my application.rb, or production.rb, in case you're wondering. I think this may have a more elegant solution, but this works for now.
you should set in production.rb:
config.assets.compile = true
and in command line use:
rake assets:precompile
before launching it your server.

Using Rails 3 autoload paths isn't loading some folders but is loading others

I'm using the autoload path's in the application.rb to loads some extra modules and structs.
This is the following bit of code doing it:
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
#{config.root}/app/jobs/
)
The funny thing is both of the "concerns" folders for extending models and controllers are working perfectly.
However the jobs folder is not getting loaded at all.
Is there something special I need to do in order to get a folder in app to be loads or does anyone know why two of these folders are loading and the third isn't?
Try and remove the trailing slash after jobs.
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
#{config.root}/app/jobs
)
You don't need to explicit load jobs anyway.
http://hakunin.com/rails3-load-paths

Rails 3.2.1 heroku asset precompile error

I have added these two lines to application.rb:
config.assets.initialize_on_precompile = false
config.assets.compile = true
However I still get errors when I push to Heroku:
2012-02-05T09:48:34+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms
2012-02-05T09:48:34+00:00 app[web.1]:
2012-02-05T09:48:34+00:00 app[web.1]: ActionView::Template::Error (bootstrap.css isn't precompiled):
Any suggestions?
By the looks of it you have a bootstrap.css file that is not included properly in your manifest file within app/assets/stylesheets and that you're probably also calling directly from a stylesheet_tag.
There are a couple of approaches to this:
You could add a line to your environment config file which will ensure the css file you're calling is precompiled:
config.assets.precompile += %w( bootstrap.css )
…for example.
This is the one i would probably do; include the bootstrap.css file in a manifest file inside `app/assets/stylesheets' as mentioned above. Your manifest file will look something like this (not sure if the formatting of this will appear correctly on here, so i have also created a Gist: https://gist.github.com/1753229):
/*
*= require bootstrap
*/
/* rest of file omitted */
You might need to require more files than that depending on what your css setup is.
Try to use rake assets:precompile before committing your code and pushing it to heroku.
read this, it's a tutorial on how to get rails 3.2.1 (and ruby 1.9.3) running on heroku. You can obviously skip the bits you don't need but it should explain why these problems are happening and how to fix them.
Also, read this article by david rice, author of the useful asset_sync gem. It will help you sort this out.

Resources