I would like to display data in Columns rather than Rows in my web page.
What is the most efficient way to do this using Ruby on Rails?
Many thanks for your help!
See Question&Answers more detail:osI would like to display data in Columns rather than Rows in my web page.
What is the most efficient way to do this using Ruby on Rails?
Many thanks for your help!
See Question&Answers more detail:osSimple solution would be to 'rotate' the information, using an array. Like this (pseudo) code (cannot check if atm)
Controller code:
@stuffs = Stuff.find(:all)
@rotated = []
@rotated[0] = [] # Stuff column0
@rotated[1] = [] # Stuff column1
# etc
index = 0
# Now put the stuff in an array for easy(ier) access
@stuffs.each do |stuff|
@rotated[0][index] = stuff.detail0
@rotated[1][index] = stuff.detail1
index += 1
end
In your View you'd need something like this:
<table>
Table head here!
<% 2.times do |row| %> # Build table (we have 2 stuff details, hence the 2 here)
<tr>
<% index.times do |column| %>
<td><%= @rotated[row][column] %></td>
<% end %>
</tr>
<% end %>
<table>
There are of course better solution, but this seems the most simple/general to me. To rotate some data from some Model.
Like others said with more information we can help you probably much better!