How do I get Haml to work with Rails?

∥☆過路亽.° 提交于 2019-11-26 23:59:03

问题


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.


回答1:


Haml with Rails 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 ..

Just:

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

And you're done.




回答2:


The answers above are spot-on. You just need to put gem 'haml' in your Gemfile.

One other tip that was not mentioned: to have rails generators use haml instead of erb, add the following to 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    



回答3:


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



回答4:


Add haml to your Gemfile:

gem "haml"

If you want to use the scaffold-functions too, add haml-rails within your development-group:

gem 'haml-rails', :group => :development

Don't forget to run:

$ bundle install



回答5:


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>



回答6:


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.




回答7:


This may be an old question but I think the answer is using haml-rails at https://github.com/indirect/haml-rails




回答8:


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.




回答9:


If you are using Pow you will need to restart it also. Ideally you are using powder (gem install powder), because then you can just run this at the terminal

$ powder restart


来源:https://stackoverflow.com/questions/99211/how-do-i-get-haml-to-work-with-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!