Ruby xml to xls style error - ruby-on-rails

Hi as you can see below I am using ruby to automate an xls creation process, but unfortunately when the xls document is created a small style error occurs. This shows in the checkboxes where the first few are too big as you can see in the image below.
also here is the code of the xls table:
<table border="1" width="100px">
<tr>
<th></th>
<th colspan="32">Hours of rest record</th>
<th colspan="16">Crew Members Name</th>
<th colspan="1"></th>
<th colspan="2"><%= #crewmember.user.full_name %></th>
</tr>
<tr>
<th></th>
<th colspan="48">Work hours (Place and 'x' in each half hour worked and count hours of rest)</th>
<th colspan="1">Start Date</th>
<th colspan="2"><%= #shifts.first.day %></th>
</tr>
<tr>
<th colspan="1">Hours / date</th>
<th colspan="2">0030</th>
<th colspan="2">0130</th>
<th colspan="2">0230</th>
<th colspan="2">0330</th>
<th colspan="2">0430</th>
<th colspan="2">0530</th>
<th colspan="2">0630</th>
<th colspan="2">0730</th>
<th colspan="2">0830</th>
<th colspan="2">0930</th>
<th colspan="2">1030</th>
<th colspan="2">1130</th>
<th colspan="2">1230</th>
<th colspan="2">1330</th>
<th colspan="2">1430</th>
<th colspan="2">1530</th>
<th colspan="2">1630</th>
<th colspan="2">1730</th>
<th colspan="2">1830</th>
<th colspan="2">1930</th>
<th colspan="2">2030</th>
<th colspan="2">2130</th>
<th colspan="2">2230</th>
<th colspan="2">2330</th>
<th colspan="1">Hours of rest</th>
<th colspan="2">Comment</th>
</tr>
<% #shifts.each do |shift| %>
<tr>
<td><%= shift.day %></td>
<td><%= shift.hour_0000_to_0029 %></td>
<td><%= shift.hour_0030_to_0059 %></td>
<td><%= shift.hour_0100_to_0129 %></td>
<td><%= shift.hour_0130_to_0159 %></td>
<td><%= shift.hour_0200_to_0229 %></td>
<td><%= shift.hour_0230_to_0259 %></td>
<td><%= shift.hour_0300_to_0329 %></td>
<td><%= shift.hour_0330_to_0359 %></td>
<td><%= shift.hour_0400_to_0429 %></td>
<td><%= shift.hour_0430_to_0459 %></td>
<td><%= shift.hour_0500_to_0529 %></td>
<td><%= shift.hour_0530_to_0559 %></td>
<td><%= shift.hour_0600_to_0629 %></td>
<td><%= shift.hour_0630_to_0659 %></td>
<td><%= shift.hour_0700_to_0729 %></td>
<td><%= shift.hour_0730_to_0759 %></td>
<td><%= shift.hour_0800_to_0829 %></td>
<td><%= shift.hour_0830_to_0859 %></td>
<td><%= shift.hour_0900_to_0929 %></td>
<td><%= shift.hour_0930_to_0959 %></td>
<td><%= shift.hour_1000_to_1029 %></td>
<td><%= shift.hour_1030_to_1059 %></td>
<td><%= shift.hour_1100_to_1129 %></td>
<td><%= shift.hour_1130_to_1159 %></td>
<td><%= shift.hour_1200_to_1229 %></td>
<td><%= shift.hour_1230_to_1259 %></td>
<td><%= shift.hour_1300_to_1329 %></td>
<td><%= shift.hour_1330_to_1359 %></td>
<td><%= shift.hour_1400_to_1429 %></td>
<td><%= shift.hour_1430_to_1459 %></td>
<td><%= shift.hour_1500_to_1529 %></td>
<td><%= shift.hour_1530_to_1559 %></td>
<td><%= shift.hour_1600_to_1629 %></td>
<td><%= shift.hour_1630_to_1659 %></td>
<td><%= shift.hour_1700_to_1729 %></td>
<td><%= shift.hour_1730_to_1759 %></td>
<td><%= shift.hour_1800_to_1829 %></td>
<td><%= shift.hour_1830_to_1859 %></td>
<td><%= shift.hour_1900_to_1929 %></td>
<td><%= shift.hour_1930_to_1959 %></td>
<td><%= shift.hour_2000_to_2029 %></td>
<td><%= shift.hour_2030_to_2059 %></td>
<td><%= shift.hour_2100_to_2129 %></td>
<td><%= shift.hour_2130_to_2159 %></td>
<td><%= shift.hour_2200_to_2229 %></td>
<td><%= shift.hour_2230_to_2259 %></td>
<td><%= shift.hour_2300_to_2329 %></td>
<td><%= shift.hour_2330_to_2359 %></td>
<td colspan="1" style="text-align:center;"><%= shift.hours_of_rest %></td>
<td colspan="2"><%= shift.time_profile_id %></td>
</tr>
<% end %>
</table>
<br/><br/>
<table border="1">
<tr>
<th>Approved By:</th>
<th>Hours of Rest Record:</th>
<th>Version</th>
<th>Last Review</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<br/>
<table border="0">
<tr>
<td>Crew Member Signiture</td>
<td style="width:200px; border-bottom: 0.5px dotted black"></td>
</tr>
<tr><td></td></tr>
<tr>
<td>Master Signiture</td>
<td style="width:200px; border-bottom: 0.5px dotted black"></td>
</tr>
</table>
another note is that when I remove all the tables but the very top table it seems to fix it.
Thank you in advance

Sorry guys I figured it out the "Hours of rest record", "version", and "last view" was dictating the width

Related

Iterate in array of hashes in side array in ruby

I want to iterate this oject and print in table
[
{
:invoice_details=>
{
:customer_name=>"Dylan Sollfrank",
:invoice_number=>"1060",
:invoice_status=>"paid",
:transaction_total_amount=>50.0,
:trnsaction_details=>
[
{
:transaction_number=>"QB1601361635",
:customer_name=>"Dylan Sollfrank",
:amount=> {:amount_to_pay=>50.0, :payment_fee=>0.0},
:created_time=>"12:10 PM",
:created_date=>"Sep 29,2020",
:payment_method=>"Quickbook",
:payment_status=>"completed"
}
]
}
}
]
invoice_details in one row and transaction_details in another row in table format. transaction_details is an array inside the invoice_details.
EDIT
I did it by
I did it
<% ar_activity.first.each do |invoice, invoices_hash| %>
<tr>
<td><%= invoices_hash[:invoice_number] %> </td>
<td><%= invoices_hash[:invoice_status]%></td>
<td><%= invoices_hash[:customer_name] %> </td>
<td><%= invoices_hash[:transaction_total_amount]%></td>
</tr>
<% invoices_hash[:trnsaction_details].each do |transaction|%>
<tr>
<td></td>
<td><%= transaction[:transaction_number]%></td>
<td><%= transaction[:customer_name]%></td>
<td><%= transaction[:amount][:amount_to_pay].to_f + transaction[:amount][:payment_fee].to_f%></td>
<td><%= "#{transaction[:created_time]} " "#{transaction[:created_date]}" %></td>
<td><%= transaction[:payment_method] %></td>
<td><%= transaction[:payment_status] %></td>
</tr>
<%end%>
<%end%>
but its only good for the first invoice_details so it's not working
Thanks
I did it
<% ar_activity.each do |invoices|%>
<% invoices.each do |invoice, invoices_hash| %>
<tr>
<td><%= invoices_hash[:invoice_number] %> </td>
<td><%= invoices_hash[:invoice_status]%></td>
<td><%= invoices_hash[:customer_name] %> </td>
<td><%= invoices_hash[:transaction_total_amount]%></td>
</tr>
<% invoices_hash[:trnsaction_details].each do |transaction|%>
<tr>
<td></td>
<td><%= transaction[:transaction_number]%></td>
<td><%= transaction[:customer_name]%></td>
<td><%= transaction[:amount][:amount_to_pay].to_f + transaction[:amount][:payment_fee].to_f%></td>
<td><%= "#{transaction[:created_time]} " "#{transaction[:created_date]}" %></td>
<td><%= transaction[:payment_method] %></td>
<td><%= transaction[:payment_status] %></td>
</tr>
<%end%>
<%end%>
<%end%>

Rails looping through params data

I am parsing an excel file and passing the data to my controller but I cannot seem to loop through it in my view:
Params:
Parameters: {"data"=>{"consult_charges"=>[{"id"=>"17474", "item"=>"Consultation", "name"=>"Ramon", "price"=>"25.0"}, {"id"=>"17584", "item"=>"Consultation", "name"=>"Ramon", "price"=>"25.0"}, {"id"=>"17490", "item"=>"Consultation", "name"=>"Elizabeth", "price"=>"25.0"}, {"id"=>"17515", "item"=>"Consultation", "name"=>"Elizabeth", "price"=>"25.0"}, {"id"=>"17554", "item"=>"Consultation", "name"=>" Elizabeth", "price"=>"25.0"}, {"id"=>"17623", "item"=>"Consult - Referral Card", "name"=>"Elizabeth", "price"=>"0.0"}, {"id"=>"17486", "item"=>"Consultation", "name"=>"Racha", "price"=>"25.0"}
Controller:
#consult_charges = params["data"]["consult_charges"]
View:
<table class="table awaken">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<% #consult_charges.each do |sale| %>
<td><%= sale["id"] %></td>
<td><%= sale["name"] %></td>
<td><%= sale["item"] %></td>
<td><%= sale["price"] %></td>
<% end -%>
</tbody>
</table>
The result is a single line of data as if there is only one sale. When I look at the value for #consult_charges it's an array of items like this:
<ActionController::Parameters {"id"=>"17584", "item"=>"Consultation", "name"=>"Ramon", "price"=>"25.0"} permitted: false>
Do I need to do something to convert the type?
The reason it's showing just one line is because <tr> tag is missing on each iteration. Change your view to;
<table class="table awaken">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<% #consult_charges.each do |sale| %>
<tr>
<td><%= sale["id"] %></td>
<td><%= sale["name"] %></td>
<td><%= sale["item"] %></td>
<td><%= sale["price"] %></td>
</tr>
<% end -%>
</tbody>
</table>

Responsive Details Not Showing On jquery-datatables-rails

I've been trying to make this work and I can't seem to find a solution:
I have a table and I have a basic initialization of the Datatables everything seems to work fine but once the responsive gets activated the details button doesn't work if I click on it it goes red with the - sign but the details doesn't appear.
This is my table:
<table id="tabla" class="display dt-responsive no-wrap" width="100%">
<thead>
<tr>
<th>Profesor</th>
<th>Materia</th>
<th>Seccion</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #profesors.each do |profesor| %>
<tr>
<td><%= profesor.profesor %></td>
<td><%= profesor.materia %></td>
<td><%= profesor.seccion %></td>
<td><%= link_to 'Show', profesor %></td>
<td><%= link_to 'Edit', edit_profesor_path(profesor) %></td>
<td><%= link_to 'Destroy', profesor, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Alumnos', alumnos_path("prof" => profesor) %></td>
</tr>
<% end %>
</tbody>
</table>
This is my JS
$('#tabla').DataTable({
responsive: true
});
If you use bootstrap try wrapping the <table> with <div class="table-responsive"> link
Some like:
<div class="table-responsive">
<table id="tabla" class="display dt-responsive no-wrap" width="100%">
<thead>
<tr>
<th>Profesor</th>
<th>Materia</th>
<th>Seccion</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #profesors.each do |profesor| %>
<tr>
<td><%= profesor.profesor %></td>
<td><%= profesor.materia %></td>
<td><%= profesor.seccion %></td>
<td><%= link_to 'Show', profesor %></td>
<td><%= link_to 'Edit', edit_profesor_path(profesor) %></td>
<td><%= link_to 'Destroy', profesor, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Alumnos', alumnos_path("prof" => profesor) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

Iterate over column names

I have an employee object that I'd like to just show a list of the keys and the associated values for in the show.html.erb file. Here's what I have currently, but how can this be done with a for loop?
<table class="table table-striped">
<tr>
<th>Item</th>
<th>Value</th>
</tr>
<tr>
<td>Name</td>
<td><%= #employee.name %></td>
</tr>
<tr>
<td>Email</td>
<td><%= #employee.email %></td>
</tr>
<tr>
<td>Job Code</td>
<td><%= #employee.job_code %></td>
</tr>
...
</table>
<% #employee.attributes.each do |key, value| %>
<tr>
<td><%= key.gsub('_', ' ').titleize %></td>
<td><%= value %></td>
</tr>
<% end %>

Ruby display array values

I am not a ruby developer. This is the first time I am looking into the code. I want to build a dynamic table for which I have managed below code. However, I am not able to display all the contents of the array except for the first and the last values. How do I display all the values?
Thanks for your help!!
<style>table, td, th{border:1px solid white;}td{padding:5px;}th{background-color:#E0E6EB;color:black;}</style>
<div>
<table border=2>
<tr>
<th width="250px"><B><p style="text-align: center">Name</p></B></th>
<th width="120px"><B><p style="text-align: center">Number</p></B></th>
<th width="60px"><B><p style="text-align: center">Status</p></B></th>
<th width="155px"><B><p style="text-align: center">Product Type</p></B></th>
<th width="60px"><B><p style="text-align: center">Source</p></B></th>
</tr>
<% tempTickets = #subject.PersonAccounts.sorted_by(field("title").in_descending_order) %>
<% cnt = tempTickets.length %>
<% tempTickets.each do |ticket| %>
<div>
<tr>
<td><%= ticket['perfinaccnt-accountname'].first %></td>
<td><%= ticket['perfinaccnt-accountnumber'].first %></td>
<td><%= ticket['perfinaccnt-accountstatus'].first %></td>
<td><%= ticket['perfinaccnt-producttype'].first %></td>
<td><%= ticket['perfinaccnt-accountsrcsystem'].first %></td>
</tr>
</div>
<div>
<tr>
<td><%= ticket['perfinaccnt-accountname'].last %></td>
<td><%= ticket['perfinaccnt-accountnumber'].last %></td>
<td><%= ticket['perfinaccnt-accountstatus'].last %></td>
<td><%= ticket['perfinaccnt-producttype'].last %></td>
<td><%= ticket['perfinaccnt-accountsrcsystem'].last %></td>
</tr>
</div>
<% end %>
</table>
</div>
You could do it with three nested loops:
<%= tempTickets.each do |ticket|
[
'perfinaccnt-accountname',
'perfinaccnt-accountnumber',
'perfinaccnt-accountstatus',
'perfinaccnt-producttype',
'perfinaccnt-accountsrcsystem'
].each do |f|
ticket[f].each do |tf|
puts "<td>tf</td>";
end if ticket[f]
end
end %>
I'm not sure about the data structure here but you could check it by doing an #inspect to tempTickets and all the subsequent objects. From the looks of it "ticket['perfinaccnt-accountname']" is actually an array
and as such you can just loop through it. Not the fastest way to do it but it should work to just do a nested loop.
<style>table, td, th{border:1px solid white;}td{padding:5px;}th{background-color:#E0E6EB;color:black;}</style>
<div>
<table border=2>
<tr>
<th width="250px"><B><p style="text-align: center">Name</p></B></th>
<th width="120px"><B><p style="text-align: center">Number</p></B></th>
<th width="60px"><B><p style="text-align: center">Status</p></B></th>
<th width="155px"><B><p style="text-align: center">Product Type</p></B></th>
<th width="60px"><B><p style="text-align: center">Source</p></B></th>
</tr>
<% tempTickets = #subject.PersonAccounts.sorted_by(field("title").in_descending_order) %>
<% cnt = tempTickets.length %>
<% tempTickets.each do |ticket| %>
<div><tr>
<% ticket.each do |k,v|
v.each do |col| %>
<td><%= col %></td>
<% end %>
<% end %>
</tr></div>
<% end %>
</table>
</div>

Resources