在一段时间没有任何活动的情况下点击应用程序时,会引发以下错误:
Sass::SyntaxError (File to import not found or unreadable: active_admin/mixins.
如果我刷新页面,它会完美加载而不会出现任何错误。
这是 Heroku 问题还是真正的应用程序错误?有人知道任何解决方案吗?
在一段时间没有任何活动的情况下点击应用程序时,会引发以下错误:
Sass::SyntaxError (File to import not found or unreadable: active_admin/mixins.
如果我刷新页面,它会完美加载而不会出现任何错误。
这是 Heroku 问题还是真正的应用程序错误?有人知道任何解决方案吗?
您需要从组集中删除 gem 'sass-rails', "~> 3.1.0"。
我猜你有一个资产管道在编译期间处理的 Sass 语法错误。它仅在不活动后发生的原因是应用程序被 Heroku 闲置并需要重新启动以服务请求,因此资产管道再次“唤醒”。
添加一个 sass_heroku.rb 到 config/initializers 它应该可以解决问题
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
我尝试了几件事无济于事。我尝试在本地和 Heroku 上进行预编译。
当我访问我的 Heroku 网站时,我得到...
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
我尝试了 Stephane Paul 的解决方案,尽管我不够聪明,无法理解它 - 没有帮助。
为我解决问题的是提前预编译。
澄清一下,我只在尝试在 Heroku 上使用 activeadmin 时看到了这个错误——在开发中工作得很好。
解决方案是运行rake assets:precompile
并确保将 public/assets 目录 git commit 到 heroku,这样就不会预编译资产本身,因此将跳过错误。