All threads / Why is this image_tag not working?

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?

Join the discussion

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

Join 35,699+ 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.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.