本文介绍了具有HAML的ActionView :: MissingTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在全新安装的Snow Leopard上安装Ruby on Rails.经过战斗(和跳动)MySQL和Sphinx问题,我陷入了与HAML相关的愚蠢错误.

I'm getting Ruby on Rails set up on a fresh installation of Snow Leopard. After battling (and beating) MySQL and Sphinx problems, I'm stuck on a stupid error related to HAML.

基本上,对于使用HAML的每个视图,我都会收到一个丢失的模板错误.我可以添加一个空白的xxx.html.erb文件,并且一个(空白)页面可以正常加载.但是xxx.html.haml会引发错误,即使该文件确实存在于适当的目录中.

Essentially I'm getting a missing template error for every view that uses HAML. I can add a blank xxx.html.erb file and and a (blank) page loads fine. But xxx.html.haml throws the error, even though that file definitely exists in the appropriate directory.

这是开发服务器中的错误:

Here is the error from the development server:

ActionView::MissingTemplate (Missing template sections/index.erb in view path app/views):
  haml (2.2.4) rails/./lib/sass/plugin/rails.rb:19:in `process'

我正在使用haml宝石(2.2.4),rails宝石(2.3.4)和红宝石1.8.7.我确实运行过haml --rails.从我的RoR应用根目录中;初始化文件位于vendor/plugins/haml目录中.我已经通过IRB确认"require'haml'" => true.

I am using the haml gem (2.2.4), rails gem (2.3.4), and ruby 1.8.7. I did run haml --rails . from my RoR app root directory; the init file is in the vendor/plugins/haml directory. I have confirmed that "require 'haml'" => true via IRB.

任何帮助将不胜感激!

针对Yaraher:

尝试卸载并重新安装,除了rdocs(找不到主页README.rdoc")外,没有引起任何错误.

Tried un- and re-installing, which raised no errors except with the rdocs ("Could not find main page README.rdoc").

在脚本/控制台中:

>> require 'haml'
=> []

更新:

在该项目中安装已知可与HAML一起使用的旧版Rails似乎已解决"了该问题.我仍然很好奇听到这个问题的真实答案-我不想被困在2.3.2.

Installing an old version of Rails known to work with HAML in this project seems to have "fixed" the problem. I'd still be curious to hear a real answer to this problem -- I don't want to be stuck at 2.3.2.

sudo gem install -v 2.3.2 rails

更新2:

这肯定是由Rails 2.3.2和2.3.4之间的差异引起的.安装了两个gem后,我可以设置在我的environment.rb文件中使用的宝石. HAML在2.3.2上可以正常工作,并按照2.3.4所述中断.

This is definitely caused by a difference between Rails 2.3.2 and 2.3.4. With both gems installed I can set which is used in my environment.rb file. HAML works fine with 2.3.2 and breaks as described with 2.3.4.

推荐答案

该问题尴尬答案的时间:

Time for the embarrassing answer to this question:

Rails 2.3.2和2.3.4之间的区别在于,它不会将xxx.haml.html文件识别为应由HAML(或ERB)解析的文件;这在2.3.2中运行良好. HAML文件应始终命名为xxx.html.haml anwyay,因此,这甚至不是错误.

There is a difference between Rails 2.3.2 and 2.3.4 that does not recognize xxx.haml.html files as files that should be parsed by HAML (or ERB); this worked fine in 2.3.2. HAML files should always be named xxx.html.haml anwyay, so this isn't even a bug.

我没有意识到这是问题所在,因为我在全新的Snow Leopard安装中启用了隐藏文件扩展名"选项(默认情况下处于启用状态).因此,当我尝试通过Finder将文件扩展名切换为html.haml进行测试时,实际上将其更改为haml.html.haml或一些废话.

I didn't realize that this was the problem because I had the "hide file extensions" option turned on (on by default) in my fresh Snow Leopard installation. So when I tried switching the file extension through Finder to html.haml to test this, it actually changed it to haml.html.haml or some nonsense.

故事的寓意:我运行了以下脚本,现在HAML可与Rails 2.3.4一起使用.

Moral of the story: I ran the following script and now HAML works with Rails 2.3.4.

path = '/path_to_rails_app/views/'
dir = Dir.new(path)
dir.each do |d|
  if File.directory?(path+d)
    Dir.new(path+d).each do |f|
      if (f =~ /.*\.haml\.html$/) != nil
        File.rename(path+d+'/'+f, path+d+'/'+f.gsub('haml.html', 'html.haml'))
      end
    end
  end
end

这篇关于具有HAML的ActionView :: MissingTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:28