0
0

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 1 year has passed since last update.

プロフィール画像の大きさを指定して、丸くする

Posted at

調べていてなかなか出てこなかったので、少し時間かかりましたが備忘録までに。

やりたいこと

プロフィールのアバター画像の大きさを指定して、形を丸くしたい。

.html
<% if @user.avatar? %>
  <%= image_tag @user.avatar.url %>
<% else %>
  <%= image_tag ("default-avatar.png") %>
<% end %>

このままだとアバター画像の大きさがavatar/uploader.rbで指定されている値で表示されてしまう。
また、画像が四角なのでアイコンっぽくない。

.html
<% if @user.avatar? %>
  <%= image_tag @user.avatar.url, class: "rounded-circle", size: "150x150" %>
<% else %>
  <%= image_tag ("default-avatar.png"), class: "rounded-circle", size: "150x150" %>
<% end %>

viewでclass: "rounded-circle"size: "150x150"を指定してあげればOK。

これだけでもかわいいアイコンになります。

参考:https://qiita.com/moru0606/items/a7a581bcf2069389af4e

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?