4

I am using globalize gem for some locales.
I have added a field in translation that saves different image for different locales.
Rails admin globalize field only supports for string and it doesn't provide any option to upload a file.
How can I achieve this option?

Florian
  • 24,425
  • 4
  • 49
  • 80
Jaswinder
  • 1,455
  • 14
  • 27

1 Answers1

2

For uploads you must use some processing method to allow storing your file under a simple string field.
Usually you would use some solution for file uploads, like Carrierwave and in this specific case you would also have to use Globalize to manage Carrierwave translated fields, after you setup both gems in you gemfile and ran bundle install you would have to setup uploaders for each file upload rule you would like to enforce i.e.:

rails generate uploader Avatar

Then, initialize the uploader on your model file app/models/assets.rb on the string column/field like the code below:

class Asset < ApplicationRecord
  extend CarrierwaveGlobalize
  # Globalize translated attributes
  translates :avatar
  mount_translated_uploader :avatar, AvatarUploader
 end
asdfg_rocks
  • 117
  • 1
  • 11
ErvalhouS
  • 4,178
  • 1
  • 22
  • 38