Philip Hallstrom wrote:
>>    <%= "<td>#{h i}</td>\n" %>
>>  <% end %>
>>  <%= "</tr>\n" %>
>> <% end %>
> 
> @stories.attributes....
> 
> http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002348
> 
> -philip

Great thanks.

So I have come up something like this:

the row == 1 check is to print the header

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

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

  <%= "<tr>" %>
  <% s.attributes.each do |i| %>
  <% p i %>
  <%= "<td>#{h i[1]}</td>\n" %>
  <% end %>
  <%= "</tr>\n" %>

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

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


it might be better if the internal loop counter can be used for looping 
@all_stories so that now extra local variable "row" is needed.

also, the use of i[0], i[1] seems a little less structured than if 
i.attr_name, i.attr_value can be used.

the row == 1 situation also seems like somewhat not adhering to DRY.

-- 
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