Programming Journal

学習したことの整理用です。

image_tagの使い方

railsにおけるimage_tagの使い方メモ


アセットパイプライン - Railsガイド


①画像が、app/assets/image 以下にあるとき…
画像名でOK

<%= image_tag 'sample.jpg' %>

②画像が、public/以下のとき…
publicディレクトリからの相対パスを指定する。

<%= image_tag '/sample.jpg' %>
クラスやサイズを指定することも可能

※sizeは X(エックス)の小文字 横x縦

<%= image_tag 'sample.jpg',  class:'rounded-circle mr15',  size:'40x40' %>