Custom Routing with singular resource error - ruby-on-rails

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.

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;

Print HTML Page Twitter bootstrap

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

question about application.html.erb

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>

Problem with Partial Form in Rails 3

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.

Model binding when rendering a partial view multiple times (partial view used for editing)

Greeting Everyone,
I'm having a little trouble with a partial view I'm using as an edit form. Aside from the hidden elements in the form, the model is null when passed to my EditContact post controller.
I should add, I realize there's a more seamless way to do what I'm doing using AJAX, but I think if I can solve the clunky way first it will help me understand the framcework a little better.
Here's my EditContact partial view:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<WebUI.DataAccess.CONTACT>" %>
<div id="contactPartial-<%= ViewData.Model.id %>">
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("EditContact", "Investigator"))
{ %>
<%= Html.HiddenFor(Model => Model.id) %>
<%= Html.HiddenFor(Model => Model.investId) %>
<table id="EditContact-<%= ViewData.Model.id %>" width="100%">
<tr>
<th colspan="4">
<b>New Contact</b>
</th>
</tr>
<tr>
<td>
<b>
<%= Html.LabelFor(Model => Model.type)%></b><br />
<%= Html.EditorFor(Model => Model.type, null, "contactType-" + ViewData.Model.id)%><br />
<%= Html.ValidationMessageFor(Model => Model.type) %>
</td>
</tr>
<tr>
<td>
<b>
<%= Html.LabelFor(Model => Model.salutation)%></b><br />
<%= Html.EditorFor(Model => Model.salutation, null, "contactsalutation-"+ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.firstName)%></b><br />
<%= Html.EditorFor(Model => Model.firstName, null, "contactFirstName-"+ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.middleName)%></b><br />
<%= Html.EditorFor(Model => Model.middleName, null, "contactMiddleName-"+ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.lastName)%></b><br />
<%= Html.EditorFor(Model => Model.lastName, null, "contactLastName-"+ViewData.Model.id)%><br />
<%= Html.ValidationMessageFor(Model => Model.lastName)%>
</td>
</tr>
<tr>
<td>
<b>
<%= Html.LabelFor(Model => Model.title)%></b><br />
<%= Html.EditorFor(Model => Model.title, null, "contactTitle-"+ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.phone)%></b><br />
<%= Html.EditorFor(Model => Model.phone, null, "contactPhone="+ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.altPhone)%></b><br />
<%= Html.EditorFor(Model => Model.altPhone, null, "contactAltPhone-" + ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.fax)%></b><br />
<%= Html.EditorFor(Model => Model.fax, null, "contactFax-" + ViewData.Model.id)%>
</td>
</tr>
<tr>
<td>
<b>
<%= Html.LabelFor(Model => Model.email)%></b><br />
<%= Html.EditorFor(Model => Model.email, null, "contactEmail-" + ViewData.Model.id)%>
</td>
<td>
<b>
<%= Html.LabelFor(Model => Model.comment)%></b><br />
<%= Html.EditorFor(Model => Model.comment, null, "contactComment-" + ViewData.Model.id)%>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Save" />
</td>
<td>
<button id="<%= ViewData.Model.id %>" class="contactEditHide">
Cancel</button>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<% } %>
</div>
When the Edit contact post controller is passed the model only id and investId have values; everything else is null. Here's how I'm rendering the partial view in my Details view:
<table width="100%">
<tr>
<th colspan="7">
<b>Contacts</b>
</th>
<th id="contactButton" class="button">
<button id="showEditContact-0" type="button" class="contactEditShow">New Contact</button>
</th>
</tr>
<tr>
<th>
Type
</th>
<th>
Name
</th>
<th colspan="2">
Title
</th>
<th>
Prim. & Alt. Phone
</th>
<th>
Fax
</th>
<th colspan="2">
Comment
</th>
</tr>
<% for (int i = 0; i < Model.CONTACTs.Count; i++)
{ %>
<tr id="contactRow-<%= Model.CONTACTs[i].id %>" class="contactRow">
<td>
<%= Html.Encode(Model.CONTACTs[i].type)%>
</td>
<td>
<%= Html.Encode(Model.CONTACTs[i].salutation)%>
<%= Html.Encode(Model.CONTACTs[i].firstName)%>
<%= Html.Encode(Model.CONTACTs[i].middleName)%>
<%= Html.Encode(Model.CONTACTs[i].lastName)%>
<br />
<a href="mailto:<%= Html.AttributeEncode(Model.CONTACTs[i].email) %>">
<%= Html.Encode(Model.CONTACTs[i].email)%></a>
</td>
<td colspan="2">
<%= Html.Encode(Model.CONTACTs[i].title)%>
</td>
<td>
Prim:<%= Html.Encode(Model.CONTACTs[i].phone)%><br />
Alt:<%= Html.Encode(Model.CONTACTs[i].altPhone)%>
</td>
<td>
<%= Html.Encode(Model.CONTACTs[i].fax)%>
</td>
<td>
<%= Html.Encode(Model.CONTACTs[i].comment)%>
</td>
<td>
<button id="<%= Model.CONTACTs[i].id %>" type="button" class="contactEditShow">Edit Contact</button>
</td>
</tr>
<tr>
<td colspan="8">
<% Html.RenderPartial("EditContact", Model.CONTACTs[i]); %>
</td>
</tr>
<% } %>
</table>
My details view is strongly tyed to an INVESTIGATOR model:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebUI.DataAccess.INVESTIGATOR>" %>
As you can see above, my partial view is strongly typed to a CONTACTS model.
I ran into a similar problem with Model binding when, in a view, I was trying to allow for the editing all layers of an address at one time and fixed it by indexing the model, similar to the Details view above. It seems like I need to do the same thing in my partial view to ensure Model binding, but I'm not sure how to achieve this (having syntax issues).
Of course, I could be off here an need a new solution in general!
Let me know if you need more detail! Thanks!
Why are you using
<%= Html.EditorFor(Model => Model.salutation, null, "contactsalutation-"+ViewData.Model.id)%>
If you use it simply like this
<%= Html.EditorFor(Model => Model.salutation) %>
It should be working.
In order to map your model, your control need to have the same id as there name, and the third parameter you're using changes your control id.
Use Html.EditorFor instead of Html.RenderPartial.
See Model binding with nested child models and PartialViews in ASP.NET MVC.

Resources