rake assets:precompile failing without a useful error - ruby-on-rails

I'm trying to precompile my assets, but whenever I try it fails with an error, but doesn't tell me anything other than that so I have no idea where it's coming from or how to find it. I'm running rake assets:precompile --trace and getting the following output
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/nginx/.rvm/rubies/ruby-1.9.3-p327/bin/ruby /home/nginx/.rvm/gems/ruby-1.9.3-p327/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
undefined method `[]' for nil:NilClass
Command failed with status (1): [/home/nginx/.rvm/rubies/ruby-1.9.3-p327/bi...]
That is the full output, I've not cut anything out. As you can see, I'm just getting an error but no location or anything else.
Is there some way I can easily track this down?

OK I figured it out..well sort of.
So I know roughly why I was getting the error but still not the actual reason for the error and which file it was :(
But basically, I have altered the files that are precompiled by rails, and the method I was using was causing all css files to be precompiled regardless of whether I was importing the files into application.css.scss or not.
This was then leading to some of the SASS mixins not being found, and for some reason, having the asset compression settings that I have, caused me to simply get the error I originally posted.
Once I'd disabled the compression, I got a more helpful error which eventually lead me to the final solution.
Thanks :)

Related

Rails activestorage does not create migration files

I make an image-upload for a user profile using the activestorage gem built into rails, but it is not working, the intriguing part is that there are no errors, the migration just does not get created.
What is wrong here, any ideas on how I can fix this?
rails version - 6.0
I added require 'active_storage/engine' to the config/application.rb file already
And then ran rails active_storage:install
What is even more intriguing is that I get the same output without adding the require active_storage/engine to application.rb. And there are no errors
output
** Invoke active_storage:install (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute active_storage:install
** Invoke active_storage:install:migrations (first_time)
** Execute active_storage:install:migrations
** Invoke railties:install:migrations (first_time)
** Invoke db:load_config (first_time)
** Invoke environment
** Execute db:load_config
** Execute railties:install:migrations```
I expect the migration file to be created after this but it is not.

Ruby on Rails in production error

I've just put my Rails app online in production. And I kind of have two problems:
I get a 500 on my website for which the production.log says:
Completed 500 Internal Server Error in 10.0ms
ActionView::Template::Error (./icons/icon_nameplate.png isn't precompiled):
For this what I tried is running the following command:
bundle exec rake assets:precompile
This didn't work. I want to say that when I run the server locally on my computer with rails server everything works just fine.
Output of bundle exec rake assets:clean assets:precompile --trace:
** Invoke assets:clean (first_time)
** Execute assets:clean
/usr/bin/ruby1.9.1 /usr/local/bin/rake assets:clean:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:clean:all (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:clean:all
rm -rf /home/celliptic/public/assets
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/bin/ruby1.9.1 /usr/local/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
The second problem may be why the first one didn't get corrected after precompilation. It's just that any modification on the server isn't directly reflected on the website. Is it normal? Is it because of some kind of proxy caching my website?
Thank you for your answers!
Try running:
bundle exec rake assets:clean assets:precompile --trace
then spawn it if you are using passenger:
touch tmp/restart.txt
then check again.
The error you have: ActionView::Template::Error (./icons/icon_nameplate.png isn't precompiled), to me, seems like you're trying to load a static asset when it's not there.
I would look at your views or CSS to where you referenced icon_nameplate.png - I believe the problem will likely be that you're trying to reference the file directly, and as it has not been compiled, it's unavailable. The proof of this would be that it's referencing a static (non fingerprinted) link
After you've followed tungsten_carbide's directions, please let us know what happens
Hi what webserver you are using? and under which Linux?
try those steps:
see if you got the permissions to write the compiled assets.
you sure you include it under application.css?
paste your complete css file maybe you use methods like asset-url which can cause the error you talk about.
Thanks everyone for your help. It works well now, but I don't really know which command made the deal. I've made:
bundle exec rake assets:clean assets:precompile --trace
touch tmp/restart.txt
Changed config.assets.compile = true in production.rb
At this moment it didn't work, so I went to sleep. Woke up, load my website and it worked
So maybe it needed time to activate the changes or I don't know.
Still thank you for your help.

spree 2.0.3 heroku error precompiling assets "Error: Out of stack space"

I'm trying to get a basic spree application working on Heroku. I'm following http://railsapps.github.io/rails-heroku-tutorial.html and the spree heroku guide.
I have edited config/application.rb to include config.assets.initialize_on_precompile = false
Then, because I need to precompile before I push to Heroku, I get stuck here:
D:\code\foo>rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
d:/RailsInstaller/Ruby1.9.3/bin/ruby.exe d:/RailsInstaller/Ruby1.9.3/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Error: Out of stack space
(in D:/code/foo/app/assets/javascripts/admin/all.js)
d:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-.4.0/lib/execjs/external_runtime.rb:68:in `extract_result'
...much more...
The all.js asset is unchanged from the original installation:
Running
rake assets:clean
before the precompile fixed this for somebody else, but not for me.
Browsing around it looks like this might be a windows specific issue? If it matters I used railsinstaller and I'm running Windows 7 on fairly new laptop.
Then, because I need to precompile before I push to Heroku
This is false. By default, Heroku's Cedar stack compiles your assets during slug compilation when you push to Heroku.
For more information see: https://devcenter.heroku.com/articles/rails-asset-pipeline

rails heroku giving me We're sorry something went wrong error, gmaps4rails.css isn't compiled

I checked my heroku logs and the only thing that I can see that's giving me errors is
2013-07-04T21:32:14.887388+00:00 app[web.1]: ActionView::Template::Error (gmaps4rails.css isn't precompiled):
and then a few lines down I get
2013-07-04T21:32:14.888116+00:00 app[web.1]: Completed 500 Internal Server Error in 767ms
I'm not sure what is causing the error but maybe if I fix this issue, I can test to see if I'm still getting the error. In my confi/application.rb file I have this:
config.assets.initialize_on_precompile = false
config.assets.precompile += %w( gmaps4rails.css )
config.assets.compile = true
I'm not sure what is causing the error.
Also, I've tried restarting my heroku server, using heroku rake db:migrate and still getting the same errors.
Thanks
EDIT:
Added output from rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/andrewliu/.rvm/rubies/ruby-1.9.3-p392/bin/ruby /Users/andrewliu/.rvm/gems/ruby-1.9.3-p392#global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
Given the comments above I think you should
Remove this line from enviroment
config.assets.precompile += %w( gmaps4rails.css )
Remove this line from layout
<%= stylesheet_link_tag 'gmaps4rails' %>
Check if in applications.css you have this file included explicitly or require_tree .
because if you have gmaps4rails.css in app/assets/stylesheets then it should be precompiled with other assets.
EDIT: Explanation
What was the problem really? Two things.
First you ask Rails to add a file to asset compilation, but you should only do it if file is outside app/assets directory (ex. in gem)
Second, in layout you wanted to add a stylesheet link to this file but it was not compiled separately but as a part of application.css

rake db:migrate doesn't work and brings me back to the command line rails 3.1.1

Using rails 3.1.1 for windows with railsinstaller
>rake db:migrate
after a pause, brings me right back to the command line. No errors, no messages, just right back to the command line.
I tried
>rake --trace db:migrate
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump
Doesn't look like anything is wrong, but obviously something isn't working right.
Can anyone help?
If there are no migrations to be run, there will be no output. The --trace command outputs the various steps that rake goes through to prepare, execute, and clean up after the migration. However, when it sees that there is no migration to be run, then it doesn't actually make any DB changes. Only DB changes cause additional output.
The only difference between this and a migration is that the changes to the DB will be output to the command line. No changes => no output.
Make sure you are in the right folder (maybe in the right branch, when using git) and make sure that you have created a migration file.
rails generate migration MigrationName
Edit the generated file as you wish.

Resources