0

in the default index.html.erb template there didn't display id ,created_at,updated_at columns

so now i want to display them by change the template but i didn't find the meta variant,here is the part of the original index.html.erb template file code,it use a attributes to display all user defined column,but didn't show default columns,dose someone know how to add this 3 columns

<% for attribute in attributes -%>
   <div class="field">
    <%%= f.label :<%= attribute.name %> %><br />
    <%%= f.<%= attribute.field_type %> :<%= attribute.name%> %>
  </div>
<% end -%>
mlzboy
  • 14,343
  • 23
  • 76
  • 97

2 Answers2

0

If I understood what you're looking for, this should be it. I don't watch in the database but just in the model for the presence of the fields you want to show, I hope is enough... Here is the line to put before the loop, this is the one for the id.

<%%= 'Id: ' + @<%= singular_table_name %>.id.to_s unless @<%= singular_table_name %>.methods.index(:id).nil? %>

moreover I could say that there is for sure a better way to check the presence of the field instead of using the index function, and probably a better way overall, but this works.

ecoologic
  • 10,202
  • 3
  • 62
  • 66
-1

You have doubly wrapped in asp style tags:

Id: <%= object.id %>
Created at: <%= object.created_at %>
Updated at: <%= object.updated_at %>

That code should show the 3 columns as you desired, or they don't exist, see if they're in the database table.

Logan Bailey
  • 7,039
  • 7
  • 36
  • 44
  • use doubly wrapped because i didn't want to it executed,it's a scaffold template(build template for template) – mlzboy Nov 02 '10 at 08:59