LoginSignup
20
20

More than 5 years have passed since last update.

Railsでhamlを導入する!

Last updated at Posted at 2019-01-18

何かと便利なhaml。
今回はRailsで取り入れてみる。

Gem導入

Gemfile
  gem 'haml-rails'
ターミナル
bundle install

すると、、、

application.html.haml
!!!
%html
  %head
    %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
    %title ChatSpace
    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true
    = javascript_include_tag 'application', 'data-turbolinks-track' => true
    = csrf_meta_tags
  %body
    = render partial: 'layouts/flash'
    = yield
mailer.html.erb
!!!
 %html
   %head
     %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
     :css
       /* Email styles need to be inline */
   %body
     = yield
mailer.text.erb
= yield

の3つのファイルが出現。設定ファイルだと思って大丈夫です。

拡張子がerbのファイルをhamlに変換する

ターミナル
$ rails haml:erb2haml

上記のコマンドを打てば後は自動的に拡張子をhamlに変えてくれます。

終了!

20
20
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
20