ActionView::Template::Error(未预编译):在Heroku Cedar上。

11

更新:

事实证明,有时候results.image是nil或者"",这导致应用程序崩溃,因为资源管道在寻找一个像""这样的图像,但是没有找到。现在如果没有图像,我不会显示它,但我将需要添加一个默认图像来替代缺失的图像...这应该是一个更加永久的解决方案。


我在Heroku cedar和Rails资源管道的问题上遇到了一些SO的问题,并尝试了许多解决方案,但是没有一个解决方案有效,可能是因为我遇到的问题有一个独特的地方,我在其他地方没有看到过。

我的应用程序使用Rails 3.2.6,并已部署在Heroku的cedar堆栈上。这是一个基本的搜索应用程序,通过websolr搜索附加的postgres数据库,所以当你加载索引(index#index)而没有params[:q].present?时,你会得到一个搜索框,这个工作正常。但是当我在搜索框中输入内容并点击提交按钮后,index#index再次加载,但这次尝试显示结果时,我得到了以下错误:

app[web.1]: Completed 500 Internal Server Error in 440ms
app[web.1]: 
app[web.1]: ActionView::Template::Error ( isn't precompiled):
app[web.1]:     12:         - @results.each do |result|
app[web.1]:     13:           %li
app[web.1]:     14:             %div
app[web.1]:     15:               = image_tag result.image
app[web.1]:     16:             %div
app[web.1]:     17:               = result.title
app[web.1]:     18:             %div
app[web.1]:   app/views/index/index.html.haml:15:in `block in _app_views_index_index_html_haml___4350601325072829986_32734540'
app[web.1]:   app/views/index/index.html.haml:12:in   _app_views_index_index_html_haml___4350601325072829986_32734540'

我个人的情况与我见过的其他情况不同之处在于以下这行代码:

ActionView::Template::Error ( isn't precompiled):

我看到类似问题的提问中都有一个带括号的 css 文件,例如 ("foo.css" 没有预编译),而在我的情况下它似乎应该是 ("index.css" 没有预编译)。但这里什么也没有!

这是我尝试让其正常工作的暂存部署,所以我已经尝试运行 RAILS_ENV=staging rake assets:precompile(当然,需要提交结果),但这并没有解决问题。我甚至尝试在视图中剥离 style 标签(请注意那里实际上没有任何样式)。没有任何作用,我很迷茫。非常感谢您的帮助。

以下是我的 gemfile 参考:

source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'pg'
gem 'haml-rails'
gem 'mongoid'
gem 'sunspot_rails', '~> 1.3.0'
gem 'sunspot_solr'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :development do
  gem 'heroku_san'
  gem 'annotate'
  gem 'awesome_print'
end

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

group :test do
  gem 'cucumber-rails', :require => false
  gem 'capybara'
  gem 'database_cleaner'
  gem 'spork'
  gem 'launchy'
end

group :staging, :production do
  gem 'thin'
end

这是我config/application.rb文件中的配置选项:

config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.enabled = true
config.assets.version = '1.0'
config.assets.compile = true

以下是我环境/暂存.rb文件中的配置选项:

config.cache_classes = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.precompile += ['index.css.scss']
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify

刚遇到了同样的问题。非常感谢! - rickypai
1个回答

16

你有没有在某个地方使用了空的图片URL?你是否安装了CarrierWave等类似的东西?

从你的代码中我看到image_tag result.image,这可能是null吗?

这个帖子应该可以解决问题:ActionView::Template::Error ( isn't precompiled):


我没有安装CarrierWave,但是有可能其中一个图像URL为空。我会检查并发布结果。 - Jon Stokes
消除空和空白图像成功了!我会发布更新。 - Jon Stokes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接