开发者

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

开发者 https://www.devze.com 2023-04-11 18:54 出处:网络
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.

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?


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


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.


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消