Issues with Globalize and CarrierWave uploads in Rails 4.2 app -


i have issues translated files in rails 4.2 app.

background

here gem versions i'm using:

gem "rails", "4.2.1" gem "carrierwave" # 0.10.0 gem "globalize" # 5.0.1 

and model:

class download < activerecord::base   belongs_to :download_type   has_and_belongs_to_many :products    translates :title, :part_number, :file    mount_uploader :file, downloadfileuploader    validates :title, presence: true    def to_param     "#{id}-#{title.parameterize}"   end end 

the issues

  1. in view, want list download , of current translations download, current locale data each translation. in rails console:

    > i18n.locale => :en  > download = download.find(481) => #<download id: 481, title: "smartsensor hd quick-reference guide (user)", part_number: "wx-500-0171", download_type_id: 3, created_at: "2015-01-16 22:49:13", updated_at: "2015-04-20 16:59:25", file: "smartsensor_hd_user_quick-reference_guide-20150116...", download_updated_at: nil>  > download.translations.count => 8  > download.translated_locales => [:de, :en, :es, :fr, :it, :pt, :ru, :"zh-cn"]  > download.file.class => downloadfileuploader  > download.file.url => "/uploads/download/file/481/smartsensor_hd_user_quick-reference_guide-20150116154913-en.pdf"  > download.title => "smartsensor hd quick-reference guide (user)"  > download.part_number => "wx-500-0171" 

    and when locale changes:

    > i18n.locale = :de => :de  > download.file.class => downloadfileuploader  > download.file.url => "/uploads/download/file/481/smartsensor_hd_user_quick-reference_guide-20150116154913-en.pdf"  > download.title => "smartsensor hd kurzanleitung"  > download.part_number => "wx-502-0006" 

    if try , access translation directly:

    > i18n.locale = :de => :de  > download.translation.file.class => string 
  2. if change how uploader mounted in model:

    translation.mount_uploader :file, downloadfileuploader 

    existing translations list correctly—including file, can no longer upload files. gets stored in database this:

     /uploads/download/translation/file/401/%23%3cactiondispatch%3a%3ahttp%3a%3auploadedfile%3a0x007f9c12e6fe00%3e 

    notice inserts /translation path, can fix in uploader, filename isn't file.

  3. if move translates :title, :part_number, :file below mount_uploader :file, downloadfileuploader in model, globalize overrides mounted uploader , column returned class string when accessing it.

the cry help

help! 😮

i wrote simple gem https://github.com/dalpo/carrierwave_globalize. should allow use globalize , carrierwave together.

you have extend model carrierwaveglobalize module , use mount_translated_uploader class method mount carrierwave uploader instead of mount_uploader mehtod.

follow instructions in readme more info.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -