问题
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?
回答1:
This gem will do the trick http://github.com/indirect/haml-rails
回答2:
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 :)
回答3:
This gem here might be useful. I don't think there is any way to do this outside of a plugin/gem. (disclaimer: I haven't tried this myself, but came across it when I was researching the same thing)
来源:https://stackoverflow.com/questions/2173789/how-to-generate-haml-views-instead-of-erb