从不同目录编译haml
我用它来启动haml编译:从不同目录编译haml,haml,Haml,我用它来启动haml编译: /install-location/haml /myproject/index.haml /myproject/index.html 当我在带有haml文件的目录中时,它运行正常,但当我切换到其他目录时,我得到: Exception on line 3: No such file or directory @ rb_sysopen - assets/page/structure/_head.haml Use --trace for backtrace. 如何解
/install-location/haml /myproject/index.haml /myproject/index.html
当我在带有haml文件的目录中时,它运行正常,但当我切换到其他目录时,我得到:
Exception on line 3: No such file or directory @ rb_sysopen - assets/page/structure/_head.haml
Use --trace for backtrace.
如何解决此问题?您尝试读取的路径-
资产/page/structure/\u head.haml
与工作目录相关,而不是与源文件目录相关。当你在同一个目录中时,它会工作,因为这两个目录是相同的
为了能够从不同的目录运行代码,您需要使用绝对路径。您可以使用和\uuuu FILE\uuu
将相对路径转换为绝对路径:
= Haml::Engine.new(File.read(File.expand_path 'assets/page/structure/_head.haml', File.dirname(__FILE__))).render
看起来您的Haml中有一些代码试图读取另一个Haml文件,但使用的是相对路径。代码的这一部分看起来像什么?第3行是=Haml::Engine.new(File.read('assets/page/structure/_head.Haml'))。renderThis在使用例如guard Haml时不起作用。