我的 Rails 4.2 应用程序中的翻译文件有问题。
背景
这是我正在使用的 gem 版本:
gem "rails", "4.2.1"
gem "carrierwave" # 0.10.0
gem "globalize" # 5.0.1
我的模型:
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
问题
在我看来,我想列出下载和该下载的所有当前翻译,但我得到的只是每个翻译的当前语言环境数据。在 Rails 控制台中:
> 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"
当语言环境发生变化时:
> 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"
如果我尝试直接访问翻译:
> I18n.locale = :de => :de > download.translation.file.class => String
如果我更改上传器在我的模型中的安装方式:
Translation.mount_uploader :file, DownloadFileUploader
现有翻译列表正确 - 包括文件,但我无法再上传文件。存储在数据库中的是:
/uploads/download/translation/file/401/%23%3CActionDispatch%3A%3AHttp%3A%3AUploadedFile%3A0x007f9c12e6fe00%3E
请注意,它插入
/translation
到路径中,我可以在上传器中修复它,但文件名实际上不是文件。如果我在我的模型中移动
translates :title, :part_number, :file
到下方 ,Globalize 会覆盖已安装的上传器,并且在访问它时mount_uploader :file, DownloadFileUploader
该列将作为类返回。String
呼救声
帮助!