forest wrote:
> I am stuck trying to figure out how to take an array of data and
> dynamically build a 3x3 html table from it without standard for loops.
>
> Here is the code in JavaScript:
*snip*
> Can someone point me in the right direction for how to do this. I found
> each_index but still was at a loss.
I tried 'ri Enumerator' to learn more, but it just comes back talking
about SyncEnumerator, which is something else. (Trying the lowercase
'enumerator' didn't work at all.)
Yes, enumerator is part of the standard library. Go to http://ruby-doc.org/stdlib/ and find enumerator (right after English) in the left frame if ri isn't helping.
Tim
···
On Mar 16, 2006, at 1:10 PM, Matthew Moss wrote:
require "enumerator"
Is this standard library?
I tried 'ri Enumerator' to learn more, but it just comes back talking
about SyncEnumerator, which is something else. (Trying the lowercase
'enumerator' didn't work at all.)
I wrote next function (maybe need to be rewritten to method for Array
cass) -
def array_to_table(arr, width)
data = "<table>"
arr.each_slice(width) do |row|
data << "<tr>"
row.each do |elem|
data << ("<td>" + yield(elem) + "</td>")
end
data << "</tr>"
end
data << "</table>"
end
Using -
<%= array_to_table(User.find(:all), 3) {|user| "<div
id='user_div'>#{user.name}</div>"} %>