dalpo / carrierwave_globalize

Use Globalize to manage Carrierwave translated fields :gem:
MIT License
10 stars 10 forks source link

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

Open raikun85 opened 5 years ago

raikun85 commented 5 years ago

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 "#" - which is not useful.

Any hits for where this might not be working?

foxtacles commented 3 years ago

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.