Ruby-on-rails 如何让 Haml 与 Rails 一起工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/99211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get Haml to work with Rails?
提问by kch
I am trying to get Haml to work with my Ruby on Rails project. I am new to Ruby on Rails and I really like it. However, when I attempt to add an aplication.html.hamlor index.html.hamlfor a view, I just receive errors.
我试图让 Haml 与我的 Ruby on Rails 项目一起工作。我是 Ruby on Rails 的新手,我真的很喜欢它。但是,当我尝试为视图添加aplication.html.hamlor 时index.html.haml,只会收到错误消息。
I am using NetBeans as my IDE.
我使用 NetBeans 作为我的 IDE。
回答by kch
Haml with Rails 3
带 Rails 的 Haml 3
For Rails 3 all you need to do is add gem "haml", '3.0.25'to your Gemfile. No need to install plugin or run haml --rails ..
对于Rails 3中,所有你需要做的就是添加gem "haml", '3.0.25'到您的Gemfile。无需安装插件或运行haml --rails ..
Just:
只是:
$ cd awesome-rails-3-app.git $ echo 'gem "haml"' >> Gemfile
And you're done.
你已经完成了。
回答by bowsersenior
The answers above are spot-on. You just need to put gem 'haml'in your Gemfile.
上面的答案是一针见血。你只需要gem 'haml'输入你的Gemfile.
One other tip that was not mentioned: to have rails generators use hamlinstead of erb, add the following to config/application.rb:
另一个未提及的提示:要使用 rails 生成器haml代替erb,请将以下内容添加到config/application.rb:
config.generators do |g|
g.template_engine :haml
# you can also specify a different test framework or ORM here
# g.test_framework :rspec
# g.orm :mongoid
end
回答by Ryan McGeary
First, install hamlas a gem in bundler by adding this to your Gemfile:
首先,安装HAML加入这个你在打捆作为宝石Gemfile:
gem "haml"
Run bundle install, then make sure your views are named with a *.html.hamlextension. For example:
运行bundle install,然后确保您的视图以*.html.haml扩展名命名。例如:
`-- app
`-- views
|-- layouts
| `-- application.html.haml
`-- users
|-- edit.html.haml
|-- index.html.haml
|-- new.html.haml
`-- show.html.haml
回答by Matthias
Add haml to your Gemfile:
将 haml 添加到您的 Gemfile 中:
gem "haml"
If you want to use the scaffold-functions too, add haml-rails within your development-group:
如果您也想使用脚手架功能,请在您的开发组中添加 haml-rails:
gem 'haml-rails', :group => :development
Don't forget to run:
不要忘记运行:
$ bundle install
回答by gdelfino
Before trying to use haml in your rails application, you can verify that the command line executable is installed correctly:
在尝试在 Rails 应用程序中使用 haml 之前,您可以验证命令行可执行文件是否已正确安装:
$ haml
%p
%span Hello World!
Then press CTRL-D and you should see:
然后按CTRL-D,你应该看到:
<p>
<span>Hello World!</span>
</p>
回答by Pete
First, make sure you have the HAML gem.
首先,确保您拥有 HAML gem。
gem list --local | grep haml
If haml doesn't show up in the list, then do this:
如果 haml 没有出现在列表中,请执行以下操作:
sudo gem install haml
Then do this from your project directory:
然后从您的项目目录执行此操作:
# cd ../
# haml --rails <yourproject>
That should install everything you need, and the HAML views should stop complaining and parse correctly.
这应该会安装您需要的一切,并且 HAML 视图应该停止抱怨并正确解析。
回答by v4r
This may be an old question but I think the answer is using haml-rails at https://github.com/indirect/haml-rails
这可能是一个老问题,但我认为答案是在https://github.com/indirect/haml-rails 上使用 haml-rails
回答by railsuser1984
if for some reason you installed haml, but you haml doesn't start. try
如果由于某种原因你安装了haml,但你的haml没有启动。尝试
sudo ln haml /usr/bin/
in the bin directory of your haml gem
在你的haml gem的bin目录中
for some reason this didn't happen automatically on my ubuntu 9.04 Jaunty.
出于某种原因,这不会在我的 ubuntu 9.04 Jaunty 上自动发生。

