LoginSignup
20
27

More than 5 years have passed since last update.

rails erbをhamlへ変換

Last updated at Posted at 2018-03-10

railsアプリのテンプレートを、erbでなくhamlで作成しようと思ったので、erbからhamlへの変換手順をまとめてみました。

Gemfileに、次のgemを追加
gaml-rails・・・hamlを使うためのgem
erb2haml・・・erbをhamlに変換するgem

Gemfile
gem 'haml-rails'
gem 'erb2haml'
ターミナル
bundle install
ターミナル
rake haml:replace_erbs

を実行すると
hamlへ変換して、erbを削除してくれる。

ターミナル
Looking for ERB files to convert to Haml...
Converting: app/views/layouts/application.html.erb... Done!
Removing: app/views/layouts/application.html.erb... Removed!
Converting: app/views/layouts/mailer.html.erb... Done!
Removing: app/views/layouts/mailer.html.erb... Removed!
Converting: app/views/layouts/mailer.text.erb... Done!
Removing: app/views/layouts/mailer.text.erb... Removed!

きちんと、hamlへ変換されている。

スクリーンショット 2018-03-10 18.51.28.png

20
27
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
27