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

mount_translated_uploader always populates with string of "Uploader" object #8

Open
raikun85 opened this issue May 13, 2019 · 1 comment

Comments

@raikun85
Copy link

raikun85 commented May 13, 2019

Hi there,

I've followed the instructions, and boiled down, the code in use is:

class Bob < ActiveRecord::Base
  translates :message, :button_text, :message_footer, :image_landing_url, :square_image
  extend CarrierwaveGlobalize
  mount_translated_uploader :square_image, SquareImageUploader
end

Uploader:

class SquareImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  storage :file
  
  process resize_and_crop: 800

  private

   def resize_and_crop(size)
    manipulate! do |image|
      if image[:width] < image[:height]
        remove = ((image[:height] - image[:width])/2).round
        image.shave("0x#{remove}")
      elsif image[:width] > image[:height]
        remove = ((image[:width] - image[:height])/2).round
        image.shave("#{remove}x0")
      end
      image.resize("#{size}x#{size}")
      image
    end
  end

end

The problem happens when the resulting form (relevant snippet):

= f.fields_for :translations, bob_translations do |ft|
        .col-md-4
          .panel.panel-default
            .panel-heading
              = translation_locale_name(ft.object.locale)
            .panel-body
              = ft.hidden_field :locale
              = ft.file_field :square_image

The form has multipart also set.

But all of the values posted to the fields being saved as string representations of the upload file object, like "#ActionDispatch::Http::UploadedFile:0x00007fd5d44c99e0" - which is not useful.

Any hits for where this might not be working?

@foxtacles
Copy link

foxtacles commented Jul 22, 2021

For anyone who comes across this: I found the same issue when integrating ActiveAdmin with Globalize + Carrierwave. It boiled down to the fact that assignment to the nested translations attribute won't work because there's no mounted uploader on the Translation class, and the file object will subsequently be cast to a string. I've changed this gem like this:

https://github.com/foxtacles/carrierwave_globalize/tree/fix-carrierwave-globalize

and it works fine for me now.

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