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

Conditional processing of versions behaves oddly #2720

Open
clickworkorange opened this issue Jan 23, 2024 · 0 comments
Open

Conditional processing of versions behaves oddly #2720

clickworkorange opened this issue Jan 23, 2024 · 0 comments

Comments

@clickworkorange
Copy link
Contributor

clickworkorange commented Jan 23, 2024

I have a model Image which has a role:string attribute and mounts :image_file uploader. I want to check the role attribute in my ImageFileUploader class, and produce a different set of versions depending on its value:

  version :thumb do
    # always produce this
    process resize_to_fit: [240, 240]
  end

  version :normal, if: :not_banner? do
    # only produce this if role != "banner"
    process resize_to_fit: [1200, 1200]
  end

  version :banner, if: :is_banner? do
    # only produce this if role == "banner"
    process resize_to_fill: [1200, 600]
  end

  def not_banner?(image)
    model.role != "banner"
  end

  def is_banner?(image)
    model.role == "banner"
  end

If I upload an image and set the role to "banner" only the :thumb gets created. For any other role the :normal version is produced and the :banner version is skipped - just as expected. Why doesn't the :is_banner? condition work here?

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

1 participant