How to generate Haml views instead of erb

喜夏-厌秋 提交于 2019-12-03 04:14:03

问题


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

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