I am trying to run number_of_days.times do to create a table, and in the first column I need to iterate through dates. I am trying to add + 1.day for each .times do so that each row of the table has the next date. I am blanking on why my counter isn't working inside the .times do and what I should do about it. Here is my code:
#day_count is the number of days from a starting date to today, which I have confirmed is working to return the correct number integer and in fact is running through my times do correctly because it creates the correct number of table rows.
<table>
<thead>
<th><strong>Date</strong></th>
<th><strong>Total Entries</strong></th>
<th><strong>New Entries</strong></th>
<th><strong>New Form Entries</strong></th>
<th><strong>New Image Entries</strong></th>
</thead>
<tbody>
<% count = -1 %>
<% #day_count.times do %>
<tr>
<% count.to_i + 1 %>
<td><%= #start_date + count.day %></td>
<td> test </td>
<td> test </td>
<td> test </td>
<td> test </td>
</tr>
<% end %>
</tbody>
</table>
each#start_date + count.day produces the same date. I know I am missing something very simple here... thanks in advance for the help
I'm not sure why you wouldn't:
(1..#day_count).each do |count|
...
or
(#start_date..Date.today).each do |day|
...
I'm not sure you're incrementing the count variable each time the loop is iterated.
Try adding count += 1 somewhere in there.
<table>
<thead>
<th><strong>Date</strong></th>
<th><strong>Total Entries</strong></th>
<th><strong>New Entries</strong></th>
<th><strong>New Form Entries</strong></th>
<th><strong>New Image Entries</strong></th>
</thead>
<tbody>
<% count = 0 %>
<% #day_count.times do %>
<tr>
<td><%= #start_date + count.day %></td>
<% count += 1 %>
<td> test </td>
<td> test </td>
<td> test </td>
<td> test </td>
</tr>
<% end %>
</tbody>
</table>
Related
this my code and it increases always when i have an evaluation, in the end it shows the grade, but, the average always stays after the grade. I wanted to know how I do it to put it at the end.
<% #registration.matrix.blocks.each do |block| %>
<h5>Block: <%= block.description %></h5>
<div class="table-responsive">
<table class="table table-sm table-striped table-bordered shadow-sm">
<thead class="thead-dark">
<tr>
<th>Discipline</th>
<th>Assigned Fouls</th>
<th>Test 1</th>
<th>Test 2</th>
<th>Test 3</th>
<th>Test 4</th>
<th>Test 5</th>
<th>Test 6</th>
<th>Test 7</th>
<th>Test 8</th>
<th>Final Test</th>
<th>Average</th>
</tr>
</thead>
<tbody>
<% block.disciplines.distinct.each do |discipline| %>
<tr>
<td><%= discipline.name %></td>
<td>
<%= number_of_absences(current_user, discipline) %>
</td>
<% discipline.evaluations.each do |evaluation| %>
<td><%= Evaluate.get_evaluate(current_user.id, evaluation.id).present? ? Evaluate.get_evaluate(current_user.id, evaluation.id).note : '0,0' %></td>
<% end %>
<td><%= get_media(current_user, discipline) %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
Image to see the bug
So I would like to know how I fix the error, for example I put the grade 10, it divides by 8 as I programmed, but the average that is 10/8 since 10 was the only grade that assigns, it gets 1,25 however the average is on the side and not in the end, as I do to put in the end in the table "average"
If the question is how to align the average value under the Average table header? the answer is that you have to put as many td as needed in order to align it there, otherwise I didn't understand the question :-)
I am trying to submit a grid form like the below one,
show.html.erb
<%= form_for :datadef, url: update_all_vmodule_path do |fdf|%>
<table id="csvfiles" class="display" width="100%">
<thead>
<tr>
<th width="10%">Column No</th>
<th width="20%">Column name</th>
<th width="20%">Data type</th>
<th width="15%">Column format</th>
<th width="10%">Length</th>
<th width="25%">Comments</th>
</tr>
</thead>
<tbody>
<% #datadefrecords.each do |ddre| %>
<%= fields_for "datadef_records[]", ddre do |dr_fld| %>
<tr>
<td><%= ddre.column_no %></td>
<td><%= ddre.column_name %></td>
<td><%= dr_fld.collection_select :column_datatype, Datadef.select(:column_datatype).uniq, :column_datatype, :column_datatype, {:prompt => true} %> </td>
<td><%= dr_fld.text_field :column_format %></td>
<td><%= dr_fld.text_field :column_length %></td>
<td><%= dr_fld.text_field :comments %></td>
</tr>
<% end %>
<% end %>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"><%= fdf.submit 'Save' %> <%= link_to("<button>Cancel</button>".html_safe, cancelmodal_vmodule_path ) %></td>
</tr>
</tbody>
</table>
<% end %>
<% end %>
This the method i am calling it to submit
def update_all
session[:datadef] = nil
#updatedatadef = Datadef.all.where(:id => params[:datadef_records]).update_all(update_all_params)
redirect_to migproject_path(params[:vmodule][:migproject_id])
end
This is the strong parameters
def update_all_params
params.require(:datadef_records).permit( :column_datatype, :column_format, :column_length, :comments)
end
This is how i get the parameters from form
{"utf8"=>"✓",
"authenticity_token"=>"QrX8JYYYQOlfwKgAABJd0+A7VpugS2Y6n8doDsuKqeM=",
"datadef_records"=>{"12"=>{"column_datatype"=>"varchar",
"column_format"=>"2",
"column_length"=>"2",
"comments"=>"2"},
"13"=>{"column_datatype"=>"varchar",
"column_format"=>"2",
"column_length"=>"2",
"comments"=>"2"}},
"commit"=>"Save",
"id"=>"2"}
But i get this "Empty list of attributes to change" error which is not allowing me to write it in table. And i am not able to identify what could be the error.
Thanks in advance.
I think the problem is to do with your use of update_all, although I'm not 100% sure as to the syntax of the problem.
From what I understand, update_all needs a hash of actual params to populate your data; even then, it will only update what you pass to it (kind of like update_attributes).
Here's a good reference:
data = params[:datadef_records]
#updatedatadef = Datadef.update(data.keys, data.values)
This negates the use of your strong_params, which I'd recommend using. I'd have to spend some time thinking about getting it to work.
I'm creating a report using group_by to break out orders for a month by week. This works perfectly fine using rails beginning_of_week method but it breaks up weeks for a month using standard instead of ISO weeks.
groups orders by week
orders = orders.group_by {|x| x.order_date.beginning_of_week(start_day = :monday)}
loop in view
<table style="width:100%">
<thead>
<tr>
<th>Item</th>
<th>price</th>
</tr>
</thead>
<tbody>
<% orders.each do |week, items| %>
<tr>
<th colspan="2">
Orders week of <%= week.strftime("%m-%d-%Y") %> - <%= (week + 4).strftime("%m-%d-%Y") %>
</th>
</tr>
<% items.each do |weekitem| %>
<tr>
<td><%= weekitem.item_number %></td>
<td><%= weekitem.price %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
I thought I could chain cweek like below but it returns an error.
orders = orders.group_by {|x| x.order_date.beginning_of_week.cweek(start_day = :monday)}
Considering my example how would I group_by ISO weeks instead of standard? Is there any way to switch that using beginning_of_week method or is there another way this has to be done?
I am trying to display in my a table with most popular tag words, ordered by the count of impression. Then add kaminari to paginate through the records.
in my controller I tried:
#tag_answers = Tag.group(:content).page(params[:page]).order("count_all DESC").count
and in my view:
<table>
<thead>
<th>Tag</th>
<th>Count</th>
</thead>
<tbody>
<% #tag_answers.each do |tag_content, tag_count| %>
<tr>
<td> <%= tag_content %> </td>
<td> <%= tag_count %> </td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate #tag_answers %>
but i am getting the following error
undefined method `current_page' for #<ActiveSupport::OrderedHash:0x000001031b8678>
Try
#tag_answers = Tag.group(:content).select('content, COUNT(*) as count').order("count DESC").page(params[:page])
I currently have an Array that contains some URL's to images.
#images = [ "http://site/images/01.jpg", "http://site/images/02.jpg" ]
Total 18 images
I would like to take this array and create a thumbnail gallery where the gallery is 3 columns across in my view. The HTML out put would be
<table>
<tr>
<td><img src="http://site/images/01.jpg"></td>
<td><img src="http://site/images/02.jpg"></td>
<td><img src="http://site/images/03.jpg"></td>
</tr>
<tr>
<td><img src="http://site/images/04.jpg"></td>
<td><img src="http://site/images/05.jpg"></td>
<td><img src="http://site/images/06.jpg"></td>
</tr>
</table>
My current implementation gets me a one column table
<table>
<tr>
<% #images.each do | image | %>
<td><%= image_tag(image)%></td><br>
<% end %>
</tr>
</table>
In the future I might want it to be 6 columns instead of 3 columns.
I'm looking for a way to do this in a clean and flexible way.
I was looking at the Ruby documentation and I saw this
Class Range (rng.step method)
http://www.ruby-doc.org/core/classes/Range.html
Not sure if this Range class step method can solve the problem but the example it provides is interesting.
Any thoughts, I'm still learning and maybe I'm over thinking this?
use each_slice()
<table>
<% #images.each_slice(3) do |images| %>
<tr>
<% images.each do |image| %>
<td><%= image_tag(image) %></td>
<% end %>
</tr>
<% end %>
</table>
Untested. You need to use each_with_index and the modulus % operator.
<% #images.each_with_index | image, index | %>
<% unless index % column_count == 0 %>
<td><%= image_tag(image)%></td>
<% else %>
<td><%= image_tag(image) %></td>
</tr>
<tr>
<% end %>
<% end %>