question about application.html.erb - ruby-on-rails

i have a table in my application.html.erb.like this:
<body>
<table width='100%' border='3'>
<tr><td height="100"> </td></tr>
<tr>
<td width="10%"></td>
<td width="80%"></td>
<td width="10%"></td>
</tr>
</table>
<%= yield %>
</body>
i want to put contents of other page in <td width="80%"></td> but i dont know how can i do that?
thank you for your helps

<body>
<table width='100%' border='3'>
<tr><td height="100"> </td></tr>
<tr>
<td width="10%"></td>
<td width="80%"><%= render "other_page" %></td>
<td width="10%"></td>
</tr>
</table>
<%= yield %>
</body>
This will render _other_page.html.erb.
Read more about it here:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials

Simply move the yield statement:
<body>
<table width='100%' border='3'>
<tr>
<td height="100"></td>
</tr>
<tr>
<td width="10%"></td>
<td width="80%"><%= yield %></td>
<td width="10%"></td>
</tr>
</table>
</body>

Related

How to implement bootstrap accordion in table in MVC?

I want to implement bootstrap accordion in my application. Currently, If I click on any rows, it gives me first #Html.Raw(item.D) and #Html.Raw(item.B).
What i want is that, if i click on 2nd row then its respective #Html.Raw(item.D) and #Html.Raw(item.B) should displayed and so on.
Please suggest me where I am going wrong.
<div class="panel-body">
<table class="table">
#foreach (var item in Model)
{
<tr class="accordion-toggle" data-toggle="collapse" data-target="#12345-cores">
<td align="left">
#Html.Raw(item.H)
</td>
<td align="right">
#Html.Raw(item.E)
</td>
</tr>
<tr>
<td class="accordion-body collapse" id="12345-cores">
<table>
<tbody>
<tr>
<td>
#Html.Raw(item.D)
</td>
<td></td>
<td>
#Html.Raw(item.B)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
}
</table>
You need to specify id uniquely, to do so you need to append raw id(or something unique for each row) to id and data-target attributes,
<div class="panel-body">
<table class="table">
#foreach (var item in Model)
{
<tr class="accordion-toggle" data-toggle="collapse" data-target="#12345-cores#(item.id)">
<td align="left">
#Html.Raw(item.H)
</td>
<td align="right">
#Html.Raw(item.E)
</td>
</tr>
<tr>
<td class="accordion-body collapse" id="12345-cores#(item.id)">
<table>
<tbody>
<tr>
<td>
#Html.Raw(item.D)
</td>
<td></td>
<td>
#Html.Raw(item.B)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
}
</table>
updated : data-target="#12345-cores#(item.id) & id="12345-cores#(item.id)"

Inline CSS is not working with gem 'htmltopdf'

My requirement is to download docx file and should be open on Microsoft word:
I am using following gems:
gem 'responders'
gem 'htmltoword
Controller code:
require 'htmltoword'
class Admin::VisibilitiesController < ApplicationController
respond_to :docx, :html, :css,:js
def preview
#project = Project.find_by(id: params[:id])
#feeder = Project.find_by(id: params[:id]).form2.last.feeder11s.first
respond_to do |format|
format.docx do
render :docx => "report1_docx",:template => 'admin/visibilities/preview.html.docx.erb', :page_height => 600, :page_width =>345
end
end
end
View file code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<style type="text/css">
div.alwaysbreak { page-break-before: always; }
div.nobreak:before { clear:both; }
div.nobreak { page-break-inside: avoid; }
td{padding: 2px 5px;}
</style>
<div style="padding-top:20px;">
<table style="width:800px;margin:0px auto;border:1px solid grey; background: #fff;margin: 0 auto;margin-bottom:30px;padding:10px 20px; ">
<tbody>
<tr>
<td style="padding: 15px 0 50px;">
<table style="padding:0px;overflow:hidden;display:table;">
<tbody>
<tr>
<td style="font-size: 16px;width:100%;font-weight:600">
Report No......./...../......./20116-17.....
</td>
</tr>
<tr>
<td style="font-size: 16px;width:100%;font-weight:600">
Dated: ......
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size:28px;font-weight:bold;text-align:center;padding-bottom:20px; font-style: italic;">THIRD PARTY VILLAGE INSPECTION REPORT</td>
</tr>
<tr>
<td style="font-size:28px;font-weight: bold;text-align:center;padding-bottom:25px; font-style: italic;">OF</td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:25px;">RURAL ELECTRIFICATION WORKS UNDER DEEN DAYAL UPADHYAYA GRAM JYOTI YOJANA (erstwhile RGGVY 12TH PLAN)</td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:20px;">IN</td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:25px;">..............DISTRICT</td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:20px;">SUBMITTED TO</td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:25px;">........................</td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:20px;">SUBMITTED BY </td>
</tr>
<tr>
<td style="font-size:24px;font-weight:400;text-align:center;padding-bottom:30px;">........................</td>
</tr>
<tr>
<td style="font-style: italic; padding-bottom: 30px; padding-top: 100px;">
<table style="width: 100%; margin-top: 50px;">
<tr>
<td style="font-size:12px;padding-bottom:10px;font-weight:600">Report No (admin)/District(survey)/1st/2016-17/070</td>
<td style="font-size:12px;padding-bottom:10px;font-weight:600; text-align: right;">Dated: from survey (form1)</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding-bottom: 50px;">
<table style="width: 100%;">
<tr>
<td style="font-size:18px;font-weight:600">Location:</td>
</tr>
<tr>
<td style="font-size:16px;font-weight:600">Name of Village : <%= #project.form1.try(:village_name) %></td>
<tr>
<td style="font-size:16px;font-weight:600">Census Code No : <%= #project.form1.try(:census_code_no) %>
</td>
</tr>
<tr>
<td style="font-size:16px;font-weight:600">Name of Block : <%= #project.form1.try(:block_name) %></td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Output
htmltoword gem currently provides just some basic styling support mostly on alignment and tables.
Here is opened GitHub issue https://github.com/karnov/htmltoword/issues/45 about that problem.
And here is the doc describing supported styles and classes.
Try to use some basic HTML tags instead of CSS-styles where it is possible, it seems the only way at the moment to get your word doc to be styled.

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;

How to set the highchart and the table horizontally?

This is what my highchart looks like atm
I kinda want the chart to be on the right side while the table to be on the left
this is my html:
<div id="words" style="width:70%;float:left;">
<table border="1" class="highchart" data-graph-container-before="1" data-graph-type="column">
<thead>
<tr>
<th>Word</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr>
<td>icon</td>
<td>12</td>
</tr>
<tr>
<td>text</td>
<td>12</td>
</tr>
<tr>
<td>your</td>
<td>9</td>
</tr>
<tr>
<td>post</td>
<td>6</td>
</tr>
<tr>
<td>document</td>
<td>5</td>
</tr>
<tr>
<td>with</td>
<td>5</td>
</tr>
<tr>
<td>parentNode</td>
<td>4</td>
</tr>
<tr>
<td>email</td>
<td>4</td>
</tr>
<tr>
<td>com"</td>
<td>4</td>
</tr>
<tr>
<td>googletag</td>
<td>3</td>
</tr>
</tbody>
</table>
What should i do to achieve such output?
If you can change HTML, then simply put table before Highcharts container and set proper styles (float, width). For example you can also use two divs: http://jsfiddle.net/68qdew8g/
<div style="float: left; width: 30%;">
<table border="1" class="highchart" data-graph-container-before="1" data-graph-type="column">
...
</table>
</div>
<div id="words" style="width:70%;float:left;"></div>

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