All threads / Why is this image_tag not working?
Ask A Question


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 %>
    <%= image_tag {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?

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

Join the discussion

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

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

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

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.