Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
308 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...