How do I get Haml to work with Rails?

后端 未结 10 1093
一向
一向 2020-12-07 13:15

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

相关标签:
10条回答
  • 2020-12-07 13:27

    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>
    
    0 讨论(0)
  • 2020-12-07 13:30

    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.

    0 讨论(0)
  • 2020-12-07 13:30

    make sure to add haml gem into your Gemfile

    0 讨论(0)
  • 2020-12-07 13:31

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

    0 讨论(0)
  • 2020-12-07 13:39

    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    
    
    0 讨论(0)
  • 2020-12-07 13:40

    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
    
    0 讨论(0)
提交回复
热议问题