aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-06-08 15:52:02 +0200
committerTeddy Wing2017-06-08 15:52:02 +0200
commita2fc8b0253819fa5585a04cf9c8232a689184b29 (patch)
treea8099ce854949e259e0ed55654f5456c5615e37e /app
parentfcaf1c7e79c1f2c9e5f95fd032e363ffc84b35e1 (diff)
downloadchouette-core-a2fc8b0253819fa5585a04cf9c8232a689184b29.tar.bz2
TableBuilder: Simplify #column_header_label
Get rid of the old code that got an I18n key from the collection's model name. Instead of the longer text transformations from before, use `ActiveSupport::Inflector` methods to achieve the same result. Makes for a shorter line of code. Refs #3479
Diffstat (limited to 'app')
-rw-r--r--app/helpers/table_builder_helper.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index ee79fb4d1..2296af8c7 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -194,7 +194,6 @@ module TableBuilderHelper
pic2 = content_tag :span, '', class: "fa fa-sort-desc #{(direction == 'asc') ? 'active' : ''}"
pics = content_tag :span, pic1 + pic2, class: 'orderers'
- # This snake cases and downcases the class name. Should use the ActiveSupport method to do this
# TODO: figure out a way to maybe explicitise the dynamicness of getting the model type from the `collection`.
# TODO: rename `pics` to something like `icons` or arrow icons or some such
@@ -203,7 +202,9 @@ module TableBuilderHelper
end
def column_header_label(model, field)
- model_underscored = model.to_s.gsub('Chouette::', '').scan(/[A-Z][a-z]+/).join('_').downcase
- I18n.t("activerecord.attributes.#{model_underscored}.#{field}")
+ # Transform `Chouette::Line` into "line"
+ model_key = model.to_s.demodulize.underscore
+
+ I18n.t("activerecord.attributes.#{model_key}.#{field}")
end
end