views:

7265

answers:

6

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.haml or index.html.haml for a view, I just receive errors.

I am using NetBeans as my IDE. Any help would be appreciated.

A: 

What are the errors?

Do you have the HAML plugin installed?

Otto
+13  A: 

First, install haml as a gem in bundler by adding this to your Gemfile:

gem "haml"

Run bundle install, then make sure your views are named with a *.html.haml extension. For example:

`-- app
    `-- views
        |-- layouts
        |   `-- application.html.haml
        `-- users
            |-- edit.html.haml
            |-- index.html.haml
            |-- new.html.haml
            `-- show.html.haml
Ryan McGeary
If you have erb templates already go ahead and rename them .html.haml. At the top of the file tell haml to use the erb filter by putting :erb at the top of the file. Then you can slowly convert your templates. More on filters by visiting.http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html
gregf
Why is it important to end with .html.haml and not just .haml?
Teef L
mathee, It's Rails convention. `name.mime.format` (e.g. show.html.erb, show.xml.builder, show.html.haml)
Ryan McGeary
+7  A: 

First, make sure you have the HAML gem.

gem list --local | grep haml

If haml doesn't show up in the list, then do this:

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.

Pete
Be mindful that for Rails 3, `haml --rails` is no longer needed. See my answer for Rails 3 howto.
kch
+2  A: 

Before trying to use haml in your rails application, you can verify that the command line executable is installed correctly:

$ haml
%p 
  %span Hello World!

Then press CTRL-D and you should see:

<p>
  <span>Hello World!</span>
</p>
gdelfino
A: 

if for some reason you installed haml, but you haml doesn't start. try

sudo ln haml /usr/bin/

in the bin directory of your haml gem

for some reason this didn't happen automatically on my ubuntu 9.04 Jaunty.

railsuser1984
+13  A: 

Haml with Rails 3

For Rails 3 all you need to do is add gem "haml" to your Gemfile. No need to install plugin or run haml --rails ..

Just:

$ cd awesome-rails-3-app.git
$ echo 'gem "haml"' >> Gemfile

And you're done.

kch