3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

railsでslimテンプレートエンジンを使う

3
Last updated at Posted at 2014-10-29

手順

  • slim-railsのインストール
  • erbファイルをslimに変換する

参考URL

http://stackoverflow.com/questions/19057030/how-to-make-rails-render-slim-templates-instead-of-erb-templates
http://www.mocchiblog.com/?p=14680

slimのインストール

GemFile
gem 'slim-rails'
config/application.rb
class Application < Rails::Application
  #... 省略

  config.generators do |g|
    g.template_engine :slim
  end
end

erbをslimに変換するコマンド

html2slimインストールコマンド
## これでerb2slimコマンドを入手
$ gem install html2slim

## .erbファイルを.slimファイルに変換
$ for i in app/views/**/*.erb; do erb2slim $i ${i%erb}slim && rm $i; done

テンプレートの優先順位は

erb > slim らしい。
なので既存のerbファイルが残っているとslim側は動作しないので注意が必要

3
3
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?