Jian Lin wrote:

> yes, column_names gave a better order:
> 
> C:\Software Projects\ror\shov10>ruby script/console
> Loading development environment (Rails 2.3.5)
>>> Story.column_names
> => ["id", "name", "link", "created_at", "updated_at"]


so the code can be:

<style>
  table { border-collapse: collapse }
  td, th { border: 1px solid #ccc; padding: 0.33em }
  th { background: #eee }
  tr:hover { background: #eee }
</style>

<%= "<p><p><p><table>\n" %>
<% row = 1 %>
<% @all_stories.each do |s| %>
  <% if row == 1 %>
    <%= "<tr>" %>
    <% @column_names.each do |i| %>
    <%= "<th>#{h i}</th>\n" %>
    <% end %>
    <%= "</tr>\n" %>
  <% end %>

  <%= "<tr>" %>
  <% @column_names.each do |k| %>
  <%= "<td>#{h s.attributes[k]}</td>\n" %>
  <% end %>
  <%= "</tr>\n" %>

  <% row += 1 %>
<% end %>

<%= "</table>\n" %>

I found that either

  s.attributes[k]

or

  s.send(k)

can be used.  the second one is to invoke the getter method and it gave 
a slight different version of the datetime object.

kind of interesting that in script/console, i get

>> s.created_at
=> Thu, 13 May 2010 09:22:50 UTC +00:00

>> s.send("created_at")
=> Thu, 13 May 2010 09:22:50 UTC +00:00

but on the webpage, i get a different format:

2010-05-13 09:23:58 UTC

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to