{"action":"opened","issue":{"url":"https://api.github.com/repos/globalize/globalize/issues/456","labels_url":"https://api.github.com/repos/globalize/globalize/issues/456/labels{/name}","comments_url":"https://api.github.com/repos/globalize/globalize/issues/456/comments","events_url":"https://api.github.com/repos/globalize/globalize/issues/456/events","html_url":"https://github.com/globalize/globalize/issues/456","id":98231525,"number":456,"title":"Globalize breaks CarrierWave uploader","user":{"login":"partydrone","id":57892,"avatar_url":"https://avatars.githubusercontent.com/u/57892?v=3","gravatar_id":"","url":"https://api.github.com/users/partydrone","html_url":"https://github.com/partydrone","followers_url":"https://api.github.com/users/partydrone/followers","following_url":"https://api.github.com/users/partydrone/following{/other_user}","gists_url":"https://api.github.com/users/partydrone/gists{/gist_id}","starred_url":"https://api.github.com/users/partydrone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/partydrone/subscriptions","organizations_url":"https://api.github.com/users/partydrone/orgs","repos_url":"https://api.github.com/users/partydrone/repos","events_url":"https://api.github.com/users/partydrone/events{/privacy}","received_events_url":"https://api.github.com/users/partydrone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-30T18:26:16Z","updated_at":"2015-07-30T18:26:16Z","closed_at":null,"body":"## Background\r\n\r\nHere are the gem versions I'm using:\r\n\r\n```ruby\r\ngem \"rails\", \"4.2.3\"\r\ngem \"carrierwave\" # 0.10.0\r\ngem \"globalize\" # 5.0.1\r\n```\r\n\r\nMy model:\r\n\r\n```ruby\r\nclass Download < ActiveRecord::Base\r\n  belongs_to :download_type\r\n  has_and_belongs_to_many :products\r\n\r\n  translates :title, :part_number, :file\r\n\r\n  mount_uploader :file, DownloadFileUploader\r\n\r\n  validates :title, presence: true\r\n\r\n  def to_param\r\n    \"#{id}-#{title.parameterize}\"\r\n  end\r\nend\r\n```\r\n\r\nAnd my uploader:\r\n\r\n```ruby\r\nclass DownloadFileUploader < CarrierWave::Uploader::Base\r\n  def store_dir\r\n    \"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}\"\r\n  end\r\n\r\n  def filename\r\n    \"#{model.title.parameterize(sep = '_')}-#{I18n.locale}-#{Digest::SHA1.hexdigest file.read}#{File.extname(original_filename)}\" if original_filename\r\n  end\r\nend\r\n```\r\n\r\n## The Issue\r\n\r\nIn my view, I want to list a Download and all of the current translations for that download, but it doesn't change the filename for each locale. In the Rails console:\r\n\r\n```\r\n> I18n.locale\r\n=> :en\r\n\r\n> download = Download.find(481)\r\n=> #<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>\r\n\r\n> download.translations.count\r\n=> 8\r\n\r\n> download.translated_locales\r\n=> [:de, :en, :es, :fr, :it, :pt, :ru, :\"zh-CN\"]\r\n\r\n> download.file.class\r\n=> DownloadFileUploader\r\n\r\n> download.file.url\r\n=> \"/uploads/download/file/481/smartsensor_hd_user_quick-reference_guide-20150116154913-en.pdf\"\r\n\r\n> download.title\r\n=> \"SmartSensor HD Quick-reference Guide (User)\"\r\n\r\n> download.part_number\r\n=> \"WX-500-0171\"\r\n```\r\n\r\nAnd when the locale changes:\r\n\r\n```\r\n> I18n.locale = :de\r\n=> :de\r\n\r\n> download\r\n=> #<Download id: 481, title: \"SmartSensor HD Kurzanleitung\", part_number: \"WX-502-0006\", download_type_id: 3, created_at: \"2015-01-16 22:49:13\", updated_at: \"2015-04-20 16:59:25\", file: \"kurzanleitung-20150119113123-de.pdf\", download_updated_at: nil>\r\n\r\n> download.file.class\r\n=> DownloadFileUploader\r\n\r\n> download.file.url\r\n=> \"/uploads/download/file/481/smartsensor_hd_user_quick-reference_guide-20150116154913-en.pdf\"\r\n\r\n> download.title\r\n=> \"SmartSensor HD Kurzanleitung\"\r\n\r\n> download.part_number\r\n=> \"WX-502-0006\"\r\n```\r\n\r\nNotice `download.file.url` doesn't change, even though the `file` attribute of the model has updated. If I try and access the translation directly:\r\n\r\n```\r\n> I18n.locale = :de\r\n=> :de\r\n\r\n> download.translation.file.class\r\n=> String\r\n```\r\n\r\n## Attempted Solution\r\n\r\nIf I change how the uploader is mounted in my model:\r\n\r\n```ruby\r\nTranslation.mount_uploader :file, DownloadFileUploader\r\n```\r\n\r\nExisting translations list correctly—including the file, but new uploads break. What gets stored in the database is this:\r\n\r\n```\r\n /uploads/download/translation/file/401/%23%3CActionDispatch%3A%3AHttp%3A%3AUploadedFile%3A0x007f9c12e6fe00%3E\r\n```\r\n\r\nAnd no file is uploaded.\r\n\r\nNotice that it inserts `/translation` into the path, which I can fix in the uploader,  the `:id` is wrong (401 instead of 481), and the filename isn't actually a filename—it looks like a URL-escaped string representation of a Ruby object.\r\n\r\nIf I move `translates :title, :part_number, :file` below `mount_uploader :file, DownloadFileUploader` in my model, Globalize overrides the mounted uploader and that column is returned as class `String` instead of `DownloadFileUploader`."}}