[英]How do I get Haml to work with Rails?
I am trying to get Haml to work with my Ruby on Rails project.我试图让 Haml 与我的 Ruby on Rails 项目一起工作。 I am new to Ruby on Rails and I really like it.我是 Ruby on Rails 的新手,我真的很喜欢它。 However, when I attempt to add an aplication.html.haml
or index.html.haml
for a view, I just receive errors.但是,当我尝试为视图添加aplication.html.haml
或index.html.haml
,我只会收到错误消息。
I am using NetBeans as my IDE.我使用 NetBeans 作为我的 IDE。
For Rails 3 all you need to do is add gem "haml", '3.0.25'
to your Gemfile
.对于 Rails 3,您需要做的就是将gem "haml", '3.0.25'
到Gemfile
。 No need to install plugin or run haml --rails .
无需安装插件或运行haml --rails .
. .
Just:只是:
$ cd awesome-rails-3-app.git $ echo 'gem "haml"' >> Gemfile
And you're done.你已经完成了。
The answers above are spot-on.上面的答案是一针见血。 You just need to put gem 'haml'
in your Gemfile
.你只需要在你的Gemfile
放入gem 'haml'
。
One other tip that was not mentioned: to have rails generators use haml
instead 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
First, install haml as a gem in bundler by adding this to your Gemfile
:首先,通过将以下内容添加到您的Gemfile
,将 haml作为 gem安装在 bundler 中:
gem "haml"
Run bundle install
, then make sure your views are named with a *.html.haml extension.运行bundle install
,然后确保您的视图以*.html.haml扩展名命名。 For example:例如:
`-- app
`-- views
|-- layouts
| `-- application.html.haml
`-- users
|-- edit.html.haml
|-- index.html.haml
|-- new.html.haml
`-- show.html.haml
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
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>
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 视图应该停止抱怨并正确解析。
这可能是一个老问题,但我认为答案是在https://github.com/indirect/haml-rails 上使用 haml-rails
if for some reason you installed haml, but you haml doesn't start.如果由于某种原因你安装了haml,但你的haml没有启动。 try尝试
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 上自动发生。
确保将haml
gem 添加到您的Gemfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.