I'm building an app with Rails 2.3.4 and using
script/generate controller home index
to generate a controller and home page. I've got Haml installed. I get an erb file:
app/views/home/index.html.erb
but I'd prefer to have a Haml file generated instead, like:
app/views/home/index.html.haml
I recall Merb would generate .haml views instead of .erb if a haml gem was detected. Is this not available in Rails 2.3.4? I tried
script/generate controller home index --haml
but a "--haml" option is invalid.
Of course I can manually change my erb files to haml files but I'd rather have the generator do the work. Call me lazy. Suggestions?
ERB has a simple syntax for mixing HTML and Ruby commands, but it can be somewhat verbose. Haml is a very popular alternative which has a condensed syntax for expressing HTML.
In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong , %div , %body , %html ; any tag you want. Then, after the name of the tag is = , which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.
Haml (HTML Abstraction Markup Language) Haml is a markup language that's used to cleanly and simply describe the HTML of any web document, without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ERB, and ASP.
This gem will do the trick http://github.com/indirect/haml-rails
Waht actually worked for me, but in rails 3.1 is this wiki here: https://github.com/plataformatec/devise/wiki/How-To:-Create-Haml-and-Slim-Views :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With