Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

css not getting precompiled #483

Closed
jrosw opened this Issue · 61 comments
@jrosw

I have a standard Rails 3.1.1.rc1 application set up. The only thing I have done to this point:

  • rails new myapp -T -d postgresql
  • Edited gemfile to add active_admin and a few other gems
  • Moved sass-rails out of assets group as per issue #447
  • Set up a very simple index page and set root :to => this page, which has no dynamic content
  • migrated the database and run in development mode. Everything runs fine.
  • Send the app over to the production server (Apache2, Passenger, Postgresql), migrate database and access the /admin

At this point I get a 500 error. So checking the production log, I get

ActionView::Template::Error (active_admin.css isn't precompiled):
    6:   <title><%= [@page_title, active_admin_application.site_title].compact.join(" | ") %></title>
    7:
    8:   <% ActiveAdmin.application.stylesheets.each do |path| %>
    9:     <%= stylesheet_link_tag path %>
    10:   <% end %>
    11:   <% ActiveAdmin.application.javascripts.each do |path| %>
    12:     <%= javascript_include_tag path %>

So, I open up a terminal and do

rake RAILS_ENV=production assets:precompile

And all the assets are compiled, except for the active_admin.css. I can see that the active_admin.css.scss file is in app/assets/stylesheets but for some reason it is being skipped.

Here is the gemfile:

gem 'rails', '3.1.1.rc1'

gem 'pg'
gem 'sass-rails', "  ~> 3.1.0"
group :assets do
  gem 'therubyracer'
#  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'ancestry'
gem 'cancan', :git => "git://github.com/ryanb/cancan.git", :branch => "2.0"
gem 'friendly_id'
gem 'role_model'
gem 'activeadmin'

group :development, :test do
  gem 'guard-rspec'
end

group :development do
  gem 'rspec-rails'
  gem 'unicorn'
  gem 'capistrano'
end

group :test do
  gem 'rspec'
  gem 'webrat'
  gem 'factory_girl_rails'
end

Other than the above gemfile and very basic index page I have made no modifications to the application.

@szymon-przybyl

I have the same issue.

To precompile active_admin.css.scss you can just add it to config/environments/production.rb , to config.assets.precompile , but even then I have error that activeadmin images aren't precompiled :/

@szymon-przybyl

Add the following line to your config/environments/production.rb:

config.assets.precompile += %w[active_admin.css active_admin.js]

btw, it is a good idea to add that note to readme of activeadmin

@szymon-przybyl

I've added that note to Readme in this pull request: #443

@jrosw

Adding js/css to config.assets.precompile worked for me, thanks

@mrbrdo

This issue is bad! Fix please or add very clear note to readme and docs!

@szymon-przybyl

@mrbrdo i've already pulled a request with that instructions to readme: #443

@rtdp
config.assets.precompile += %w[active_admin.css active_admin.js]

this solved the issue for me as well.
Btw, this is not yet mentioned in readme.

@clarif

Adding config.assets.precompile didn't work for me but the following did (still in production.rb):

config.assets.compile = true

(found here: rails/rails#2765 (comment))

@orthodoX

requiring sass-rails from "3-1-stable" branch in my Gemfile solved me all the troubles I had with this precompiling.

@pcreux pcreux closed this
@giedriusr

doesn't work even adding config.assets.precompile += %w[active_admin.css active_admin.js] to production :(

@bbonamin

@giedriusr
It worked for me after adding
config.assets.compile = true

and the configuration discussed in this issue

@cwoodcox

Yeah, I'm still having this issue on Rails 3.1.1 with the configuration in place, and I manually precompiled assets on the server with the rake task.

@ghost

Could you also update http://activeadmin.info/documentation.html with this "tip"?

@jschwindt

I sent this pull request that solves the problem adding the assets to the precompile list in the engine itself:

#822

@abuisman
config.assets.compile = true

This worked for me thanks.

@jschwindt

@abuisman Yes, it works, but that way the assets are compiled after the first request and it can take time. And if you have an assets server you need to compile the assets locally before sending them to the assets server.

My pull request remove the necessity of having to modify production.rb to include something that is related with the gem.

@seanlinsley
Owner

I've tried both AA 0.3.4 and 0.4.0 on Rails 3.1, but neither of these solutions have worked for me. I've tried every suggestion in this thread but it still refuses to work. Has something changed in such a short time?

Edit: I just made a bare-bones Rails & Active Admin test application to confirm, and I'm still getting this:

ActionView::Template::Error (active_admin.css isn't precompiled):
    6:   <title><%= [@page_title, active_admin_application.site_title].compact.join(" | ") %></title>
    7: 
    8:   <% ActiveAdmin.application.stylesheets.each do |style| %>
    9:     <%= stylesheet_link_tag style.path, style.options %>
    10:   <% end %>
    11:   <% ActiveAdmin.application.javascripts.each do |path| %>
    12:     <%= javascript_include_tag path %>

@chrisval

Is there a fix to this problem that doesn't imply setting config.assets.compile at true?

@mrbrdo

Add the necessary files to config.assets.precompile

@chrisval

@mrbrdo Thanks for your answer. But I already added all my css and js files thanks to
config.assets.precompile += [/^a-z0-9+(css|js)$/]

@mrbrdo

I would guess that doesn't include subdirectories, could be wrong. Adding SPECIFIC PATHS to config.assets.precompile worked for me.

@chrisval

The thing is that when I test it in localhost with :
RAILS_ENV=staging bundle exec rake assets:precompile
rails server -e staging
It works perfectly.

@seanlinsley
Owner

@chrisval It was a stupid mistake... but the reason config.assets.compile = true wasn't working was because it was also set to false later on in the file ^^' Perhaps that's what you're running in to as well?

@chrisval

I thank you for your follow-up. But it figured out the problem was on Heroku's side.
They advised me to download their Heroku Lab plugin and enter:
heroku labs:disable user_env_compile -a myapp
Precompilation worked perfectly after that!

See https://devcenter.heroku.com/articles/labs-user-env-compile for full details.

@latortuga

Anyone using Heroku in this thread should note that the precompile task does NOT look at production.rb. If you add the active admin assets to the precompile list, you MUST do it in application.rb.

@kbighorse

Heroku user, neither production.rb nor application.rb are working for me, any solutions?

@latortuga

@kbighorse Assets not being precompiled is typically one (or both) of two things:

  1. The :assets gem group is not being required during precompile. Check that your Bundler.require is requiring :assets at the top of application.rb
  2. The precompile list does not include the active admin assets. config.assets.precompile += %w[ active_admin.css active_admin.js ] in application.rb.

If adding to the precompile list isn't working, I'd wager the problem is the first one.

@chrisval

If the solutions provided by latortuga don't help, try the solution here https://devcenter.heroku.com/articles/labs-user-env-compile

@kbighorse

@chrisval tried that earlier, said that feature wasn't enabled for me. Got it working as long as I commit compiled assets to source control, trying to get it to compile into the slug at deploy time. Will post my configuration when I do.

@latortuga

@kbighorse did you run the active admin assets generator (rails g active_admin:assets)? If the assets aren't being precompiled that means that they aren't a part of any of sprockets manifest files. You have to either a) add them to your existing manifest (often require_tree . will do this for you but it has the side effect of including the active admin styles everywhere) or b) manually add them to the list of of files that are precompiled (using the config.assets.precompile).

@kbighorse

@latortuga Yes, the asset files are present, and like I said, I've successfully precompiled locally, I just have to check the compiled assets into source control for Heroku to find them. I'm trying to have Heroku compile them at slug compile time. To make that work, I can't have manifest.yml in source control, is that what you were suggesting? Or did you mean /app/assets/stylesheets/application.css?

FWIW, I had this same issue with nested_forms assets, but adding them to the config.assets.precompile array worked like a charm. Not sure why active_admin should be that different.

@latortuga

@kbighorse I was talking about your sprockets Rails manifest file, the second one you mentioned (app/assets/stylesheets/application.css by default).

The active admin assets installer calls the file active_admin.css.scss - is your call that appends to the precompile list using the right name? It looks like nested_form only has js assets and not CSS - my best guess is that your issue is stemming from the fact that you are either not using sass or you aren't including sass (or the assets gem group) in your Bundler.require call at the top of application.rb. This would prevent the active admin css from compiling properly. You said you can successfully precompile locally, but can you do it successfully with config.initialize_on_precompile = false set in application.rb? If not, it's probably a problem with sass. If you can, then I'm stumped!

@kbighorse

I've tried both 'active_admin.css' and 'active_admin.css.scss' in the precompile array. Here's my current Bundler snippet:

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

though I've uncommented the other line as well in my many permutations now.

And config.assets.initialize_on_precompile = false is required for Heroku, so it's been that way.

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end
...
gem 'sass-rails',   "~> 3.1.0" # had to take this line out of group :assets for some reason I forget..

Yes, it is a little frustrating, but I do have Heroku support on it, we'll see what they say. I am a bit puzzled fundamentally why my case would be particular, just doing a basic deployment on Heroku. I might also mention that I had to use active_admin v0.3.4, I forget why. Active Admin seems very useful, but I have hit snags pretty much every step of the way.

@agis-

So what's with that issue? What's the workflow to be able to deploy on Heroku?

This is giving me a hard time too. So should we have config.assets.compile set to false and precompile the assets locally and then push them on Heroku? Or?

Or use Heroku's Lab Plugin?

@latortuga

@Agis- I added a guide to the wiki so if you're still having problems, check it out here

@agis-

@latortuga Thanks! All these does not apply for the Bamboo stack?

@latortuga
@agis-

I'm currently running 3.2.3 on Bamboo stack with the asset pipeline enabled so I guess it's fine, but I guess I'll migrate to Cedar just to be sure.

@latortuga

That's interesting and good to note. Their docs are somewhat unclear - this makes it sound like the asset pipeline is only supported on Cedar but it isn't conclusive about it being unsupported on Bamboo. Choice quotes:

While Rails 3.1 and 3.2 can run on the Bamboo stack without the asset pipeline, these versions of Rails runs best on Heroku’s Cedar stack.

The new Rails asset pipeline is supported on Heroku’s Cedar stack.

Also found this on SO which says you should precompile before deploy and it works fine.

@vood

If you use capistrano add load 'deploy/assets' to your Capfile

@GideonJa

Why is this issue closed? I'm trying to deploy to Heroku Cedar and getting the same error.
I followed the steps on this wiki with little success.
1. Added config.assets.precompile += %w( active_admin.css active_admin.js ) in production.rb
2. Place assets in vendor/assets
3. Confirmed bundle exec rake assets:precompile RAILS_ENV=production
4. Have config.initialize_on_precompile = false in application.rb

  • I got it to work with no CSS when i used the config.assets.compile=true production.rb
  • The only thing i did not try was heroku labs:disable user_env_compile -a myapp because of this warning:

Warning

Changing config vars will not cause an app’s slug to be recompiled. This could lead to unexpected inconsistency if a slug was compiled with a different set of config vars than those it is run against. Pushing new code will cause the slug to be recompiled against the current set of config vars.

So I am not sure of the consequences

@latortuga

@GideonJa I noted in the wiki that you cannot use production.rb on Heroku, it is ignored during precompile. However, someone changed it to say production.rb which is really quite obnoxious. @mergulhao any explanation on why you removed my note?

@mergulhao

I updated the wiki because I tested it on Heroku and it worked for me to use that configuration in production.rb. So I thought the wiki is outdated.

I put it as the first option on the wiki since with all updated gems (rails and active_admin) it's the only configuration that is needed to put it to work on Heroku.

It's not personal, sorry.

@latortuga

@GideonJa to answer your question, this issue is closed because the problem is almost always a configuration issue and there are a number of solutions posted. I sympathize with your troubles, having spent a number of hours that I can never have back simply staring at unstyled or error pages due to Heroku's asset pipeline handling. There are several configuration problems that can occur that would cause precompile issues, especially if your situation is any of the following:

  • Using a default sprockets manifest that includes the require_tree directive
  • Lack of familiarity with how sprockets directives work (it's very easy to make a mistake constructing a manifest)
  • Maintaining a legacy Rails app that began on 2.x or 3.0 and was migrated to 3.1+
  • Deploying to Heroku for the first time after being on a different platform

I encourage you to try putting your precompile additions in application.rb (note: I may be beating a dead horse here but, do not use production.rb if you intend for Heroku to precompile when you deploy, Heroku never reads the production.rb config during the precompile task) and give it another try. I'm sorry about the documentation oversight, we'll try to keep it better managed in the future.

@GideonJa
  • Added config.assets.precompile += %w( active_admin.css active_admin.js ) to application.rb and deployed: no change
  • just in case I also added config.assets.compile=true to application.rb and deployed: no change

Out of the 4 points you had mentioned, the last 2 are not relevant to my case (Maintaining a legacy... and Deploying to Heroku for the first time after being ...)

I thought i solved the require_tree directive by moving active_admin.css & active_admin.js to the vendor folder,
so i really don't know what to do next...

@jpmckinney

The current thread for a proper fix to this issue is #834

@jpmckinney

@latortuga Setting the precompile config in production.rb works fine if you are running the assets:precompile task locally and committing the compiled assets to git before pushing to Heroku.

@latortuga

@jpmckinney why would Heroku care what the precompile list includes if it's not precompiling?

@jpmckinney

? All I'm saying is that if you're compiling assets locally with RAILS_ENV=production bundle exec rake assets:precompile then there's nothing wrong with setting the precompile config in production.rb. You're telling people to never use production.rb, but there is at least one case where it makes sense.

@latortuga

@GideonJa just to be explicitly clear, in your app, you have:

vendor/assets/stylesheets/active_admin.css
vendor/assets/javascripts/active_admin.js

And in application.rb you have:

config.initialize_on_precompile = false
config.assets.precompile += %w( active_admin.css active_admin.js )

Are you modifying any javascript/stylesheet inclusion anywhere? Does heroku report that precompile fails when you deploy?

@latortuga

@jpmckinney I updated one of my previous comments to be more explicit on this note but I reviewed my other replies and the wiki page and all of them are very clear about how Heroku does not read production.rb during precompilation. Yes there are other options for compiling assets, including precompiling locally and live compilation.

@agis-

@GideonJa You should check the logs using heroku logs -t (Heroku's CLI). Maybe you haven't include active_admin/print.css for precompiling, at least that was in my case.

Also, ensure that you're on the Cedar stack.

@Dagnan

Hi all. I read /wiki/Heroku-Cedar-deployment-with-the-Asset-Pipeline (BTW this link should be given in the README) and I do not understand why if I have active_admin.css.scc in assets/stylesheets it is not loaded by sprocket with "require_tree ."

Also do you confirm that the only utility of moving ActiveAdmin assets to vendro/assets is not have them is other parts of the app except the admin?

@latortuga

Hi all. I read /wiki/Heroku-Cedar-deployment-with-the-Asset-Pipeline (BTW this link should be given in the README) and I do not understand why if I have active_admin.css.scc in assets/stylesheets it is not loaded by sprocket with "require_tree ."

Do you mean app/assets or vendor/assets? Your question is rather vague so you'll have to add more details such as:

  • where did you put the active admin css file exactly
  • what file is your sprockets directive in
  • what output did you see versus what you expected to see

Also do you confirm that the only utility of moving ActiveAdmin assets to vendro/assets is not have them is other parts of the app except the admin?

It's the primary utility. It's very easy to inadvertently include the active admin css in all parts of your site by using require_tree. Moving the AA assets to vendor/assets bypasses this risk.

@Dagnan

active_admim.css.scss is in app/assets/stylesheets, and application.css is the default:

 *= require_self
 *= require_tree .

Whith just this configuration the active_admin.css.scss file is not precompiled. I have to put in my application.rb:

config.assets.precompile += %w[active_admin.css active_admin.js active_admin/print.css]

Thanks for helping!

@coreyward

+1 on what @Dagnan said. I am using ActiveAdmin 0.5.0 and, perhaps a bit unconventionally, not using the default precompile Proc that includes a confusing grab of files (including CSS partials, and missing a bunch of required files, making it more of a hassle than it is worth).

I have had to manually specify all three of active_admin.css, active_admin.js, and active_admin/print.css for pre-compilation or I get an AssetNotPrecompiledError. This is unexpected and a pain in the ass. ActiveAdmin should know how to precompile its own assets.

@sickill

+1 on what @coreyward and @Dagnan said.

@Sporky023

I'm using activeadmin-0.5.0

I was able to deploy to Cedar and use active admin by adding this to config/application.rb:

    config.assets.precompile += ['active_admin.css', 'active_admin.js', 'active_admin/print.css']
@rishijain

I am getting this error on development and production(heroku) :-
wrong number of arguments(1 for 0) (in /app/assets/stylesheets/active_admin.css.scss)

(around line #9):

6: <%= [@page_title, active_admin_application.site_title].compact.join(" | ") %>
7:
8: <% ActiveAdmin.application.stylesheets.each do |path| %>
9: <%= stylesheet_link_tag path %>
10: <% end %>
11: <% ActiveAdmin.application.javascripts.each do |path| %>
12: <%= javascript_include_tag path %>

I have tried above solutions but no success. Anyone?

@mlushpenko

Thanks, Clarif, this worked for me as well
"clarif commented a year ago

Adding config.assets.precompile didn't work for me but the following did (still in production.rb):

config.assets.compile = true

(found here: rails/rails#2765)"

@reqorder

@mlushpenko your solution is interpreted in the following manner:
'if you can't find a specific precompiled asset, compile it on runtime.'
If this is your desired way of handling this issue, feel free to use it. the preferred way is adding the files to the precompile list and set config.asset.compile = false

@raysapida raysapida referenced this issue from a commit in raysapida/mustached-octo-robot
@raysapida raysapida Set compile to true 523b9d8
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.