0

Instead of each table being created as a new row like:

TABLE #1

TABLE #2

TABLE #3

How can I make it like so:

TABLE #1 | TABLE #2 | TABLE #3

I'm asking specifically in regards to the Monthly Average table.

Any help would be greatly appreciated!

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

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

end

controller

  def index
   @averaged_quantifieds = current_user.quantifieds.averaged
   @instance_quantifieds = current_user.quantifieds.instance
  end

index

<!-- 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>
  <td>
            <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>
  </tbody>
</td>
    <% end %>
    <% end %>
 </table>
</div>

form

<%= form_for(@quantified) do |f| %>
  <% if @quantified.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@quantified.errors.count, "error") %> prohibited this quantified from being saved:</h2>

      <ul>
      <% @quantified.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<div class="america">
<form>
   <%= f.select :categories, Quantified::CATEGORIES %>

   <br>
   <br>

  <div class="form-group">
    <%= f.text_field :name, class: 'form-control', placeholder: 'Enter Name' %>
  </div>

  <div class="form-group">
    <%= f.text_field :result, class: 'form-control', placeholder: 'Enter Result' %>
  </div>

  <div class="form-group">
    <%= f.text_field :metric, class: 'form-control', placeholder: 'Enter Metric' %>
  </div>

    <div class="date-group">
      <label> Date: </label>
      <%= f.date_select :date, :order => [:month, :day, :year], class: 'date-select' %>
    </div>


<div class="america2">
  <%= button_tag(type: 'submit', class: "btn") do %>
  <span class="glyphicon glyphicon-plus"></span>
  <% end %>

  <%= link_to quantifieds_path, class: 'btn' do %>
  <span class="glyphicon glyphicon-chevron-left"></span>
  <% end %>

  <%= link_to @quantified, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn' do %>
  <span class="glyphicon glyphicon-trash"></span>
  <% end %>
</div>

</form>
</div>
<% end %>

schema

  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"
4
  • What are you trying to ask ? Why tables created in horizontal manner ? What's the issue ? Commented Jan 9, 2015 at 22:01
  • Thank you! I asked a similar question here: stackoverflow.com/questions/27852572/…. I guess I'm asking the wrong question, which is why I'm having a really hard time figuring out the answer maybe you can make sense out of my madness. Commented Jan 9, 2015 at 22:08
  • How to Add Column (Instead of Row) for Each "Table Loop Iteration?" 1st part: how to add column to table,understood and clear. But What's this table loop iteration? Commented Jan 9, 2015 at 22:11
  • Oops sorry I meant it as every time <% @averaged_quantifieds.each do |averaged| %> creates a new table on the index page that it would appear as a column instead of as a row in the <div>. Commented Jan 9, 2015 at 23:55

2 Answers 2

1

Assuming: - You have issue in representing data in horizontal rows. -you have got 4 columns in your table and naming them as name, metric, date, result.

Following table will help you in fixing your issue:

<table>
  <thead>
    <tr>
      <th> Name</th>
      <th>Metric</th>
      <th>date</th>
      <th>result</th>
    </tr>
  </thead>

  <tbody>
    <% @averaged_quantifieds.each do |averaged| %>
      <% if averaged.user == current_user %>
        <tr>
          <td><%= averaged.name %> </td>
          <td><%= averaged.metric %> </td>
          <td> <%= average.date %> </td>
          <td><%= averaged.result %> </td>
          </tr>
      <% end %>
    <% end %>
  </tbody>
</table>
Sign up to request clarification or add additional context in comments.

Comments

0

I am rather inexperienced myself but I understand your problem. If you want your table laid out in a horizontal way you must change the code in the view. For instance In your case I think it's supposed to be like this:

 <tr>
  <td class="value">
            <%= averaged.name %>
            (<%= averaged.metric %>) </td>
         </tr>

And so on and so forth.

You are not closing your td's correctly either. In your case you only have one for the whole thing. You need one every time you are adding data.

If I'm wrong, dont crucify me, this is my first question I'm answering

More info here: http://www.w3schools.com/html/html_tables.asp

Please reply if I fixed your problem

1 Comment

Thank you for your help! The problem is unfortunately not the table itself, but when new tables are created within the larger <div>. Once a User submits a new _form that creates a new table that table is created as a row, not a column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.