I created a virtual (fickle) model in Rails 3 (see below)
Now I need to apply translations to the model, but the standard translation positions do not work. eg.
en: activerecord: attributes: media_upload: title: "My Title" 
I know that I can apply this directly to a label with an optional string parameter, for example. f.label :title, t('activerecord.attributes.media_upload') , but this does not work for error messages as a result of checks. Similarly, I could add a key to the translation file for the label helper, as suggested in Localize a nested virtual attribute in Rails , but this also does not work for validation.
 helpers: label: media_upload: title: "My Title" 
Besides overriding all relevant validation statements, is there another way to localize attributes in mutable models?
Below is a sample model,
 class MediaUpload include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_accessor :media_file, :title validates_presence_of :media_file validates_presence_of :title def initialize(attributes = {}) unless attributes.nil? attributes.each do |name, value| send("#{name}=", value) end end end def persisted? false end end 
source share