I have a table of data in which I go through each user attribute, and display it in a table. This seems like a lot of repetition, even though the words are not the same, the process for each attribute is. Is there a way to automatically make a table row with a header of attribute.titleize and a data cell of user.attribute?
%table
%tr
%th First Name
%td= @user.first_name
%tr
%th Middle Name
%td= @user.middle_name
%tr
%th Last Name
%td= @user.last_name
You could make an
_attributepartial to render a single row of the table:If you don’t want to render every attribute of
User, create a method on the model that returns the attributes you do want and call that instead of@user.attributes: