Project

General

Profile

Feature #22383

Updated by Toshi MARUYAMA about 8 years ago

For now, in _10-patches.rb_ we have a redefinition of method _human_attribute_name_. But default (plain without hierarchy) Redmine style of transliterations are not convinient for some reasons, especially in big projects. So, my proposal is follows: enable ActiveRecord behaviour for finding transliterations path and add in list of search paths custom one from Redmine. Here is a worked snippet of code: 
 <pre><code class="ruby"> <pre> 
 def self.human_attribute_name(attr, options = {}) 
   prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '') 

   redmine_default = 
       [ 
           :"field_#{name.underscore.gsub('/', '_')}_#{prepared_attr}", 
           :"field_#{prepared_attr}" 
       ] 

   if options[:default].present? 
     options[:default] = [options[:default]] unless options[:default].is_a? Array 
     options[:default].unshift redmine_default 
   else 
     options[:default] = redmine_default 
   end 

   super 
 end 
 </code></pre> </pre> 

 In this case we obtain follows chain of search paths: 
 # default AR paths (for example: activerecord.attributes.model_name.field_name) 
 # default Redmine paths (for example: field_content) 
 # user specified paths (specified in _:default_ key from _options_ attribute) 
 # @attribute.humanize@ (from default _human_attribute_name_ from ActiveModel) 

Back