Re: How to create a two dimensional table

Colin Law
2009-01-15T09:14:11Z

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
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
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">
>
>
> <% for s in @service_code %>
> <%=s.col02 %>
> <% end %>
>
>
> <% for h in @hospital_code %>
>
> <%=h.col01 %>
>
> <% end %>
>
>
> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com