Skip to content
This repository

Sass Precompile failing in Heroku Cedar Stack #474

Closed
ghost opened this Issue September 12, 2011 · 38 comments
Deleted user

The content you are editing has changed. Reload the page and try again.

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
rake aborted!
active_admin/nested_menu_arrow.gif isn't precompiled
(in /Users/mattbridges/Sites/frbc-dev/app/assets/stylesheets/active_admin.css.scss)

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
rake aborted!
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
   Injecting rails31_enable_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.

Sending Request…

Attach images by dragging & dropping or selecting them. Octocat-spinner-32 Uploading your images… Unfortunately, we don't support that file type. Try again with a PNG, GIF, or JPG. Yowza, that's a big file. Try again with an image file smaller than 10MB. This browser doesn't support image attachments. We recommend updating to the latest Internet Explorer, Google Chrome, or Firefox. Something went really wrong, and we can't process that image. Try again.

Dale Hofkens

Your local problem probably has something to do with rails/rails#2765 and/or rails/rails#2768, dunno about the Heroku problem.

Mohammad Alansari

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?

Jaime Iniesta

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.

Bruno Mattarollo

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:

/Users/bruno/.rvm/gems/ruby-1.9.2-p290@tc2/gems/activeadmin-0.3.2/lib/active_admin/event.rb:22:in 'dispatch'
/Users/bruno/.rvm/gems/ruby-1.9.2-p290@tc2/gems/activeadmin-0.3.2/lib/active_admin/application.rb:95:in 'find_or_create_namespace'
/Users/bruno/.rvm/gems/ruby-1.9.2-p290@tc2/gems/activeadmin-0.3.2/lib/active_admin/application.rb:86:in 'register'
/Users/bruno/.rvm/gems/ruby-1.9.2-p290@tc2/gems/activeadmin-0.3.2/lib/active_admin.rb:60:in 'register'
/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?

Oskar Boethius Lissheim

Getting this too on rails 3.1.1.rc3, using devise but not activeadmin.

Oskar Boethius Lissheim

Yep, solves it.

robbied72

So what do i need to do to sort this out using active admin on heroku?

Oskar Boethius Lissheim

Since activeadmin uses devise, it's probably it that causes the issue. Check the new Troubleshooting section for some config:

https://github.com/plataformatec/devise/blob/master/README.rdoc

Bruno Mattarollo

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.

Jaime Iniesta

The rails guides for the asset pipeline already include a note about making this work on heroku

plataformatec/devise@96f55a7#diff-1

Jaime Iniesta

Oops, I meant http://guides.rubyonrails.org/asset_pipeline.html but the previous link also contains the heroku fix

Oskar Boethius Lissheim

Yep, just an extra pointer to it in the devise README.

robbied72

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]

rake aborted!
undefined method `context_class' for nil:NilClass

so still scratching my head

benatkin

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 task
  • railties
  • loads environment
  • railties
  • loads routes
  • routes load ActiveAdmin
  • ActiveAdmin wants a database-specific setting
  • ActiveRecord tries to load the database
benatkin

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'
    ActiveAdmin.routes(self)

    devise_for :admin_users, ActiveAdmin::Devise.config

    devise_for :users do
      post 'logout', :to => 'devise/sessions#destroy'
    end
  end

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.

benatkin

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.

benatkin

I made a minimal example. Here's the trace. There's a workaround branch too.

benatkin

I added a ticket to rails too.

Deleted user

The content you are editing has changed. Reload the page and try again.

Thanks to all who have helped in isolating this problem. At this point, my problem has been solved. Thank you!

Sending Request…

Attach images by dragging & dropping or selecting them. Octocat-spinner-32 Uploading your images… Unfortunately, we don't support that file type. Try again with a PNG, GIF, or JPG. Yowza, that's a big file. Try again with an image file smaller than 10MB. This browser doesn't support image attachments. We recommend updating to the latest Internet Explorer, Google Chrome, or Firefox. Something went really wrong, and we can't process that image. Try again.

benatkin

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:

Myapp::Application.routes.draw |do|
  # 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'
Gareth Bradley

@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! :)

Ankur Sethi

Yes, thanks for that routes.rb fix/hack ;-) It works for heroku with rails 3.1. Hopefully it gets into Rails

BIG Folio

@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:

http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting

Marcus Mateus

@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.

benatkin

@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

Ankur Sethi

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.

Marcus Mateus

@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

background:url("/assets/active_admin/orderable.png");

I wonder if we could simply use the following in the scss files:

background:image-url("active_admin/orderable.png")

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.

Marcus Mateus

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.

benatkin

@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 :thumbsup:!

Marcus Mateus

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.

Todd Mazierski toddmazierski referenced this issue from a commit February 26, 2012
Commit has since been removed from the repository and is no longer available.
S.Korth
skorth commented May 16, 2012

I use AA 0.4.4 on Cedar stack (heroku). I also get this error:

Running: rake assets:precompile
rake aborted!
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?

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.

S.Korth
skorth commented May 16, 2012

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 ?

Ankur Sethi

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.

Sean Linsley
Collaborator

I assume #1910 combined with config.assets.initialize_on_precompile = false fixes the problem?

Sean Linsley seanlinsley closed this March 27, 2013
Sean Linsley
Collaborator

Until someone can confirm that this is still an issue, I'm going to close the ticket.

Alex

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.