I am trying to retrieve simple statistics for database completeness. I would like to know how many fields out of total number of fields have been filled in per record, considering that fields not entered have “null” in them or “”.
Here is how the existing code looks like :
<% if @products %>
<% total_attribute_count = Product.columns.size %>
<% @products do |product| -%>
<p><%= platform.name %></p>
<p>I would like to have here a number of attributes filled in, so I could calculate a percentage based on total_attribute_count</p>
<% end -%>
<% end %>
You can try following
Ref
column_names