LoginSignup
4
0

More than 1 year has passed since last update.

【Rails】Slim-rails

Last updated at Posted at 2021-10-05

##概要
Ruby製のHTMLテンプレートエンジンであるslimを使えるようにするGem。Slimはコーディングを速くするだけでなく、コードを読み込むスピードも速くなる。

##手順

###インストール

Gemfile

gem 'slim-rails'

bundle installh後、viewファイルの拡張子を「html.slim」に変更。

###実装例

html.erbの時

<% @posts.each do |a| %>
 <p><%= a.title %></p>
<% end %>

slim-rails適用後

- @posts.each do |a|
  p = a.title

###ポイント

  • <% %> というruby記法の使用宣言が、「-」となっていること
  • <%= %> というruby記法の使用宣言 + 出力が、「=」となっていること
  • 閉じタグが不要なこと(段落によって閉じタグを判断する)
  • <p> ~~ </p>という記法が、「p」となっていること(HTMLタグの<> や、閉じタグは不要)
4
0
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
4
0