Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Yes I copy & pasted this code from stackoverflow.com. If I find the answers here more useful I may switch over or use both. Thanks in advance for any help you may bestow me with!

XML
What code do I need to add to make this **#1 table**:

![enter image description here][1] - Click at Bottom


look like this **#2 table**:
![enter image description here][2] - Click at Bottom

Every time the user inputs a new _form containing name | metric | result | date there should be a new row added for the date and a new column added for the name & metric.

If you decide to take up this crusade, thank you! You shall be blessed with **70** virgins.


**index**

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

    <!-- Default bootstrap panel contents -->
    <div id="values" class="panel panel-default">

      <div class="panel-heading"><h4><b>AVERAGE</b></h4></div>

      <!-- Table -->
    <table>
      <thead>
        <% @averaged_quantifieds.each do |averaged| %>
          <% if averaged.user == current_user %>
          <tr>
            <th class="value">
            <%= averaged.name %>
            (<%= averaged.metric %>)
            </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th class="category">
            <%= averaged.date.strftime("%m-%d-%Y") %>
            </th>

            <th class="value">
            <%= averaged.result %>
            </th>
          </tr>
          <% end %>
      <% end %>
     </table>
    </div>


<!-- end snippet -->

**controller index**

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

      def index
       @averaged_quantifieds = current_user.quantifieds.averaged
      end

<!-- end snippet -->

**rb**

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

    class Quantified < ActiveRecord::Base
        belongs_to :user
        scope :averaged,  -> { where(categories: 'Monthly Average') }

        CATEGORIES = ['Monthly Average', 'One-Time Instance']
    end

<!-- end snippet -->

**schema**

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

      create_table "quantifieds", force: true do |t|
        t.string   "categories"
        t.string   "name"
        t.string   "metric"
        t.decimal  "result"
        t.date     "date"
        t.datetime "created_at", null: false
        t.datetime "updated_at", null: false
        t.integer  "user_id"
      end

      add_index "quantifieds", ["categories"], name: "index_quantifieds_on_categories"
      add_index "quantifieds", ["user_id"], name: "index_quantifieds_on_user_id"

<!-- end snippet -->

  [1]: http://i.stack.imgur.com/vgUym.png
  [2]: http://i.stack.imgur.com/5fDG9.png
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900