I have a model Post
with
has_one_attached :cover
Having an attachment is not necessary. So, is there any way that I can add a default attachment even if the user doesn't provide one.
So, when the post is displayed there is a cover image I can show.
<% if @post.cover.attached? %>
<%= image_tag(@post.cover, class: 'card-img-top img-fluid') %>
<% else %>
<div class="text-align-center img-place-holder">
No Image Added Please add One
</div>
<% end %>
Is there any way other than checking if something is attached and trying to resolve it like this.
So, I could use,
<%= image_tag(@post.cover, class: 'card-img-top img-fluid') %>
directly without any if condition
thank you
image_pack_tag
rather than animage_tag
– Idolah