Ask A Question

Notifications

You’re not receiving notifications from this thread.

Why is this image_tag not working?

Christopher Guller asked in Rails

If I try and put this code:

  <% if notification.actor.avatar.attached? %>
    <%= image_tag notification.actor.avatar.variant(combine_options: {resize: '150x150^', extent: '150x150', gravity: 'Center'}), class:"rounded-circle" %>
  <% else %>
    <%= image_tag("fallback/default-avatar-3.png", class:"rounded-circle") %>
  <% end %>

into one of my notification layout pages I only get:

Can't resolve image into URL: undefined method `to_model' for #<ActiveStorage::Variant:0x00007fdf8499d7a0>
Did you mean?  to_yaml

This works on every other page for me other than the ones for notifications. This also isn't the only thing that doesn't work. Any active storage image will get the same error even if it isn't the same tag. I have no idea what is causing this to happen and I don't really have a good idea of how to fix it. Any way of fixing this error?

Reply

I've just hit this same issue. Did you ever solve it?

Reply

I face a similar problem but I realized that I had previously stored data in the database without a file and it was generating that error. So I deleted the file and save a new record with an image and that was it.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.