Making label of attributes more maintainable in view
That was a stormy day when I have to update all of label of an attribute from Created At
to Register At
(column User.created_at). It was not easy to find and replace
because other models also use that label. So this is what ....
def self.human_attribute_name(attribute, options = {}) key = :"#{i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}" I18n.translate(key) end
//concern module ReadableAttributes extend ActiveSupport::Concern included do column_names.each do |name| define_singleton_method "_#{name}_" do |*args| human_attribute_name(name.to_sym, default: args) end end end end