i tried to make a partial form.but an error like this occured:
SyntaxError in Vorlesungs#new
Showing /home/babak/Management/app/views/vorlesungs/_Form.erb where line #1 raised:
compile error
/home/babak/Management/app/views/vorlesungs/_Form.erb:1: dynamic constant assignment
..._assigns[:submit_lable];Form = local_assigns[:Form];;#output...
^
Extracted source (around line #1):
1: <html>
2: <body>
3: <p>
4: <table>
that is my _Form code:
<html>
<body>
<p>
<table>
<tr align="center" style="width: 100%">
<td width="25%"></td>
<td width="50%">
<table>
<tr>
<td>Name : </td>
<td><%= v.text_field :Name %> </td>
</tr>
<tr>
<td>Name de Professur :</td>
<td><%= v.text_field :Leiter_name %></td>
</tr>
<tr>
<td>Proffesuren :</td>
<td><%= v.text_field :Professuren %></td>
</tr>
<tr>
<td> <%= submit_tag submit_lable%></td>
</tr>
</table>
</td>
<td width="25%"></td>
</tr>
</table>
</p>
</body>
</html>
and in my view:
<%= form_for(#vorlesung) do |v| %>
<%= render :partial => 'Form',:locals => {:v =>v,:submit_lable =>'Update'} %>
<% end %>
Thank you for your helps
Make your partial name lowercase.
Related
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;
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 %>
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.
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
i have two tables(adverb,word) and two controllers(adverbs,words).i want to have one form to add and edit the records of two tables.
adverb controller:
class AdverbsController < ApplicationController
def new
#adverb=Adverb.new
end
def create
#adverb=Adverb.create(params[:adverb])
if #adverb.save
redirect_to :action => 'index'
else
render :action => 'new'
end
end
def index
#adverb =Adverb.find(:all)
end
def edit
#adverb =Adverb.find(params[:id])
end
def update
if #adverb.update_attributes(params[:adverb])
redirect_to :action => 'index'
else
redirect_to :action => 'edit'
end
end
end
and words controller:
class WordsController < ApplicationController
def new
#word=Word.new
end
def create
#word=Word.create(params[:word])
if #word.save
redirect_to :action => 'index'
else
render :action => 'new'
end
end
def index
#word=Word.find(:all)
end
def edit
#word=Word.find(params[:id])
end
def update
if #word.update_attributes(params[:word])
redirect_to :action => 'index'
else
redirect_to :action => 'edit'
end
end
end
I use Partial form
<html>
<div id="tabs">
<ul>
<li>word </li>
<li>Adverb </li>
</ul>
<div id="tabs-1">
<table >
<tr>
<td align="right">
Artikel :
</td>
<td align="center">
<%= w.label :Artikel ,'der' %><%= w.radio_button :Artikel,'der',:checked =>false%>
<%= w.label :Artikel ,'die' %><%= w.radio_button :Artikel,'die',:checked =>true %>
<%= w.label :Artikel ,'das' %><%= w.radio_button :Artikel,'das',:checked =>false %>
</td>
</tr>
<tr>
<td align="right">
Neues Wort:
</td>
<td>
<%= w.text_field :Name ,:size => '31*45'%>
</td>
</tr>
<tr>
<td align="right">
Synonome :
</td>
<td>
<%= w.text_field :syn ,:size => '31*45'%>
</td>
</tr>
<tr>
<td align="right">
Bedeutung :
</td>
<td>
<%= w.text_area :bedeutung , :size =>'30*45' %>
</td>
</tr>
<tr>
<td align="right">
Beispiel :
</td>
<td>
<%= w.text_field :beispiel ,:size => '31*45' %>
</td>
</tr>
<tr>
<td>
Kommentar:
</td>
<td>
<%= w.text_area :kommentar ,:size =>'30*45' %>
</td>
</tr>
<tr>
<td align="center">
<%= w.submit submit_lable %>
</td>
</tr>
</table>
</div>
<div id="tabs-2">
<%= fields_for (#adverb) do |av| %>
<table>
<tr>
<td align="right">
Adverb :
</td>
<td>
<%= av.text_field :name %>
</td>
</tr>
<tr>
<td align="right">
Bedeutung :
</td>
<td>
<%= av.text_field :bedeutung %>
</td>
</tr>
<tr>
<td align="right">
Synonome :
</td>
<td>
<%= av.text_field :syn %>
</td>
</tr>
<tr>
<td>
<%= w.submit submit_lable %>
</td>
</tr>
</table>
<% end %>
</div>
</div>
</html>
and im my new.html.erb :
<html>
<body>
<%= form_for(#word) do |w| %>
<%= render :partial => 'form',:locals => {:w =>w,:submit_lable =>'mmmm'} %>
<% end %>
</body>
</html>
but an error occured:
NoMethodError in Words#new
Showing /home/babak/kurs/app/views/words/_form.erb where line #197 raised:
undefined method `model_name' for NilClass:Class
how can i solve my problem?
thank you for your helps
I assume this exception is raised when getting the new action of the words controller. In your _form.html.erb, you have the following code:
<%= fields_for (#adverb) do |av| %>
<table>
<tr>
<td align="right">
Adverb :
</td>
<td>
<%= av.text_field :name %>
</td>
</tr>
<tr>
<td align="right">
Bedeutung :
</td>
<td>
<%= av.text_field :bedeutung %>
</td>
...
</table>
<%= end %>
I see nowhere in your new action of the words controller where #adverb is declared. Instance variables default to nil, which is why you see this error.