sren
sren

Reputation: 3623

Rails 3.1 / Active Admin / Heroku error on first load - Sass::SyntaxError

When hitting the app without any activity for a while, it throws the following error:

Sass::SyntaxError (File to import not found or unreadable: active_admin/mixins.

If I refresh the page, it loads perfectly without any errors.

Is this a Heroku issue or a real app error? Anyone know of any solutions?

Upvotes: 3

Views: 2073

Answers (5)

Martin Streicher
Martin Streicher

Reputation: 2031

I have tried several things to no avail. I tried precompiling locally and on Heroku.

When I hit my Heroku site, I get...

ActionView::Template::Error (File to import not found or unreadable: active_admin/mixins.
2012-08-01T22:00:22+00:00 app[web.2]: Load paths:
2012-08-01T22:00:22+00:00 app[web.2]:   /app
2012-08-01T22:00:22+00:00 app[web.2]:   /app/vendor/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/app/assets/stylesheets
2012-08-01T22:00:22+00:00 app[web.2]:   (in /app/app/assets/stylesheets/active_admin.css.scss)):
2012-08-01T22:00:22+00:00 app[web.2]:     6:   <title><%= [@page_title, active_admin_application.site_title].compact.join(" | ") %></title>
2012-08-01T22:00:22+00:00 app[web.2]:     7: 
2012-08-01T22:00:22+00:00 app[web.2]:     8:   <% ActiveAdmin.application.stylesheets.each do |style| %>
2012-08-01T22:00:22+00:00 app[web.2]:     9:     <%= stylesheet_link_tag style.path, style.options %>
2012-08-01T22:00:22+00:00 app[web.2]:     10:   <% end %>
2012-08-01T22:00:22+00:00 app[web.2]:     11:   <% ActiveAdmin.application.javascripts.each do |path| %>
2012-08-01T22:00:22+00:00 app[web.2]:     12:     <%= javascript_include_tag path %>
2012-08-01T22:00:22+00:00 app[web.2]:   app/assets/stylesheets/active_admin.css.scss:2

Upvotes: 1

spartan_dev
spartan_dev

Reputation: 103

I tried Stephane Paul's solution, even though I'm not smart enough to understand it - didn't help.

What solved the problem for me was pre-compiling ahead of time.

Just to clarify, I've only seen this error when trying to use activeadmin on Heroku - worked fine in development.

And the solution was to run rake assets:precompile and make sure to git commit the public/assets directory to heroku, which will then not precomiple the assets itself, hence the error will be skipped.

Upvotes: 0

Stephane Paul
Stephane Paul

Reputation: 21

add a sass_heroku.rb to config/initializers and it should do the trick

heroku = !!ENV['HEROKU_TYPE']
css_dir = heroku ? 'tmp' : 'public'
location = Rails.root + 'app/styles'

unless Sass::Plugin.template_location_array.any? { |pair| pair.first.to_s == location.to_s }
    Sass::Plugin.add_template_location(location, Rails.root + css_dir + 'stylesheets')
end

if heroku
  Sass::Plugin.template_location_array.each do |template_location, css_location|
    css_location.sub!(%r{/public/stylesheets$}, "/#{css_dir}/stylesheets")
  end
  Rails.configuration.middleware.insert_after 'Sass::Plugin::Rack', 'Rack::Static', :urls => ['/stylesheets'], :root => "#{Rails.root}/tmp"
end

Upvotes: 1

Benjamin
Benjamin

Reputation: 2118

You need to remove the gem 'sass-rails', " ~> 3.1.0" from the group set.

Upvotes: 4

Neil Middleton
Neil Middleton

Reputation: 22238

I would guess that you have a Sass syntax error that the asset pipeline is dealing with during compile. The reason for it only happening after inactivity is that the app is idled down by Heroku and needs to restart to serve a request, hence the asset pipeline 'waking up' again.

Upvotes: 1

Related Questions