I am not sure if this is the place to put this issue, but I am getting the following error in my local assets:precompile command. Here is the full trace:
$ rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
active_admin/nested_menu_arrow.gif isn't precompiled
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
...and I get an entirely different error in Heroku's Cedar stack
Running: rake assets:precompile
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Tasks: TOP => environment
(See full trace by running task with --trace)
Precompiling assets failed, enabling runtime asset compilation
I have no idea what is causing this error. I just ran this on a brand new, no-code-changes app, so no code of my own should be conflicting.
Your local problem probably has something to do with rails/rails#2765 and/or rails/rails#2768, dunno about the Heroku problem.
This seems to be related to Devise, please check plataformatec/devise#1339 . It seems Devise new branch has fixed this. Can we include Devise or do we need a new update of ActiveAdmin for this?
I'm on rails 3.1.1.rc1, devise 1.4.7 and activeadmin 0.3.2, and have the same problem on the heroku cedar stack when the asset:precompile rake task is launched.
I am finding the same error when trying to run RAILS_ENV=production bundle exec rake assets:precompile and it seems that for some strange reason, ActiveAdmin is trying to connect to the database. I read the Devise issue #1339 however the error in my case appears when ActiveAdmin is loading the first resource:
RAILS_ENV=production bundle exec rake assets:precompile
/Users/bruno/code/tc-v2/app/admin/affiliates.rb:1:in '<top (required)>'
(lots of stuff removed from the previous trace). I dropped the DB for production and the rake task fails because it cannot connect to the database. It's not a Heroku issue per-se. Any suggestions about what I should do to be able to pre-compile the assets on Heroku (since the database won't exist) or should I be looking at running the precompile task locally before deploy with a DB that exists locally?
Getting this too on rails 3.1.1.rc3, using devise but not activeadmin.
Yep, solves it.
So what do i need to do to sort this out using active admin on heroku?
Since activeadmin uses devise, it's probably it that causes the issue. Check the new Troubleshooting section for some config:
The solution I have found is to do the assets:precompile on my local development machine where I have access to the production database via database.yml, commit those assets to git and deploy.
The rails guides for the asset pipeline already include a note about making this work on heroku
Oops, I meant http://guides.rubyonrails.org/asset_pipeline.html but the previous link also contains the heroku fix
Yep, just an extra pointer to it in the devise README.
Changes application.rb to:-
[config.assets.initialize_on_precompile = false]
as suggested but i now get this error when running [bundle exec rake assets:precompile]
undefined method `context_class' for nil:NilClass
so still scratching my head
The trace is interesting. If you'd like to see it change the production setting in config/database.yml to something that won't work and run rake -v --trace assets:precompile. I'd post mine except I'm working on a client project. It goes something like this, though:
rake -v --trace assets:precompile
Is this reasonable? It works for me.
# These cause Rails to set up a connection to the production database, which isn't available during
# assets:precompile on Heroku, so the following unless block skips setting up these routes only when
# rake assets:precompile is being run.
# Could be a problem if the assets needed these to be loaded to compile properly; pretty sure they don't.
unless ARGV.join.include? 'assets:precompile'
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users do
post 'logout', :to => 'devise/sessions#destroy'
There could be an authentication issue if something that relied on user authentication didn't explicitly check for a user, and somehow assets:precompiled got inserted into the ARGV, but it seems to me that neither should happen.
I'm not sure if this is an issue that can just be fixed inside of ActiveAdmin or Devise will need to fix it too. I think unless/until rails loads less during asset pre-compilation, ActiveAdmin and others that have route generating scripts should avoid connecting to the DB if it hasn't already been connected to.
I made a minimal example. Here's the trace. There's a workaround branch too.
I added a ticket to rails too.
Thanks to all who have helped in isolating this problem. At this point, my problem has been solved. Thank you!
I updated my fix. Instead of putting my dynamic routes in an unless block, I'm breaking out of the entire routes block if it's precompiling assets. Here's the snippet I put at the top of the routes block in config/routes.rb:
# The ActiveAdmin routes cause Rails to set up a connection to the
# production database, which isn't available during
# assets:precompile on Heroku, so the following unless block skips
# setting up these routes only when rake assets:precompile is
# being run.
# Could be a problem if the assets needed these to be loaded to
# compile properly; pretty sure they don't.
break if ARGV.join.include? 'assets:precompile'
@benatkin The routes.rb fix worked perfectly for me (rails 3.1 on heroku). Many thanks!
Now I just have to sort out my css styles which have been overriden! :)
Yes, thanks for that routes.rb fix/hack ;-) It works for heroku with rails 3.1. Hopefully it gets into Rails
@benatkin the fix resolved that error for me but I still get a message that precompile failed.
Maybe I'm wrong, but it really seems like this should be addressed in ActiveAdmin. According to the Heroku guide, you shouldn't rely on config vars/database being present when precompiling:
@benatkin It seems ActiveAdmin uses routes in the scss files for image assets. For example:
background:url(active_admin_image_path("orderable.png")) no-repeat 0 4px;
I was setting the new config.assets.initialize_on_precompile flag in Rails 3.2 to false, which solves the heroku problems but does not resolve the routes used in the scss files.
What we really need is for ActiveAdmin not hit the DB during the initialization process... or at least when precompiling.
@marcusmateus In this SO comment the commenter discourages scss authors from using _path, and encourages them to use -url instead. I wonder where image-url comes from and if ActiveAdmin could set up its own thing like image-url (active-admin-image-url), that would be configurable in the initializer. http://stackoverflow.com/a/7442776/3461
I am running Rails 3.2.1 on Heroku Cedar with active admin and i don't have a problem. I have
config.assets.initialize_on_precompile = false
# Enable the asset pipeline
config.assets.enabled = true
But nothing else special, I am using asset_sync and the precompile succeeds.
@amalagaura precompile certainly succeeds, but the referenced paths are not properly resolved. That means that the ActiveAdmin images will not appear... since they are mostly small 'helper' icons you may not even have noticed.
@benatkin yea, I was looking into that too... the Rails guides recommend the same course of action (http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass). Since what we're trying to generate is something like
I wonder if we could simply use the following in the scss files:
Not sure if creating an active-admin-image-url syntax would be better long-term, but I'm going to take a quick stab a the above.
After a quick test, my suggestion above seems to work... now I just need to find the time to fully implement it & send a pull request.
@marcusmateus I think the image-url way that you're implementing is the most elegant approach of the ones I've considered (how it is now, active-admin-image-url, and image-url). It's great for seasoned sass authors because they can quickly see what's happening and override it with their own images or change the url if they're editing the sass. So 👍!
Just submitted a pull request #1054 ... feel free to review it & +1 the request to make sure it gets incorporated... there appears to be quite the backlog of pulls.
I use AA 0.4.4 on Cedar stack (heroku). I also get this error:
If i use (by heroku recommended) "config.assets.initialize_on_precompile = false" the error doesn't came up again, but all Background images doesn't work in AA and get removed while precompiling the css.
Did you go through this?
I did that. But with this option the ActiveAdmine CSS get's precompiled without background image config. All background icons are missing. This even happens with precompiled css on my local machine. If i didn't use this option all icons are there, but i can't deploy on heroku :-(. Maybe releated to #630 ?
Oh I assumed you were using asset_sync. That works really well, serves all your static assets out of S3 or cloudfront and works with heroku & activeadmin.
I assume #1910 combined with config.assets.initialize_on_precompile = false fixes the problem?
config.assets.initialize_on_precompile = false
Until someone can confirm that this is still an issue, I'm going to close the ticket.
Heroku pulled this from Rails 4 compile https://devcenter.heroku.com/articles/rails4-getting-started#rails-asset-pipeline
So this fix is no longer good