Print HTML Page Twitter bootstrap - ruby-on-rails

I have a show page /invoices/show that displays contents of my Invoice
<p id="notice"><%= notice %></p>
<div class="row">
<div class="span7">
<h2 style="text-align:center;"> CONSTRUCTION LTD </h2>
<h3 style="text-align:center;">OHIO</h3>
<address style="text-align:center;"> Plot 10<br/>
</address>
<h3 style="text-decoration:underline; text-align:center;"> UTILITY BILL </h3>
<h4 style="text-decoration:underline; text-align:center;"> TAX INVOICE </h4>
<table>
<td valign="top" align="left">
<div style="float:left; width:450px;">No: <%= #invoice.id %></div>
<div style="float:right"> Date: <%= #invoice.invoice_date %></div>
</td>
</table>
<P></P>
<P></P>
<div>To: <%= #invoice.customer.name%></div>
<p></p>
<table class="table table-bordered table-condensed">
<thead>
<tr class="success">
<th><label class="control-label">Description</label></th>
<th><label class="control-label">Rate</label></th>
<th><label class="control-label">Tax</label></th>
<th><label class="control-label">Amount</label></th>
</tr>
</thead>
<tbody>
<% #invoice.invoice_items.each do | item| %>
<tr class="controls">
<td><%= item.description %></td>
<td><%= item.rate %></td>
<td><%= item.tax_amount %></td>
<td><%= item.amount %></td>
</tr>
<tr>
<td colspan="3" align="left"><strong>TOTAL:</strong></td>
<td colspan="1"><%= item.amount %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="row">
<div class="span3">
<table>
<tbody>
<tr>
<td> <b>For Landlord</b></td></tr>
<tr> <td>Approved by:</td></tr>
<tr> <td>Sign:</td></tr>
</tbody>
</table>
</div>
<div class="span3" style="position: relative; align:left; left:150px;">
<table>
<tbody>
<tr>
<td> <b>For Tenant</b></td></tr>
<tr> <td>Approved by:</td></tr>
<tr> <td>Sign:</td></tr>
</tbody>
</table>
</div>
</div>
<br/>
<br />
<div>
<small><strong>Terms and Conditions</strong></small>
<table>
<tbody>
<tr>
<td><%= Settings.invoice_terms%></td>
</tr>
</tbody>
</table>
</div>
<br />
<div class="form actions">
<p>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_invoice_path, :class => 'btn btn-primary' %>
</p>
</div>
</div>
</div>
In my application.html.erb, I have this for CSS
<%= stylesheet_link_tag "application", :media => "all" %>
More to that, my application file has a nav-bar element.
I am trying to print the Invoices/show.html.erb page by going to the print option in a browser, however, I do not want it to include the nav-bar element in my application.html.erb file and the edit button in invoices/show.html.
I am using Twitter bootstrap, how can i go about this?

Here's one solution I've thought of:
What you can do is, in your show view (or the application layout) add a predicate:
if params[:controller] == "invoice" && params[:action] == "show"
# do or show whatever you want
end
Or you could do add a different layout to your views/layouts folder. Then in your controllers/invoice_controller
def show
# ...
render layout: 'a_different_layout_for_invoices'
end

Related

table column width is not increare

There is an issue to increase table column width of a particular column...
<table id="metadata">
<tr>
<td class="meta-head">GRN #</td>
<% if #grn.date.month >= 4 && #grn.date.month <= 12 %>
<td>
<textarea><%= "GRN"+#warehouse.shortform+"/"+(#grn.date.year.to_s.at(2..3))+"-"+(((#grn.date.year)+1).to_s.at(2..3))+"/"+(#grn.serial.to_s.rjust(5, '0')) %>
</textarea>
</td>
<% else %>
<td><textarea><%= "GRN"+#warehouse.shortform+"/"+(((#grn.date.year)-1).to_s.at(2..3))+"-"+(#grn.date.year.to_s.at(2..3))+"/"+(#grn.serial.to_s.rjust(5, '0')) %></textarea></td>
<% end %>
<td class="meta-head">Vehicle</td>
<td><textarea id="date"><%= #grn.vehicle_no %></textarea></td>
<td rowspan="3" style="border:none; width: 200px;">
<div id="logo">
<div id="logohelp">
<input id="imageloc" type="text" size="50" value="" /><br>
(max width: 540px, max height: 100px)
</div>
<% if #warehouse.logo != nil %>
<%= image_tag(#warehouse.logo, :alt => "logo", id: "image") %><br>
<% else %>
<% end %>
</div>
</td>
</tr>
<tr>
<td class="meta-head">GRN Date</td>
<td><textarea id="date"><%= #grn.date.strftime("%d/%m/%y") %></textarea></td>
<td class="meta-head">Bill #</td>
<td><textarea id="date"><%= #grn.bill_no %></textarea></td>
</tr>
<tr>
<td class="meta-head">Challan</td>
<td><textarea id="date">No. <%= #grn.challan_no %>, Dt. <%= #grn.challan_date %></textarea></td>
<td class="meta-head">Bill Date</td>
<td><textarea id="date"><%= #grn.bill_date %></textarea></td>
</tr>
<tr>
<td class="meta-head">PO #</td>
<td><textarea id="date"><%= #grnitems[0].purchase_order_item.purchaseorder.serial %></textarea></td>
<td class="meta-head">Transporter</td>
<td><textarea id="date"><%= #grn.transporter %></textarea></td>
<td rowspan="3" style="border:none; width: 200px;">
<% if #warehouse.address1 != nil %>
<h6> <%= #warehouse.address1 %>
<%= #warehouse.address2 %>
<%= #warehouse.address3 %>
<%= #warehouse.address4 %> </h6>
<% end %>
</td>
</tr>
<tr>
<td class="meta-head">Vendor </td>
<td><textarea id="date"><%= #grnitems[0].purchase_order_item.purchaseorder.vendor.description %></textarea> </td>
<td class="meta-head">LR #</td>
<td><textarea id="date"><%= #grn.lr_no %></textarea></td>
</tr>
<tr>
<td class="meta-head">Way bill </td>
<td><textarea id="date"></textarea></td>
<td class="meta-head">LR Date</td>
<td><textarea id="date"><%= #grn.lr_date %></textarea></td>
</tr>
</table>
my table like
i like to implement thelogo and address column are increase as per content.
I am trying various way like
<table id="metadata" width="100%" >
<td width="100%">
I dont know where i mistake?
Use this style attribute for no word wrapping:
white-space: nowrap;

Rails 5 - table row while no entry exists

In my rails app, content of documents are being tagged. For documents that do not have any tags, an empty row is shown in the listing (table rows) - always at the bottom of the table. I've tried to solve this for hours, not sure where to research and I'm not getting anywhere. All help welcome!
this is the view (snippet):
<div class="row" id="annotationResults">
<div class="panel panel-default" style="background-color: white; word-wrap: break-word; font-size: 0.9em;">
<table id="tags" class="table table-hover">
<thead>
<tr>
<th>Tagged content</th>
<th>as</th>
<th>in</th>
<th></th>
</tr>
</thead>
<tbody>
<% #annotation.tags.each do |tag| %>
<tr>
<td><%= tag.content %></td>
<td><%= tag.tagtype_id %></td>
<td><%#= tag.tagtype.name %></td>
<td><%= link_to '', [tag.annotation, tag], method: :delete, data: { confirm: 'Please confirm deletion!' }, :class => "glyphicon glyphicon-remove" %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
It's there because you're printing an empty td.
<td><%= tag.content %></td>
Will print the td element even if the tag.content is empty. Check the example:
td{ border: 1px solid black }
<table>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
Use your RoR snippet as you mentioned in the comment:
<% #annotation.tags.each do |tag| %>
<% unless tag.content.blank? %>
<td>
<!-- logic -->
</td>
<% end %>
<% end %>
try this,
<% if tag.content.present? %>
<%= tag.content %>
<% end %>

How to solve undefined method in PostgreSQL

I have this problem where i have to query lots of data as im using has_many :through relationship. this code works in sqlite but not in PostgreSQL
my Controller:
#task_logs_unapprove = TaskLog.includes(:client).includes(:staff).where(completed_at: nil).page(params[:page]).per_page(10).all
And my Views:
<div class="panel panel-dark panel-light-green">
<div class="panel-heading"><span class="panel-title">Unapprove Task Logs</span>
<div class="panel-heading-controls"><%= will_paginate #task_logs_unapprove, renderer: BootstrapPagination::Rails %></div>
</div>
<table class="table table-bordered">
<thead class="cf">
<tr>
<th>Task Code</th>
<th>Client</th>
<th>Staff</th>
<th>Work Time Today</th>
<th colspan="4"></th>
</tr>
</thead>
<tbody>
<% #task_logs_unapprove.each do |task_log| %>
<tr>
<td data-title="Name"><strong><%= task_log.task_code %></strong></td>
<td data-title="Name"><strong><%= task_log.client_name %></strong></td>
<td data-title="Name"><strong><%= task_log.staff_name %></strong></td>
<td data-title="Name"><strong><%= task_log.sum_of_hrs %></strong></td>
<td data-title="Name"><strong><%= link_to 'View', task_log %></strong></td>
<td data-title="Name"><strong><%= link_to 'Edit', edit_task_log_path(task_log) %></strong></td>
<td data-title="Name"><strong><%= link_to ' Unapproved', complete_task_log_path(task_log), method: :patch %></strong></td>
<td data-title="Name"><strong><%= link_to 'Delete', task_log, method: :delete, data: { confirm: 'Are you sure?' } %></strong></td>
</tr>
<% end %>
</tbody>
</table>
</div>
Take note this works in SqlLite but not in PostgreSQL
heres the error from my logs in heroku:
ActionView::Template::Error (undefined method `full_name' for nil:NilClass):
<div class="panel-heading">
<span class="panel-title">Unapprove Task Logs</span>
<div class="panel-heading-controls">
<%= will_paginate #task_logs_unapprove, renderer: BootstrapPagin <div class="panel-heading"> <span class="panel-title">Approve Task Logs</span> <div class="panel-heading-controls"><%= will_paginate #task_logs_approve, renderer: BootstrapPaginat <div class="panel-heading"><span class="panel-title">Unapprove Task Logs</span><div class="panel-heading-controls"><%= will_paginate #task_logs_unapprove, renderer: BootstrapPagin <div class="panel-heading"> <span class="panel-title">Approve Task Logs</span> <div class="panel-heading-controls"><%= will_paginate #task_logs_approve, renderer: BootstrapPaginat</div>nd %>iv>ong>Sorry!</strong> You Dont Have Permission To View This Page.m_of_hrs %>
</td>
the full_name error is a column in my staff and client table
i define the client_name in my task_log.rb model as like this def
client_name #{client.full_name} end same with the staff_name
I suppose that your model task_log does not have related client, so it's nil

Table in partial view not rendering

I am trying to display a table of jobs for a client sectioned by month year. The partial views evaluate and using binding.pry on each I can see that the correct values are there. The _month_section.html.erb date does not show, nor does the table in _jobs.html.erb
clients_controller.rb
def show
if id = params[:id]
if #client = current_user.clients.find_by_id(id.to_i)
if #client.jobs.count > 0
#jobs_by_month = #client.jobs.group_by{|j| j.created_at.strftime('%B %Y')}
end
else
redirect_to dashboard_path
end
end
end
show.html.erb
<% if #client.jobs.count > 0 %>
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="panel panel-white">
<div class="panel-heading">
<h4 class="panel-title">Jobs</h4>
<div class="panel-body">
<%= render 'month_section' %>
</div>
</div>
</div>
</div>
</div>
<% end -%>
_month_section.html.erb
<div class="month_section" >
<% #jobs_by_month.each do |date, jobs| %>
<div>
<h3><%= date %></h3>
<%= render partial: 'jobs', :locals => {:jobs => jobs } %>
</div>
<% end %>
</div>
_jobs.html.erb
<div class="jobs">
<div class="row">
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
</tr>
</thead>
<tbody>
<% jobs.each do |job| %>
<tr>
<td><%= job.date%></td>
<td><%= job.start_time %></td>
<td><%= job.end_time %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
Turns out issue was due to a rogue non-terminated div tag on show.html.erb outside of the snippet I posted.

Custom Routing with singular resource error

my routes are looking like this
routes.rb
get '/:pimp_id/mepagers(.:format)', :to => 'mepagers#index', :as => 'mepagers'
get '/:pimp_id/mepager/new(.:format)', :to => 'mepagers#new', :as => 'new_mepager'
get '/:pimp_id/mepager/edit(.:format)', :to => 'mepagers#edit', :as => 'edit_mepager'
get '/:pimp_id/mepager(.:format)', :to => 'mepagers#show', :as => 'mepager'
post '/:pimp_id/mepager(.:format)', :to => 'mepagers#create', :as => 'create_mepager'
put '/:pimp_id/mepager(.:format)', :to => 'mepagers#update'
patch '/:pimp_id/mepager(.:format)', :to => 'mepagers#update'
delete '/:pimp_id/mepager(.:format)', :to => 'mepagers#destroy'
I tried to take the form from
HTTP Verb Path Controller#Action Used for
GET /geocoder/new geocoders#new return an HTML form for creating the geocoder
POST /geocoder geocoders#create create the new geocoder
GET /geocoder geocoders#show display the one and only geocoder resource
GET /geocoder/edit geocoders#edit return an HTML form for editing the geocoder
PATCH/PUT /geocoder geocoders#update update the one and only geocoder resource
DELETE /geocoder geocoders#destroy delete the geocoder resource
(source http://guides.rubyonrails.org/routing.html)
But when I click the submit button on /1/mepager/new I get following error:
Routing Error
No route matches [POST] "/1/mepager/new"
I even tried to change the post actions route to /1/mepager/new but that didnt help at all because he cant find the param for mepager then. Coudlnt find anything similar on google so I hope someone can help this routing makes me sick!
new.html.erb
<%= render 'form' %>
<%= link_to 'Back', pimps_path %>
_form.html.erb
<%= form_for 'mepager_path' do |f| %>
<% if #mepager.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#mepager.errors.count, "error") %> prohibited this mepager from being saved:</h2>
<ul>
<% #mepager.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table style="border:1px solid black; border-spacing:5px"; width="1521" bgcolor="#DFDFDF">
<colgroup>
<col width="1050">
<col width="300">
</colgroup>
<tr> <td> <h1>NEW: ID# Title </td> <td> <h1>Programme: a350</h1></td> </tr>
</table>
<p id="notice"><%= notice %>
<table style="border:1px solid black; border-spacing:5px"; width="1500"; height="640">
<tr>
<th rowspan="3">
<table style="border:1px solid black; border-spacing:5px"; width="1150"; height="506">
<colgroup>
<col width="675">
<col width="675">
</colgroup>
<tr> <th colspan="2" align="left" height="10"> <u><strong>Change description & pictures:</strong></u> </th> </tr>
<tr> <th colspan="2" align="left" height="10"> <u><b>Pre:</b></u> </th> </tr>
<tr>
<td align="left" valign="top"> <div class="field"> <%= f.text_area :pre, :size=>"100x12"%> </div> </td>
<td>
<div class="actions">
<%= file_field_tag :file %>
<%= submit_tag "Upload image" %>
</div>
</td>
</tr>
<tr> <th colspan="2" align="left" height="10"> <u><b>Post:</b></u> </th> </tr>
<tr>
<td align="left" valign="top"> <div class="field"> <%= f.text_area :post, :size=>"100x12" %> </div> </td>
<td>
<div class="actions">
<%= file_field_tag :file %>
<%= submit_tag "Upload image" %>
</div>
</td>
</tr>
</table>
</th>
<td valign="top">
<table style="border:1px solid black; border-spacing:5px"; width="350"; height=135>
<colgroup>
<col width="160">
<col width="190">
</colgroup>
<tr> <th colspan="2" align="left" height="10"> <u><strong>Expected savings / overspend reduction:</strong></u> </th> </tr>
<tr> <td align="left"> h/AC: </td> <td align="left"> <div class="field"> <%= f.number_field :save_h, :size=>5 %> </div> </td> </tr>
<tr> <td align="left"> concessions/AC: </td> <td align="left"> <div class="field"> <%= f.number_field :save_c, :size=>5 %> </div> </td> </tr>
<tr> <td align="left"> others: </td> <td align="left"> <div class="field"> <%= f.text_field :save_other, :size=>30 %> </div> </td> </tr>
</table>
</td>
</tr>
<tr>
<td>
<table style="border:1px solid black; border-spacing:5px"; width="350"; height=180>
<colgroup>
<col width="160">
<col width="190">
</colgroup>
<tr> <th colspan="2" align="left" height="10"> <u><strong>Affected domains / responsibility:</strong></u> </th> </tr>
<tr> <td align="left"> Design: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_design, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Stress: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_stress, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Manufacturing: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_me, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Others: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_other, :size=>30 %> </div> </td> </tr>
</table>
</td>
</tr>
<tr>
<td>
<table style="border:1px solid black; border-spacing:5px"; width="350"; height=135>
<colgroup>
<col width="160">
<col width="190">
</colgroup>
<tr> <th colspan="2" align="left" height="10"> <u><strong>Affected documents:</strong> </u> </th> </tr>
<tr> <td align="left"> Drawing number/HTZ: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_dno, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Material ID: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_mid, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Others: </td> <td align="left"> <div class="field"> <%= f.text_field :affect_otherdoc, :size=>30 %> </div> </td> </tr>
</table>
</td>
</tr>
<tr>
<td>
<table style="border:1px solid black; border-spacing:5px"; width="1150"; height=196>
<tr height="10"> <th align="left"> <u><b>Comments / current status / further notes:</b></u> </th> </tr>
<tr> <td align="left" valign="top"> <div class="field"> <%= f.text_area :save_h, :size=>"100x8"%> </div> </td> </tr>
</table>
</td>
<td>
<table style="border:1px solid black; border-spacing:5px"; width="350"; height=150>
<colgroup>
<col width="160">
<col width="190">
</colgroup>
<tr> <th colspan="2" align="left" height="10"> <u><strong>General information:</strong></u> </th> </tr>
<tr> <td align="left"> Idea owner: </td> <td align="left"> <div class="field"> <%= f.text_field :owner, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Date of submission: </td> <td align="left"> autofilled </td> </tr>
<tr> <td align="left"> PPS available: </td> <td align="left"> <div class="field"> <%= f.text_field :pps, :size=>30 %> </div> </td> </tr>
<tr> <td align="left"> Reference (VV/ZTV): </td> <td align="left"> <div class="field"> <%= f.text_field :reference, :size=>30 %> </div> </td> </tr>
</table>
</td>
</tr>
</table>
<div class="actions">
<%= f.submit "Create One Pager" %>
</div>
<% end %>
See documentation on form_for here
Referring to the documentation linked to above; the form_for method takes a few parameters:
record
options
block
In your case, I think what you trying to do is pass the 'mepager_path' named path as the URL to which the form should be submitted. However, you're missing separators for your form_for parameters so Rails thinks 'mepager_path' is the value of the record parameter.
the record parameter is meant to convey information about the object which the form should describe so that Rails can infer properties of the object to make the form for you with minimal overhead to you, the developer. In your case, I think you can try someting like
<%= form_for :mepager, url: mepager_path do |f| %>
I'm also a Rails noob so I can't promise you my code samples are correct but the gist of my answer is that your form_for parameters are incorrect. As someone new to Rails, I'm constantly frustrated by different forms parameters can take. For me the multitude of forms make them difficult to read and I constantly have to make sure I'm not misinterpreting code. Also, hash syntax always confuses me.
My answer was taken from here. I've found it to be a very useful reference site.
Hope my answer helps you.

Resources