Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activeadmin heroku stylesheet config issue with partial fix

I was receiving the following error message after precompiling my assets locally and then pushing the code to Heroku:

2012-03-28T17:06:01+00:00 app[web.1]: Started GET "/admin/login" for 67.163.67.203 at 2012-03-28 17:06:01 +0000

2012-03-28T17:06:01+00:00 app[web.1]: 

2012-03-28T17:06:01+00:00 app[web.1]: ActionView::Template::Error (File to import not found or unreadable: active_admin/mixins.

2012-03-28T17:06:01+00:00 app[web.1]: Load paths:
2012-03-28T17:06:01+00:00 app[web.1]:   /app
2012-03-28T17:06:01+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/activeadmin-0.4.3/app/assets/stylesheets
2012-03-28T17:06:01+00:00 app[web.1]:   (in /app/vendor/assets/stylesheets/active_admin.css.scss)):
2012-03-28T17:06:01+00:00 app[web.1]:     7: 
2012-03-28T17:06:01+00:00 app[web.1]:     6:   <title><%= [@page_title, active_admin_application.site_title].compact.join(" | ") %></title>
2012-03-28T17:06:01+00:00 app[web.1]:     8:   <% ActiveAdmin.application.stylesheets.each do |style| %>
2012-03-28T17:06:01+00:00 app[web.1]:     9:     <%= stylesheet_link_tag style.path, style.options %>
2012-03-28T17:06:01+00:00 app[web.1]:     10:   <% end %>
2012-03-28T17:06:01+00:00 app[web.1]:     11:   <% ActiveAdmin.application.javascripts.each do |path| %>
2012-03-28T17:06:01+00:00 app[web.1]:     12:     <%= javascript_include_tag path %>
2012-03-28T17:06:01+00:00 app[web.1]:   vendor/assets/stylesheets/active_admin.css.scss:2

...

I tried a bunch of different options including the following tip that I found here - http://mrdanadams.com/2011/exclude-active-admin-js-css-rails/ and others on the GitHub page.

None of those options worked. Ultimately, I received some advice to delete my public/assets directory from git, push the code to Heroku and let Heroku precompile the assets. This approach partially worked. I no longer receive the error message when I try to go to the /admin page of my site. However, the active_admin CSS files are missing. It suspects that since Heroku did the precompiling it is not throwing up an error even though the active_admin.css files are not being precompiled. How can I get active_admin.css precompiled?

Btw, I am running rails 3.2.

EDIT:

It appears that my "fix" was not complete. If I have require_tree . or require_directory . in my application.css then it works but it screws up my main apps CSS because they all get compiled to application.css. If I don't have one of those entries then it breaks. Any thoughts on how I can resolve this?

like image 676
rodleg Avatar asked Mar 29 '12 21:03

rodleg


1 Answers

I was finally able to resolve this issue. In case someone else runs into this problem, I thought I would document the steps that I took to resolve it.

I ran my application locally in production mode (RAILS_ENV=production rails s) and was able to duplicate the error that I received on Heroku on my local machine.

I copied my active_admin.css.scss and active_admin.js to the /vendor/assets directory. Since y app kept telling me that it was missing active_admin/mixins I also copied the entire active_admin directory in assets to the vendor/assets directory. I am not sure if this is necessary or not.

From a Heroku perspective, I've been told, but can not confirm, that production.rb is not read during the precompile so all settings need to be defined in application.rb. So, I made sure that I had the following settings in application.rb -

#Added to fix devise/active admin issue ?
config.assets.initialize_on_precompile = false

# Precompile additional assets. Defaults to [application.js, application.css, non-JS/CSS]
config.assets.precompile += ['active_admin.css.scss', 'active_admin.js'] 

I found most of above tips around the net (on stackoverflow, heroku, github, etc.). The part that I did not see was the need to make change Bundler.require in application.rb from:

Bundler.require(*Rails.groups(:assets => %w(development test)))

to:

Bundler.require(:default, :assets, Rails.env)

Once I made those changes then I could push the code onto Heroku and let it precompile the assets for me. I hope that this can help someone save some time in resolving this issue.

like image 159
rodleg Avatar answered Oct 15 '22 23:10

rodleg