Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Known Issue #175

Open
limitlessmind opened this issue Nov 2, 2022 · 1 comment
Open

Known Issue #175

limitlessmind opened this issue Nov 2, 2022 · 1 comment

Comments

@limitlessmind
Copy link

This is regarding the known issue generating image preview. In my case an image variant. It's written that this code was fixed in Rails 6. I'm using Rails 7.

When adding an unsupported file, like a PDF when it should only accept PNG or JPEG, the preview image errors out because I am using:

<% if user.image.attached? %>

In my case it makes sense because I am using the preview on the same page as the form partial and if the image is invalid, like a PDF in this case, it would not be attached.

You have that we need to use this up to Rails 5:

<% if user.image.attached? && user.image.attachment.blob.present? && user.image.attachment.blob.persisted? %>

Would only using <% if user.image.attachment.blob.persisted? %> be OK? It does work but do you know of any use cases where all three would be required?

@lapser
Copy link

lapser commented Apr 22, 2023

The error seems not completely gone away in Rails 7. I used this:

<%= 
  image = 
    if user.image.attached? && user.image.attachment.blob.present? && user.image.attachment.blob.persisted?
      user.image.variant(:thumb)
    elsif resource.reload.picture.attached?
      user.image.variant(:thumb)
    else
      user.image_default(:thumb) # custom method
    end

  image_tag(image, :class => 'mb-3')
%>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants