I would suggest building a two dimensional array @values[][] in the
controller, iterating through the records and filling in the cells.
This can then be displayed as rows and columns in the view. I suspect
there may be more elegant ways to do this in Ruby however.
Colin

On Jan 14, 10:12 am, Valentino Lun <[email protected]>
wrote:
> Dear all
>
> I have the following data in atableand I want to create a
> 2-dimensionaltableto display it.
>
> Table: services
> col01   col02   col03
> AH   AS   1
> AH   CS   2
> AH   MS   3
> BH   BS   1
> BH   CS   1
> BH   MS   1
> CH   IS   1
> CH   BS   2
> CH   MS   1
> DH   CS   1
> DH   MS   1
>
> I want to have this present on web
>
>      AS  BS  CS  IS  MS
> AH    1       2       3
> BH        1   1       1
> CH        2       1   1
> DH            1       1
>
> I only have the idea to display the column and row title. Can anyone
> give me some idea how to generate this dynamically?. Thanks
>
> controllers/dashboard_controller.rb
>   def main
>     @hospital_code = Service.find_by_sql("select distinct hospital_code
> from services")
>     @service_code =  Service.find_by_sql("select distinct service_code
> from services")
>   end
>
> views/dashboard/main.html.erb
> <tableborder="1">
> <tr>
>   <th></th>
> <% for s in @service_code %>
>   <th><%=s.col02 %></th>
> <% end %>
> </tr>
>
> <% for h in @hospital_code %>
>   <tr>
>   <td><%=h.col01 %></td>
>   </tr>
> <% end %>
> </table>
>
> Many thanks
> Valentino
> --
> Posted viahttp://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