Jay
Jay

Reputation: 322

Specify different style of each table

I'm generating tables based on some fields from database and I need to specify different style for each table. How could specify different style for each table.

This is my code

<table width="100%">
  <% @content_data['personnel_cv_data_types'].each do |personnel_cv_data_type| %>
 <tr width="100%">
 <td>
  <fieldset>
  <legend>
    <table style="font-size:13px;"width="100%" class="personnel_cvdata_view_table_first_row">
      <tr>
        <td>
          <%= @content_data['lable_title_'+personnel_cv_data_type] %>
        </td>
        <td>
          <a onClick="add_new_entry('<%= personnel_cv_data_type %>')">Add&nbsp;<%= @content_data['lable_add_'+personnel_cv_data_type] %></a>
        </td>
      </tr>
    </table>
  </legend>

Here each table takes the same style as personnel_cvdata_view_table_first_row, How could generate tables with different style class for example

  class="personnel_cvdata_view_table_first_row_1"
  class=""ersonnel_cvdata_view_table_first_row_2

and so on an and i can write separate style for each table

Upvotes: 0

Views: 63

Answers (3)

Kris Robison
Kris Robison

Reputation: 698

You could add a class based on some unique identifier, possibly even the string personnel_cv_data_type itself if it is unique.

<table style="font-size:13px;"width="100%" class="#{personnel_cv_data_type}">
  <tr>
    <td>
      <%= @content_data['lable_title_'+personnel_cv_data_type] %>
    </td>
    <td>
      <a onClick="add_new_entry('<%= personnel_cv_data_type %>')">Add&nbsp;<%= @content_data['lable_add_'+personnel_cv_data_type] %></a>
    </td>
  </tr>
</table>

I don't know specifically what you want to make different about each style, but if the list is determinate, you could set up styles for each of the above types.

Upvotes: 1

davidb
davidb

Reputation: 8954

Instead of

<% @content_data['personnel_cv_data_types'].each do |personnel_cv_data_type| %>

Use

<% @content_data['personnel_cv_data_types'].each.with_index do |personnel_cv_data_type, counter| %>

And then you can create your tables like this

<table style="font-size:13px;"width="100%" class="personnel_cvdata_view_table_first_row_<%= counter %>">

Upvotes: 2

apneadiving
apneadiving

Reputation: 115521

Something like this seems to fit your needs:

<% @content_data['personnel_cv_data_types'].each_with_index do |personnel_cv_data_type, index| %>
...
<table style="font-size:13px;"width="100%" class="personnel_cvdata_view_table_first_row_<%= index + 1 %>">

Upvotes: 3

Related Questions