cthulhu666 / easy_table

HTML tables made easy (in Rails)
MIT License
26 stars 6 forks source link

Fallback to Class.human_attribute_name for table header labels #12

Closed MikeRogers0 closed 4 years ago

MikeRogers0 commented 6 years ago

Right now I'm currently using easy_table like this:

<%= table_for(collection, class: 'table') do |t| %>
  <% [:name, :email, :other_field].each do |field| %>
    <% t.column field, MyModel.human_attribute_name(field) %>
  <% end %>
<% end %>

Which feels a little messy.

Would it be ok if I opened a PR that used the human_attribute_name method (if it is defined on a class) as a fallback for if an I18n isn't defined under the en.easy_table.* namespace?

For example, to find the column name for the name field, it would lookup the i18n keys in this order:

en.easy_table.my_model_controller.name
en.activerecord.attributes.my_model.name
en.attributes.name

What do you think?

cthulhu666 commented 6 years ago

Hi @MikeRogers0 yes, by all means, please open a PR!